george-maroun / tracecheck

GoLinter to identify improperly formatted logs and make suggestions to fix the logs
MIT License
3 stars 0 forks source link

Should run on lines that call NewLogger and lines that call WithValues #3

Open george-maroun opened 1 year ago

george-maroun commented 1 year ago

We'd like to check if NewLogger is invoked, then check if WithValues is called on the NewLogger:

Separately, check if WithValues has even number of args

george-maroun commented 1 year ago

// Example: func LogErrorCallback(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) { log := zapr.NewLogger(zap.L()) log = log.WithValues("githubHookID", r.Header.Get("X-GitHub-Hook-ID")) log = log.WithValues("eventType", r.Header.Get("X-GitHub-Event")) log = log.WithValues("deliverID", r.Header.Get("X-GitHub-Delivery")) log.Error(err, "Failed to handle GitHub webhook") }

// Should become: // in imports add go.opentelemetry.io/otel/trace

func LogErrorCallback(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) { span := trace.SpanFromContext(ctx) log := zapr.NewLogger(zap.L()).WithValues("traceId", traceId, "spanId", spanId) log = log.WithValues("githubHookID", r.Header.Get("X-GitHub-Hook-ID")) log = log.WithValues("eventType", r.Header.Get("X-GitHub-Event")) log = log.WithValues("deliverID", r.Header.Get("X-GitHub-Delivery")) log.Error(err, "Failed to handle GitHub webhook") }

jlewi commented 1 year ago

@george-maroun In the call above where are you getting the context from?

george-maroun commented 1 year ago

@george-maroun In the call above where are you getting the context from?

Right. I’m changing the example and opening another issue to check for functions that take ctx as input.