@@ -148,13 +148,20 @@ opentracing::expected<std::unique_ptr<opentracing::SpanContext>> TracerShim::ext
148148 auto span_context = opentelemetry::trace::GetSpan (context)->GetContext ();
149149 auto baggage = opentelemetry::baggage::GetBaggage (context);
150150
151- // If the extracted SpanContext is invalid AND the extracted Baggage is empty,
152- // this operation MUST return a null value, and otherwise it MUST return a
153- // SpanContext Shim instance with the extracted values.
154- SpanContextShim *context_shim = (!span_context.IsValid () && utils::isBaggageEmpty (baggage))
155- ? nullptr
156- : new (std::nothrow) SpanContextShim (span_context, baggage);
157-
151+ // The operation MUST return a `SpanContext` Shim instance with the extracted values if any of
152+ // these conditions are met:
153+ // * `SpanContext` is valid.
154+ // * `SpanContext` is sampled.
155+ // * `SpanContext` contains non-empty extracted `Baggage`.
156+ // Otherwise, the operation MUST return null or empty value.
157+ SpanContextShim *context_shim =
158+ (!span_context.IsValid () && !span_context.IsSampled () && utils::isBaggageEmpty (baggage))
159+ ? nullptr
160+ : new (std::nothrow) SpanContextShim (span_context, baggage);
161+
162+ // Note: Invalid but sampled `SpanContext` instances are returned as a way to support
163+ // jaeger-debug-id headers (https://github.com/jaegertracing/jaeger-client-java#via-http-headers)
164+ // which are used to force propagation of debug information.
158165 return opentracing::make_expected (std::unique_ptr<opentracing::SpanContext>(context_shim));
159166}
160167
0 commit comments