diff --git a/contrib/opentelemetry/tracing_interceptor.go b/contrib/opentelemetry/tracing_interceptor.go index f3d5e5772..3451f9073 100644 --- a/contrib/opentelemetry/tracing_interceptor.go +++ b/contrib/opentelemetry/tracing_interceptor.go @@ -55,6 +55,11 @@ type TracerOptions struct { // DisableQueryTracing can be set to disable query tracing. DisableQueryTracing bool + // AllowInvalidParentSpans will swallow errors interpreting parent + // spans from headers. Useful when migrating from one tracing library + // to another, while workflows/activities may be in progress. + AllowInvalidParentSpans bool + // TextMapPropagator is the propagator to use for serializing spans. If not // set, this uses DefaultTextMapPropagator, not the OpenTelemetry global one. // To use the OpenTelemetry global one, set this value to the result of the @@ -125,10 +130,11 @@ func NewTracingInterceptor(options TracerOptions) (interceptor.Interceptor, erro func (t *tracer) Options() interceptor.TracerOptions { return interceptor.TracerOptions{ - SpanContextKey: t.options.SpanContextKey, - HeaderKey: t.options.HeaderKey, - DisableSignalTracing: t.options.DisableSignalTracing, - DisableQueryTracing: t.options.DisableQueryTracing, + SpanContextKey: t.options.SpanContextKey, + HeaderKey: t.options.HeaderKey, + DisableSignalTracing: t.options.DisableSignalTracing, + DisableQueryTracing: t.options.DisableQueryTracing, + AllowInvalidParentSpans: t.options.AllowInvalidParentSpans, } } diff --git a/interceptor/tracing_interceptor.go b/interceptor/tracing_interceptor.go index 3c0a94697..b52e8bb91 100644 --- a/interceptor/tracing_interceptor.go +++ b/interceptor/tracing_interceptor.go @@ -112,6 +112,11 @@ type TracerOptions struct { // DisableQueryTracing can be set to disable query tracing. DisableQueryTracing bool + + // AllowInvalidParentSpans will swallow errors interpreting parent + // spans from headers. Useful when migrating from one tracing library + // to another, while workflows/activities may be in progress. + AllowInvalidParentSpans bool } // TracerStartSpanOptions are options for Tracer.StartSpan. @@ -693,7 +698,7 @@ func (t *tracingInterceptor) startSpan( // Get parent span from header if not already present and allowed if options.Parent == nil && options.FromHeader { - if span, err := t.readSpanFromHeader(header); err != nil { + if span, err := t.readSpanFromHeader(header); err != nil && !t.options.AllowInvalidParentSpans { return nil, err } else if span != nil { options.Parent = span