1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-09-16 09:26:25 +02:00

Use the context passed to ExportSpans for measurements in stdouttrace (#7198)

Without this the measurements are receiving broken context.
This commit is contained in:
Tyler Yahn
2025-08-17 08:26:57 -07:00
committed by GitHub
parent 03d0c5dc47
commit 2ab7d4dc14

View File

@@ -98,7 +98,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
if e.selfObservabilityEnabled {
count := int64(len(spans))
e.spanInflightMetric.Add(context.Background(), count, e.selfObservabilityAttrs...)
e.spanInflightMetric.Add(ctx, count, e.selfObservabilityAttrs...)
defer func(starting time.Time) {
// additional attributes for self-observability,
// only spanExportedMetric and operationDurationMetric are supported
@@ -108,9 +108,9 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
addAttrs = append(addAttrs, semconv.ErrorType(err))
}
e.spanInflightMetric.Add(context.Background(), -count, e.selfObservabilityAttrs...)
e.spanExportedMetric.Add(context.Background(), count, addAttrs...)
e.operationDurationMetric.Record(context.Background(), time.Since(starting).Seconds(), addAttrs...)
e.spanInflightMetric.Add(ctx, -count, e.selfObservabilityAttrs...)
e.spanExportedMetric.Add(ctx, count, addAttrs...)
e.operationDurationMetric.Record(ctx, time.Since(starting).Seconds(), addAttrs...)
}(time.Now())
}