Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ignore invalid parent spans #1178

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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