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 d1a6d125f7..7bf0a4fa93 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 @@ -195,9 +195,11 @@ public class OpenTelemetryAutoConfiguration { @Bean @ConditionalOnProperty(prefix = "management.tracing.propagation", name = "type", havingValue = "W3C", matchIfMissing = true) - TextMapPropagator w3cTextMapPropagatorWithBaggage() { + TextMapPropagator w3cTextMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurrentTraceContext) { + List remoteFields = this.tracingProperties.getBaggage().getRemoteFields(); return TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), - W3CBaggagePropagator.getInstance()); + W3CBaggagePropagator.getInstance(), new BaggageTextMapPropagator(remoteFields, + new OtelBaggageManager(otelCurrentTraceContext, remoteFields, Collections.emptyList()))); } @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 01cf07b6bd..b08312eeed 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 @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.tracing; +import java.util.Collection; import java.util.List; import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext; @@ -182,7 +183,12 @@ class OpenTelemetryAutoConfigurationTests { @Test void shouldSupplyW3CPropagationWithBaggageByDefault() { - this.contextRunner.run((context) -> assertThat(context).hasBean("w3cTextMapPropagatorWithBaggage")); + this.contextRunner.withPropertyValues("management.tracing.baggage.remote-fields=foo").run((context) -> { + assertThat(context).hasBean("w3cTextMapPropagatorWithBaggage"); + Collection allFields = context.getBean("w3cTextMapPropagatorWithBaggage", TextMapPropagator.class) + .fields(); + assertThat(allFields).containsExactly("traceparent", "tracestate", "baggage", "foo"); + }); } @Test