Add missing BaggageTextMapPropagator for OTel W3C

Without this change we're missing the BaggageTextMapPropagator for
OTel. This means that we're not propagating remote-fields
(only baggage via the 'baggage' field).

With this change we're adding the missing propagator as
THE LAST entry in the composite TextMapPropagator. It has to be
last cause with the latest Snapshots of Micrometer Tracing it
will append the remote field baggage to existing baggage in the
context extracted via the W3CBaggagePropagator.

See gh-32898
This commit is contained in:
Marcin Grzejszczak 2022-10-27 00:32:41 +02:00 committed by Moritz Halbritter
parent 1f0cf1ac2b
commit b753170807
2 changed files with 11 additions and 3 deletions

View File

@ -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<String> remoteFields = this.tracingProperties.getBaggage().getRemoteFields();
return TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(),
W3CBaggagePropagator.getInstance());
W3CBaggagePropagator.getInstance(), new BaggageTextMapPropagator(remoteFields,
new OtelBaggageManager(otelCurrentTraceContext, remoteFields, Collections.emptyList())));
}
@Bean

View File

@ -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<String> allFields = context.getBean("w3cTextMapPropagatorWithBaggage", TextMapPropagator.class)
.fields();
assertThat(allFields).containsExactly("traceparent", "tracestate", "baggage", "foo");
});
}
@Test