Skip to content

Commit

Permalink
Add option to ignore invalid parent spans
Browse files Browse the repository at this point in the history
  • Loading branch information
cdavis-joy authored and Quinn-With-Two-Ns committed Jul 31, 2023
1 parent 6523916 commit d8d4778
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 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
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 d8d4778

Please sign in to comment.