-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add request id to logs. #4461
Add request id to logs. #4461
Conversation
ae9344f
to
48f0ceb
Compare
71d4a69
to
9d1d981
Compare
9d1d981
to
8079246
Compare
func maybeGetRequestID(ctx context.Context) string { | ||
var rID string | ||
if md, ok := metadata.FromIncomingContext(ctx); ok { | ||
if rIDs, ok := md["request-id"]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in HTTP what would this translate to? I wonder how it works with the HTTP gateway we use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GRPC moves back and forth headers having prefix Grpc-Metadata-
, so it would become Grpc-Metadata-Request-Id
.
We might want to use https://www.w3.org/TR/trace-context/ or https://uptrace.dev/opentelemetry/opentelemetry-traceparent.html |
8079246
to
8111143
Compare
@evankanderson while estimating work to improve logging I had a look at the documents you linked. My take is that the capabilities described in those specs far exceed our current need, which is to track a request execution from start to finish in logs. My take is that we're better off polishing this work, possibly changing the header's key (not the value), and merge it. |
Sounds good; I'd thought this would be something like: import "go.opentelemetry.io/otel/trace"
// ...
sc := trace.SpanContextFromContext(ctx)
ctx = zerolog.Ctx(ctx).With().Str("trace_id", sc.TraceID()).Logger().WithContext(ctx) If there's a bunch more content, then I'd agree on doing our own thing. |
8111143
to
4c55b9b
Compare
4c55b9b
to
fc6777b
Compare
This change adds a GRPC interceptor that fetches the header `Grpc-Metadata-Request-Id` and adds it to the logger. It also returns the request id to the client in the trailer, which is helpful for debugging. CLI command `minder history list` was modified to show its usage, but those changes should be reverted.
fc6777b
to
f804097
Compare
Here is an example of the output
Logs would be like this
Using |
Pull Request Test Coverage Report for Build 11351156474Details
💛 - Coveralls |
Also, use header rather than trailer.
f804097
to
f2b1f94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good start, I see the result both on the server side in the middleware and the client side in the headers (verified with curl).
Regarding the server vs client side headers - what if we had another header like e.g. Request-Correlation-ID
that the client could set in case a single client operation performs multiple requests? In that case the client might set the correlation to request ID of the first operation. There would be still the unique request ID and the correlation would really be just a hint for easier search of requests in the logs?
I'd wait here for a "bigger" tracing solution, and then have the top-level command use some sort of trace-parent to correlate the requests. One thing that may not be obvious here, but it looks like the |
I agree with @evankanderson in this, tracing across multiple requests requires some amount of shared state and more changes to the codebase. This is just a helper to filter down logs quickly.
That's correct, for that case we already track Github's delivery id that sort-of solves the same problem. |
Summary
This change adds a GRPC interceptor that fetches the header
Grpc-Metadata-Request-Id
and adds it to the logger. It also returns the request id to the client in the header, which is helpful for debugging.Fixes #4611
Change Type
Testing
Manual tests.
Review Checklist: