-
Notifications
You must be signed in to change notification settings - Fork 812
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
server/requestlog: Add Request Context in requestlog.Entry #2983
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2983 +/- ##
==========================================
+ Coverage 69.60% 69.66% +0.06%
==========================================
Files 111 111
Lines 11556 11560 +4
==========================================
+ Hits 8043 8053 +10
+ Misses 2851 2844 -7
- Partials 662 663 +1
Continue to review full report at Codecov.
|
I am not familiar with the test frameworks in this library. If this is PR is looking good, I would be happy to add a line of code somewhere to maintain the test coverage. |
@zombiezen thoughts? Add a context.Context to a struct is generally discouraged: |
Fair enough, I generally agree. I did it this way based on the |
I think it's okay here, but how about a change that's both more general and less controversial: adding the |
@jba That would solve everything I am looking for. Would you recommend deprecating the redundant fields ( |
You can document the redundant fields as deprecated. Also document that the implementor of Logger shouldn't touch the body. This is all subject to @vangent's OK, BTW. |
It's been a while, but IIRC the original reason we did not take in a I'll throw in another couple of implementation ideas here:
As an aside, migrating to OpenTelemetry would probably be a good idea to avoid users needing to deal with this in the common case. I believe OpenTelemetry is gaining more traction than OpenCensus did. I see this is already tracked as #2877. |
I like @jba's suggestion; it's the most flexible. We can document the |
Thanks for the feedback, folks. Please take another look, as I've switched from |
I would like to have access to the request's Context in the request logger, so that I can include metadata and also reference logging implementation details that might be stashed away in the context.
This is particularly useful for request loggers that aim to perform tracing with frameworks other than opencensus. It's also helpful for integrating with certain logging frameworks. I've also noticed that it is a good way to pass information from the
http.Server
s (e.g.BaseContext
) down to the request logger.To solve this, I've added a new field to
Entry
that is set based on the context from the request. I believe this change is relatively simple and backwards compatible.