-
Notifications
You must be signed in to change notification settings - Fork 289
Save baggage in span #153
Save baggage in span #153
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ type Span struct { | |
observer SpanObserver | ||
} | ||
|
||
// Tag a simple key value wrapper | ||
// Tag is a simple key value wrapper | ||
type Tag struct { | ||
key string | ||
value interface{} | ||
|
@@ -116,6 +116,11 @@ func (s *Span) LogFields(fields ...log.Field) { | |
if !s.context.IsSampled() { | ||
return | ||
} | ||
s.logFieldsNoLocking(fields...) | ||
} | ||
|
||
// this function should only be called while holding a Write lock | ||
func (s *Span) logFieldsNoLocking(fields ...log.Field) { | ||
lr := opentracing.LogRecord{ | ||
Fields: fields, | ||
Timestamp: time.Now(), | ||
|
@@ -173,6 +178,15 @@ func (s *Span) SetBaggageItem(key, value string) opentracing.Span { | |
s.Lock() | ||
defer s.Unlock() | ||
s.context = s.context.WithBaggageItem(key, value) | ||
if !s.context.IsSampled() { | ||
return s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this shortcut makes the assumption that the baggage log is always the last thing, which may not be the correct assumption in the future. It's better to include the log statement inside the if - it does not introduce significant nesting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not completely following, if the span is not sampled, we shouldn't log the span so it should fall outside of the id stmt. Not sure what you mean by "the baggage log is always the last thing" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simply meant If sampled then log baggage. |
||
} | ||
// If sampled, record the baggage in the span | ||
s.logFieldsNoLocking( | ||
log.String("event", "baggage"), | ||
log.String("key", key), | ||
log.String("value", value), | ||
) | ||
return s | ||
} | ||
|
||
|
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.
Not equal is a very weak test, it may succeed for other reasons