From 31ca94833a0d4670305de66dff270cd21cc1b6b0 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 19 Jan 2023 09:09:10 +0100 Subject: [PATCH] Use parent-based sampler by default Closes gh-33821 --- .../tracing/OpenTelemetryAutoConfiguration.java | 3 ++- .../tracing/OpenTelemetryAutoConfigurationTests.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java index e9068cdc27..2c5a8b85c8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java @@ -112,7 +112,8 @@ public class OpenTelemetryAutoConfiguration { @Bean @ConditionalOnMissingBean Sampler otelSampler() { - return Sampler.traceIdRatioBased(this.tracingProperties.getSampling().getProbability()); + Sampler rootSampler = Sampler.traceIdRatioBased(this.tracingProperties.getSampling().getProbability()); + return Sampler.parentBased(rootSampler); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java index d56190dd72..351496970e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java @@ -80,6 +80,15 @@ class OpenTelemetryAutoConfigurationTests { }); } + @Test + void samplerIsParentBased() { + this.contextRunner.run((context) -> { + Sampler sampler = context.getBean(Sampler.class); + assertThat(sampler).isNotNull(); + assertThat(sampler.getDescription()).startsWith("ParentBased{"); + }); + } + @ParameterizedTest @ValueSource(strings = { "io.micrometer.tracing.otel", "io.opentelemetry.sdk", "io.opentelemetry.api" }) void shouldNotSupplyBeansIfDependencyIsMissing(String packageName) {