Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.extension.trace.propagation;

import static io.opentelemetry.extension.trace.propagation.B3Propagator.DEBUG_HEADER;
import static io.opentelemetry.extension.trace.propagation.B3Propagator.SAMPLED_HEADER;
import static io.opentelemetry.extension.trace.propagation.B3Propagator.SPAN_ID_HEADER;
import static io.opentelemetry.extension.trace.propagation.B3Propagator.TRACE_ID_HEADER;
Expand All @@ -22,7 +23,8 @@
@Immutable
final class B3PropagatorInjectorMultipleHeaders implements B3PropagatorInjector {
private static final Collection<String> FIELDS =
Collections.unmodifiableList(Arrays.asList(TRACE_ID_HEADER, SPAN_ID_HEADER, SAMPLED_HEADER));
Collections.unmodifiableList(
Arrays.asList(TRACE_ID_HEADER, SPAN_ID_HEADER, SAMPLED_HEADER, DEBUG_HEADER));

@Override
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ void extract_nullGetter() {
void fieldsList_multiInject() {
assertThat(b3Propagator.fields())
.containsExactly(
B3Propagator.TRACE_ID_HEADER, B3Propagator.SPAN_ID_HEADER, B3Propagator.SAMPLED_HEADER);
B3Propagator.TRACE_ID_HEADER,
B3Propagator.SPAN_ID_HEADER,
B3Propagator.SAMPLED_HEADER,
B3Propagator.DEBUG_HEADER);
}

@Test
Expand Down Expand Up @@ -693,6 +696,38 @@ void extract_DebugContext_SampledTrueDebugTrue_MultipleHeaders() {
assertThat(context.get(DEBUG_CONTEXT_KEY)).isTrue();
}

@Test
void inject_ReusedCarrier_DoesNotRetainDebugFlag() {
Map<String, String> carrier = new LinkedHashMap<>();

Context debugContext =
withSpanContext(
SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()),
Context.root().with(DEBUG_CONTEXT_KEY, true));

b3Propagator.inject(debugContext, carrier, setter);
assertThat(carrier).containsEntry(B3Propagator.DEBUG_HEADER, Common.TRUE_INT);

for (String header : b3Propagator.fields()) {
carrier.remove(header);
}

Context normalContext =
withSpanContext(
SpanContext.create(
EXTRA_TRACE_ID, EXTRA_SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()),
Context.root());

b3Propagator.inject(normalContext, carrier, setter);

assertThat(carrier).doesNotContainKey(B3Propagator.DEBUG_HEADER);
assertThat(carrier).containsEntry(B3Propagator.SAMPLED_HEADER, Common.FALSE_INT);

// The receiver must also see this request as unsampled.
Context extractedContext = b3Propagator.extract(Context.root(), carrier, getter);
assertThat(getSpanContext(extractedContext).isSampled()).isFalse();
}

@Test
void inject_DebugContext_MultipleHeaders() {
Map<String, String> carrier = new LinkedHashMap<>();
Expand Down
Loading