-
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
Log correct caller information when SpanLogger
is used
#547
Conversation
54ea07b
to
bc9704f
Compare
Is there a benchmark for this code? |
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, excepting @bboreham's question, and please also see my comment about possibly using filepath.Base
.
c68ae29
to
273af4f
Compare
I've added one in 273af4f. (The existing Results:
The extra cost comes because |
@bboreham are you satisfied with the benchmarks above? If you have any ideas on how to make this less costly, I'd love to hear them. |
Given the approval, I'm going to merge this, but if there is any late feedback, I'd be happy to hear it. |
What this PR does:
This PR ensures that correct caller information is logged when
SpanLogger
is used.Previously, messages logged with
SpanLogger
would havecaller=spanlogger.go:xxx
.Unfortunately we can't retrieve the existing
Caller
instance configured in the logger and replace it with another with an increased stack depth, as there's no way to retrieve existing key/value pairs associated with a logger. So instead I've created aspanLoggerAwareCaller
that determines the correct stack depth when it is first used.For similar reasons, this also makes it difficult to only add caller information when the logger is configured to provide caller information, and so
SpanLogger
s will now unconditionally add caller information to all messages logged. Given all of the applications I checked (Mimir, Loki and Tempo) configure their loggers to include caller information, this doesn't seem to be a big issue, but it did require some changes to some tests that assert on log messages emitted through aSpanLogger
.Which issue(s) this PR fixes:
(none)
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]