From 23bdb7eb06c5edb899b81681a3135675e34048d1 Mon Sep 17 00:00:00 2001 From: kitbolourchi <74569356+KitBolourchi@users.noreply.github.com> Date: Sat, 24 Jun 2023 15:32:57 +0100 Subject: [PATCH 1/2] Change: change to _SINGLE for B3 --- .../tracing/CompositePropagationFactory.java | 2 +- .../CompositePropagationFactoryTests.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactory.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactory.java index 0ec3db30c2b7..2c653b362d4e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactory.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactory.java @@ -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(); } /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java index a232104de4ce..4808b831e07a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.Map; +import brave.Span; +import brave.Tracing; import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.Propagation; import brave.propagation.TraceContext; @@ -28,6 +30,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -67,6 +71,9 @@ void requires128BitTraceId() { @Nested static class CompostePropagationTests { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(CompositePropagationFactory.class)); + @Test void keys() { CompositePropagationFactory factory = new CompositePropagationFactory(List.of(field("a")), @@ -86,6 +93,23 @@ void inject() { assertThat(request).containsOnly(entry("a", "a-value"), entry("b", "b-value")); } + @Test + void thisIsATest() { + this.contextRunner + .withPropertyValues("management.tracing.propagation.type=B3", + "management.tracing.brave.span-joining-supported=true") + .run((context) -> { + CompositePropagationFactory factory = new CompositePropagationFactory(List.of(field("a"), field("b")), + List.of(field("c"))); + Propagation propagation = factory.get(); + Tracing tracing = context.getBean(Tracing.class); + Span parentSpan = tracing.tracer().nextSpan(); + Span childSpan = tracing.tracer().joinSpan(parentSpan.context()); + Map request = new HashMap<>(); + propagation.injector(new CompositePropagationFactoryTests.MapSetter()).inject(parentSpan.context(), request); + }); + } + @Test void extractorWhenDelegateExtractsReturnsExtraction() { CompositePropagationFactory factory = new CompositePropagationFactory(Collections.emptyList(), From 7df07d703de1c6d1d373435382a3723c28101ab7 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Wed, 12 Jul 2023 17:42:09 -0700 Subject: [PATCH 2/2] tests --- .../tracing/BraveAutoConfigurationTests.java | 32 +++++++++++++++++++ .../CompositePropagationFactoryTests.java | 24 -------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfigurationTests.java index f97f4c8c8c8a..372166ed2555 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfigurationTests.java @@ -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.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 @@ void shouldSupplyB3PropagationFactoryViaProperty() { }); } + @Test + void shouldUseB3SingleWithParentWhenPropagationTypeIsB3() { + this.contextRunner + .withPropertyValues("management.tracing.propagation.type=B3", "management.tracing.sampling.probability=1.0") + .run((context) -> { + Propagation 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 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 @@ void compositeSpanHandlerUsesFilterPredicateAndReportersInOrder() { }); } + private void injectToMap(Map map, String key, String value) { + map.put(key, value); + } + private List getInjectors(Factory factory) { assertThat(factory).as("factory").isNotNull(); if (factory instanceof CompositePropagationFactory compositePropagationFactory) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java index 4808b831e07a..a232104de4ce 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java @@ -21,8 +21,6 @@ import java.util.List; import java.util.Map; -import brave.Span; -import brave.Tracing; import brave.internal.propagation.StringPropagationAdapter; import brave.propagation.Propagation; import brave.propagation.TraceContext; @@ -30,8 +28,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -71,9 +67,6 @@ void requires128BitTraceId() { @Nested static class CompostePropagationTests { - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(CompositePropagationFactory.class)); - @Test void keys() { CompositePropagationFactory factory = new CompositePropagationFactory(List.of(field("a")), @@ -93,23 +86,6 @@ void inject() { assertThat(request).containsOnly(entry("a", "a-value"), entry("b", "b-value")); } - @Test - void thisIsATest() { - this.contextRunner - .withPropertyValues("management.tracing.propagation.type=B3", - "management.tracing.brave.span-joining-supported=true") - .run((context) -> { - CompositePropagationFactory factory = new CompositePropagationFactory(List.of(field("a"), field("b")), - List.of(field("c"))); - Propagation propagation = factory.get(); - Tracing tracing = context.getBean(Tracing.class); - Span parentSpan = tracing.tracer().nextSpan(); - Span childSpan = tracing.tracer().joinSpan(parentSpan.context()); - Map request = new HashMap<>(); - propagation.injector(new CompositePropagationFactoryTests.MapSetter()).inject(parentSpan.context(), request); - }); - } - @Test void extractorWhenDelegateExtractsReturnsExtraction() { CompositePropagationFactory factory = new CompositePropagationFactory(Collections.emptyList(),