|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.tracing; |
18 | 18 |
|
19 | 19 | import java.util.Collections; |
| 20 | +import java.util.HashMap; |
20 | 21 | import java.util.List; |
| 22 | +import java.util.Map; |
21 | 23 | import java.util.stream.Stream; |
22 | 24 |
|
23 | 25 | import brave.Span; |
|
31 | 33 | import brave.propagation.CurrentTraceContext.ScopeDecorator; |
32 | 34 | import brave.propagation.Propagation; |
33 | 35 | import brave.propagation.Propagation.Factory; |
| 36 | +import brave.propagation.TraceContext; |
34 | 37 | import brave.sampler.Sampler; |
35 | 38 | import io.micrometer.tracing.brave.bridge.BraveBaggageManager; |
36 | 39 | import io.micrometer.tracing.brave.bridge.BraveSpanCustomizer; |
@@ -152,6 +155,31 @@ void shouldSupplyB3PropagationFactoryViaProperty() { |
152 | 155 | }); |
153 | 156 | } |
154 | 157 |
|
| 158 | + @Test |
| 159 | + void shouldUseB3SingleWithParentWhenPropagationTypeIsB3() { |
| 160 | + this.contextRunner |
| 161 | + .withPropertyValues("management.tracing.propagation.type=B3", "management.tracing.sampling.probability=1.0") |
| 162 | + .run((context) -> { |
| 163 | + Propagation<String> propagation = context.getBean(Factory.class).get(); |
| 164 | + Tracer tracer = context.getBean(Tracing.class).tracer(); |
| 165 | + Span child; |
| 166 | + Span parent = tracer.nextSpan().name("parent"); |
| 167 | + try (Tracer.SpanInScope ignored = tracer.withSpanInScope(parent.start())) { |
| 168 | + child = tracer.nextSpan().name("child"); |
| 169 | + child.start().finish(); |
| 170 | + } |
| 171 | + finally { |
| 172 | + parent.finish(); |
| 173 | + } |
| 174 | + |
| 175 | + Map<String, String> map = new HashMap<>(); |
| 176 | + TraceContext childContext = child.context(); |
| 177 | + propagation.injector(this::injectToMap).inject(childContext, map); |
| 178 | + assertThat(map).containsExactly(Map.entry("b3", "%s-%s-1-%s".formatted(childContext.traceIdString(), |
| 179 | + childContext.spanIdString(), childContext.parentIdString()))); |
| 180 | + }); |
| 181 | + } |
| 182 | + |
155 | 183 | @Test |
156 | 184 | void shouldNotSupplyCorrelationScopeDecoratorIfBaggageDisabled() { |
157 | 185 | this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false") |
@@ -313,6 +341,10 @@ void compositeSpanHandlerUsesFilterPredicateAndReportersInOrder() { |
313 | 341 | }); |
314 | 342 | } |
315 | 343 |
|
| 344 | + private void injectToMap(Map<String, String> map, String key, String value) { |
| 345 | + map.put(key, value); |
| 346 | + } |
| 347 | + |
316 | 348 | private List<Factory> getInjectors(Factory factory) { |
317 | 349 | assertThat(factory).as("factory").isNotNull(); |
318 | 350 | if (factory instanceof CompositePropagationFactory compositePropagationFactory) { |
|
0 commit comments