Merge pull request #32898 from marcingrzejszczak

* gh-32898:
  Add missing BaggageTextMapPropagator for OTel W3C

Closes gh-32898
This commit is contained in:
Moritz Halbritter
2022-10-27 09:33:44 +02:00
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