Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
george-maroun opened this issue Aug 7, 2023 · 3 comments

Comments

@george-maroun
Copy link
Owner

george-maroun commented Aug 7, 2023

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

  • if so:
    • check if WithValues contains traceId
    • if not:
      • add traceId, spanId, span declaration and import
  • else:
    • add .WithValues("traceId", traceId, "spanId", spanId)
    • add span declaration and import

Separately, check if WithValues has even number of args

@george-maroun george-maroun changed the title Should run on lines that call NewLogger instead of WithValues Should run on lines that call NewLogger and lines that call WithValues Aug 7, 2023
@george-maroun
Copy link
Owner Author

george-maroun commented Aug 7, 2023

// 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
Copy link

jlewi commented Aug 7, 2023

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

@george-maroun
Copy link
Owner Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants