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

Change B3 extraction format to single #36061

Closed
Closed
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 @@ -124,7 +124,7 @@ Propagation.Factory map(PropagationType type) {
* @return the B3 propagation factory
*/
private Propagation.Factory b3Single() {
return B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.SINGLE_NO_PARENT).build();
return B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.SINGLE).build();
jonatan-ivanov marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.springframework.boot.actuate.autoconfigure.tracing;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import brave.Span;
Expand All @@ -31,6 +33,7 @@
import brave.propagation.CurrentTraceContext.ScopeDecorator;
import brave.propagation.Propagation;
import brave.propagation.Propagation.Factory;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import io.micrometer.tracing.brave.bridge.BraveBaggageManager;
import io.micrometer.tracing.brave.bridge.BraveSpanCustomizer;
Expand Down Expand Up @@ -152,6 +155,31 @@ void shouldSupplyB3PropagationFactoryViaProperty() {
});
}

@Test
void shouldUseB3SingleWithParentWhenPropagationTypeIsB3() {
this.contextRunner
.withPropertyValues("management.tracing.propagation.type=B3", "management.tracing.sampling.probability=1.0")
.run((context) -> {
Propagation<String> propagation = context.getBean(Factory.class).get();
Tracer tracer = context.getBean(Tracing.class).tracer();
Span child;
Span parent = tracer.nextSpan().name("parent");
try (Tracer.SpanInScope ignored = tracer.withSpanInScope(parent.start())) {
child = tracer.nextSpan().name("child");
child.start().finish();
}
finally {
parent.finish();
}

Map<String, String> map = new HashMap<>();
TraceContext childContext = child.context();
propagation.injector(this::injectToMap).inject(childContext, map);
assertThat(map).containsExactly(Map.entry("b3", "%s-%s-1-%s".formatted(childContext.traceIdString(),
childContext.spanIdString(), childContext.parentIdString())));
});
}

@Test
void shouldNotSupplyCorrelationScopeDecoratorIfBaggageDisabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false")
Expand Down Expand Up @@ -313,6 +341,10 @@ void compositeSpanHandlerUsesFilterPredicateAndReportersInOrder() {
});
}

private void injectToMap(Map<String, String> map, String key, String value) {
map.put(key, value);
}

private List<Factory> getInjectors(Factory factory) {
assertThat(factory).as("factory").isNotNull();
if (factory instanceof CompositePropagationFactory compositePropagationFactory) {
Expand Down