Skip to content

Commit 80f31c5

Browse files
authored
Merge branch 'main' into stl_dll_fix
2 parents f34c06c + 758687c commit 80f31c5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

opentracing-shim/src/tracer_shim.cc

+14-7
Original file line numberDiff line numberDiff line change
@@ -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

opentracing-shim/test/tracer_shim_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ TEST_F(TracerShimTest, ExtractOnlyBaggage)
211211
auto span_context_shim = static_cast<shim::SpanContextShim *>(span_context.value().get());
212212
ASSERT_TRUE(span_context_shim != nullptr);
213213
ASSERT_FALSE(span_context_shim->context().IsValid());
214+
ASSERT_FALSE(span_context_shim->context().IsSampled());
214215
ASSERT_FALSE(shim::utils::isBaggageEmpty(span_context_shim->baggage()));
215216

216217
std::string value;

0 commit comments

Comments
 (0)