Skip to content

Commit

Permalink
OpenTelemetryTracerBridge.Start: Make returned context contain span (#…
Browse files Browse the repository at this point in the history
…6614)

Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 authored Nov 13, 2023
1 parent 3c40300 commit 1408bdc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion pkg/mimir/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/mimir/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package mimir

import (
"context"
crand "crypto/rand"
"encoding/binary"
"errors"
Expand Down Expand Up @@ -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")
}

0 comments on commit 1408bdc

Please sign in to comment.