fix(tracing): use global provider by default, but allow custom providers (#2803)

pull/2750/head
Haibo 2 years ago committed by GitHub
parent c6a4604839
commit 1f10166028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      middleware/tracing/tracer.go
  2. 2
      middleware/tracing/tracing.go

@ -30,15 +30,15 @@ func NewTracer(kind trace.SpanKind, opts ...Option) *Tracer {
for _, o := range opts {
o(&op)
}
if op.tracerProvider != nil {
otel.SetTracerProvider(op.tracerProvider)
if op.tracerProvider == nil {
op.tracerProvider = otel.GetTracerProvider()
}
switch kind {
case trace.SpanKindClient:
return &Tracer{tracer: otel.Tracer(op.tracerName), kind: kind, opt: &op}
return &Tracer{tracer: op.tracerProvider.Tracer(op.tracerName), kind: kind, opt: &op}
case trace.SpanKindServer:
return &Tracer{tracer: otel.Tracer(op.tracerName), kind: kind, opt: &op}
return &Tracer{tracer: op.tracerProvider.Tracer(op.tracerName), kind: kind, opt: &op}
default:
panic(fmt.Sprintf("unsupported span kind: %v", kind))
}

@ -29,7 +29,7 @@ func WithPropagator(propagator propagation.TextMapPropagator) Option {
}
// WithTracerProvider with tracer provider.
// Deprecated: use otel.SetTracerProvider(provider) instead.
// By default, it uses the global provider that is set by otel.SetTracerProvider(provider).
func WithTracerProvider(provider trace.TracerProvider) Option {
return func(opts *options) {
opts.tracerProvider = provider

Loading…
Cancel
Save