-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added span and trace id to hotrod logs #2384
Added span and trace id to hotrod logs #2384
Conversation
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
oooh, my bad, ya I've been busy with other things! sorry about that. |
Codecov Report
@@ Coverage Diff @@
## master #2384 +/- ##
=======================================
Coverage 95.61% 95.61%
=======================================
Files 205 206 +1
Lines 10529 10547 +18
=======================================
+ Hits 10067 10085 +18
+ Misses 395 394 -1
- Partials 67 68 +1
Continue to review full report at Codecov.
|
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.
Internally at Uber we have an extension to zap.Logger that supports the notion of context extractors, e.g.
type ContextFieldExtractor = func(context.Context) zapcore.Field
and is configured with the extractor defined in Jaeger client "github.com/uber/jaeger-client-go/log/zap".Trace
Then instead of For(ctx)
and a custom logger as we do here users can use normal zap.Logger with a field Context(ctx)
, defined as below:
const (
// n.b. This is used in conjunction with the skip field produced by Context() to indicate that
// this is a special-cased field, enabling zapfx to detect context fields and subsequently
// run any configured ContextFieldExtractors. When used, the corresponding zapcore.Field
// looks similar to:
//
// zapcore.Field{
// Type: zapcore.SkipType,
// Integer: _contextFieldIndicator,
// Interface: ctx,
// }
_contextFieldIndicator int64 = 1<<8 - 1
)
// Context wraps ctx as a zapcore.Field, suitable for use with calls to zap.Logger. It may only be
// used by loggers provided by zapfx; other loggers will panic due to its internal field type.
//
// Importantly, Context differs from other zapcore.Field types in that it does not guarantee a 1:1
// ratio of provided:encoded fields. Specifically, it:
//
// - May not result in an encoded field, in cases in which there are no configured underlying
// context extractors or where context baggage does not contain the necessary context keys;
// - May result in more than one encoded field, in cases in which multiple context extractors
// find keys and produce fields; and
// - Does not indicate a concrete field key or value at log time, as key:value pairs of any
// resulting field(s) are not known until the configured extractors have run just prior to log
// entry encoding.
func Context(ctx context.Context) zapcore.Field {
return zapcore.Field{
Type: zapcore.SkipType,
Integer: _contextFieldIndicator,
Interface: ctx,
}
}
Unfortunately, it never made it to OSS.
Which problem is this PR solving?
Short description of the changes
Example:
I know this was assigned to @ghostsquad, but it's been over a month so I took a stab at it.