Skip to content

Commit

Permalink
Add option to ignore invalid parent spans (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdavis-joy authored Aug 7, 2023
1 parent 66946b9 commit 23ff5a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 10 additions & 4 deletions contrib/opentelemetry/tracing_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down
7 changes: 6 additions & 1 deletion interceptor/tracing_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23ff5a7

Please sign in to comment.