Merge pull request #36061 from KitBolourchi

* pr/36061:
  Change B3 extraction format to single

Closes gh-36061
pull/36422/head
Moritz Halbritter 1 year ago
commit c3be59889e

@ -124,7 +124,7 @@ class CompositePropagationFactory extends Propagation.Factory {
* @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();
}
/**

@ -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;
@ -31,6 +33,7 @@ import brave.propagation.CurrentTraceContext;
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;
@ -152,6 +155,31 @@ class BraveAutoConfigurationTests {
});
}
@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")
@ -313,6 +341,10 @@ class BraveAutoConfigurationTests {
});
}
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) {

Loading…
Cancel
Save