Skip to content

Commit d7d4ed6

Browse files
committed
Ignore non-existent span headers
1 parent a760de3 commit d7d4ed6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

contrib/opentelemetry/tracing_interceptor.go

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func (t *tracer) Options() interceptor.TracerOptions {
148148
}
149149

150150
func (t *tracer) UnmarshalSpan(m map[string]string) (interceptor.TracerSpanRef, error) {
151+
if _, ok := m["traceparent"]; !ok {
152+
// If there is no span, return nothing, but don't error out. This is
153+
// a legitimate place where a span does not exist in the headers
154+
return nil, nil
155+
}
151156
ctx := t.options.TextMapPropagator.Extract(context.Background(), textMapCarrier(m))
152157
spanCtx := trace.SpanContextFromContext(ctx)
153158
if !spanCtx.IsValid() {

contrib/opentracing/interceptor.go

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package opentracing
2525

2626
import (
2727
"context"
28+
"errors"
2829
"fmt"
2930

3031
"github.com/opentracing/opentracing-go"
@@ -111,6 +112,11 @@ func (t *tracer) Options() interceptor.TracerOptions {
111112

112113
func (t *tracer) UnmarshalSpan(m map[string]string) (interceptor.TracerSpanRef, error) {
113114
ctx, err := t.options.Tracer.Extract(opentracing.TextMap, opentracing.TextMapCarrier(m))
115+
if errors.Is(err, opentracing.ErrSpanContextNotFound) {
116+
// If there is no span, return nothing, but don't error out. This is
117+
// a legitimate place where a span does not exist in the headers
118+
return nil, nil
119+
}
114120
if err != nil {
115121
return nil, err
116122
}

interceptor/tracing_interceptor.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,7 @@ func (t *tracingInterceptor) writeSpanToNexusHeader(span TracerSpan, header nexu
10231023
}
10241024

10251025
func (t *tracingInterceptor) readSpanFromNexusHeader(header nexus.Header) (TracerSpanRef, error) {
1026-
// Ignore unmarshal errors, e.g. when an expected header isn't set.
1027-
// This works differently from non Nexus headers where the trace context is serialized entirely into a single
1028-
// payload and the presence of that payload implies a valid header.
1029-
span, _ := t.tracer.UnmarshalSpan(header)
1030-
return span, nil
1026+
return t.tracer.UnmarshalSpan(header)
10311027
}
10321028

10331029
func workflowFutureFromErr(ctx workflow.Context, err error) workflow.Future {

0 commit comments

Comments
 (0)