From 1408bdcc74a9859b33a03f104d84af25dce01b64 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 13 Nov 2023 11:14:57 +0100 Subject: [PATCH] OpenTelemetryTracerBridge.Start: Make returned context contain span (#6614) Signed-off-by: Arve Knudsen --- CHANGELOG.md | 1 + pkg/mimir/tracing.go | 3 ++- pkg/mimir/tracing_test.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77956cd273c..77f0b5e8e6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ * [BUGFIX] All: fix issue where traces for some inter-component gRPC calls would incorrectly show the call as failing due to cancellation. #6470 * [BUGFIX] Querier: correctly mark streaming requests to ingesters or store-gateways as successful, not cancelled, in metrics and traces. #6471 #6505 * [BUGFIX] Querier: fix issue where queries fail with "context canceled" error when an ingester or store-gateway fails healthcheck while the query is in progress. #6550 +* [BUGFIX] Tracing: When creating an OpenTelemetry tracing span, add it to the context for later retrieval. #6614 ### Mixin diff --git a/pkg/mimir/tracing.go b/pkg/mimir/tracing.go index 6883fc8de0f..a16e43c790c 100644 --- a/pkg/mimir/tracing.go +++ b/pkg/mimir/tracing.go @@ -117,7 +117,8 @@ func (t *OpenTelemetryTracerBridge) Start(ctx context.Context, spanName string, } span, ctx := opentracing.StartSpanFromContextWithTracer(ctx, t.tracer, spanName, mappedOptions...) - return ctx, NewOpenTelemetrySpanBridge(span, t.provider) + otelSpan := NewOpenTelemetrySpanBridge(span, t.provider) + return trace.ContextWithSpan(ctx, otelSpan), otelSpan } type OpenTelemetrySpanBridge struct { diff --git a/pkg/mimir/tracing_test.go b/pkg/mimir/tracing_test.go index 5faa2f3d406..2fa50c0547e 100644 --- a/pkg/mimir/tracing_test.go +++ b/pkg/mimir/tracing_test.go @@ -3,6 +3,7 @@ package mimir import ( + "context" crand "crypto/rand" "encoding/binary" "errors" @@ -205,3 +206,12 @@ func (m *TracingSpanMock) LogEventWithPayload(event string, payload interface{}) func (m *TracingSpanMock) Log(data opentracing.LogData) { m.Called(data) } + +func TestOpenTelemetryTracerBridge_Start(t *testing.T) { + bridge := NewOpenTelemetryProviderBridge(opentracing.GlobalTracer()) + tracer := bridge.Tracer("") + ctx, span := tracer.Start(context.Background(), "test") + ctxSpan := trace.SpanFromContext(ctx) + + require.Same(t, span, ctxSpan, "returned context should contain span") +}