-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
logging: Add traceID field to access logs when tracing is active #5507
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
Conversation
Related to #5336 |
91d8511
to
dd095a3
Compare
I decided to piggy-back off this PR for #5336. I don't love this though. This is kinda going into #4649 territory, we're doing allocations for the logging. We could use a I probably want to move |
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.
Thanks for taking care on this one, to ensure the proper perspective on the variables is captured (since passing arguments into a defer
'ed function evaluates the arguments right away, as opposed to later).
Also the benchmarks are really appreciated 😁
And the refactor + tests too!
The very minor performance penalty is only when tracing is enabled, yeah?
Either way, LGTM. Happy to include this in the 2.7 beta. Thank you!
modules/caddyhttp/server.go
Outdated
|
||
// preallocate with the amount of known fields | ||
fieldCount := 6 | ||
fields := make([]zapcore.Field, fieldCount+len(extra.fields)) |
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.
As discussed with Francis in Slack, these can be pooled. Doesn't have to happen in this PR, but it would reduce allocations over time as the slices will get reused.
9b1d241
to
caf4515
Compare
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
caf4515
to
245a42c
Compare
Tracing is far more useful when we can correlate logs with traces. This is done by adding a
traceID
field to the access logs.I've attempted to add this in with a minimum of performance impact, and as such have moved the request logging function out of
ServeHTTP
and into a new method that can be tested independently. I've added some basic unit tests and a couple of benchmarks to gauge the impact.Here are benchmark results before the
traceID
field was added:After:
Here's the diff:
(note: I've edited this to reflect updates since the initial push - there was a performance inconsistency in the benchmark code which I've since fixed)
IMO the ~15% hit is worth the extra field.