Skip to content

Commit

Permalink
tracing: fix lazytag export for Jaegar/otel
Browse files Browse the repository at this point in the history
Previously, lazytags would not render in the otel export to
Jaeger. This was because otel doesn't support an on-demand
nature of the lazytags in its interface.

This change manually adds lazytags as otel tags before an otel
span is finished, allowing them to render in Jaeger after they
are exported.

Resolves: cockroachdb#85166

Release note: None
  • Loading branch information
aadityasondhi committed Aug 1, 2022
1 parent 3ed3138 commit 5a346ae
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/util/tracing/span_inner.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,35 @@ func (s *spanInner) Finish() {
}

if s.otelSpan != nil {
// It is ok to access s.crdb after calling s.crdb.finish() since it will be cleaned up by the parent of this func
s.crdb.mu.Lock()
defer s.crdb.mu.Unlock()
for _, kv := range s.crdb.mu.lazyTags {
switch v := kv.Value.(type) {
case LazyTag:
for _, tag := range v.Render() {
s.otelSpan.SetAttributes(
attribute.KeyValue{
// format string with the parent key as prefix
Key: attribute.Key(fmt.Sprintf("%s-%s", kv.Key, tag.Key)),
Value: tag.Value,
})
}
case fmt.Stringer:
s.otelSpan.SetAttributes(attribute.KeyValue{
Key: attribute.Key(kv.Key),
Value: attribute.StringValue(v.String()),
})
default:
s.otelSpan.SetAttributes(attribute.KeyValue{
Key: attribute.Key(kv.Key),
Value: attribute.StringValue(fmt.Sprintf("<can't render %T>", kv.Value)),
})
}
}
s.otelSpan.End()
}

if s.netTr != nil {
s.netTr.Finish()
}
Expand Down

0 comments on commit 5a346ae

Please sign in to comment.