1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-27 22:49:15 +02:00

Propagate context to self-observability measurements in sdk/trace (#7209)

Ensures metric functionality that integrates with trace context (e.g.
exemplars) correctly receive the trace context and anything else the
user has passed.
This commit is contained in:
Tyler Yahn
2025-08-26 08:58:35 -07:00
committed by GitHub
parent 49be00144e
commit c8b89e9780
4 changed files with 158 additions and 14 deletions

View File

@@ -509,7 +509,10 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) {
attrSamplingResult = s.tracer.spanLiveMetric.AttrSpanSamplingResult(otelconv.SpanSamplingResultRecordOnly)
}
s.tracer.spanLiveMetric.Add(context.Background(), -1, attrSamplingResult)
// Add the span to the context to ensure the metric is recorded
// with the correct span context.
ctx := trace.ContextWithSpan(context.Background(), s)
s.tracer.spanLiveMetric.Add(ctx, -1, attrSamplingResult)
}()
}