-
Notifications
You must be signed in to change notification settings - Fork 68
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
spanlogger: fix double logging of caller information #604
Conversation
I'd like to investigate and understand the regression in the |
…en SpanLogger This makes the cost of spanlogger.Caller negligible for use outside of SpanLogger: │ SpanLoggerAwareCaller/with_go-kit's_Caller-10 │ SpanLoggerAwareCaller/with_dskit's_spanlogger.Caller-10 │ │ sec/op │ sec/op vs base │ comparison-after-step-2.txt 927.5n ± 5% 932.1n ± 2% ~ (p=0.093 n=6) │ SpanLoggerAwareCaller/with_go-kit's_Caller-10 │ SpanLoggerAwareCaller/with_dskit's_spanlogger.Caller-10 │ │ B/op │ B/op vs base │ comparison-after-step-2.txt 732.5 ± 0% 733.0 ± 0% ~ (p=0.636 n=6) │ SpanLoggerAwareCaller/with_go-kit's_Caller-10 │ SpanLoggerAwareCaller/with_dskit's_spanlogger.Caller-10 │ │ allocs/op │ allocs/op vs base │ comparison-after-step-2.txt 9.000 ± 0% 9.000 ± 0% ~ (p=1.000 n=6) ¹ ¹ all samples are equal
I've investigated this and addressed it in the main PR description. This PR is good to go now. |
@charleskorn does this regression only apply to debug level? |
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.
LGTM, but please see suggestion about resizing the slice + my question about regression.
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
It applies to other levels too, if they are used when wrapping a However, at least in Mimir, it seems that the vast majority of logging to a |
Ah good point. |
What this PR does:
This PR fixes an issue with the changes introduced in #547.
That PR added logging correct caller information for code that used
SpanLogger
, however, it would log both the correct caller as well ascaller=spanlogger.go:xxx
.I incorrectly believed that
github.com/go-kit/log
would use the last value if multiplecaller
keys were logged for the same message. It turns out that is incorrect: if multiple duplicate keys are logged for the same message, both are included in the output.The fix for this is to introduce a
spanlogger.Caller
that returns the correct caller information, ignoring anySpanLogger
methods. It should be used in place ofgit.luolix.top/go-kit/log
'sCaller
when creating the logger at application startup.There is a small performance penalty (~1% additional latency for logging) when logging with
spanlogger.Caller
instead ofCaller
:This cost is only paid when a log line is actually logged, and not if the log line is filtered out (eg. if the log line is at debug level but the application is configured to emit info level and above, using
spanlogger.Caller
makes no difference).This change also improves the performance of
SpanLogger
in general, as we no longer need to allocate a newspanLoggerAwareCaller
for each instance. And the behaviour above when the log line is filtered also applies, which can be seen in theinfo_and_above_allowed/level.Debug
benchmark below:There is a regression in the
all_levels_allowed/level.Debug
benchmark, as now we need to read multiple stack frames for each log call. This is unavoidable, applications that are sensitive to this regression could useSpanLogger.DebugLog()
rather than wrappingSpanLogger
withlevel.Debug(...)
.Which issue(s) this PR fixes:
(none)
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]