mirror of
https://github.com/traefik/traefik.git
synced 2025-05-05 23:43:01 +00:00
Fix panic when calling Tracer
This commit is contained in:
parent
1ccbf743cb
commit
cce935493a
@ -151,7 +151,7 @@ func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanS
|
|||||||
|
|
||||||
spanCtx, span := t.Tracer.Start(ctx, spanName, opts...)
|
spanCtx, span := t.Tracer.Start(ctx, spanName, opts...)
|
||||||
|
|
||||||
wrappedSpan := &Span{Span: span, tracerProvider: &TracerProvider{tracer: t}}
|
wrappedSpan := &Span{Span: span, tracerProvider: &TracerProvider{TracerProvider: span.TracerProvider(), tracer: t}}
|
||||||
|
|
||||||
return trace.ContextWithSpan(spanCtx, wrappedSpan), wrappedSpan
|
return trace.ContextWithSpan(spanCtx, wrappedSpan), wrappedSpan
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package tracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -392,3 +393,25 @@ func TestTracing(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTracerProvider ensures that Tracer returns a valid TracerProvider
|
||||||
|
// when using the default Traefik Tracer and a custom one.
|
||||||
|
func TestTracerProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
otlpConfig := &types.OTelTracing{}
|
||||||
|
otlpConfig.SetDefaults()
|
||||||
|
|
||||||
|
config := &static.Tracing{OTLP: otlpConfig}
|
||||||
|
tracer, closer, err := NewTracing(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
closer.Close()
|
||||||
|
|
||||||
|
_, span := tracer.Start(context.Background(), "test")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
span.TracerProvider().Tracer("github.com/traefik/traefik")
|
||||||
|
span.TracerProvider().Tracer("other")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user