diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java index 024b8e58c09..ad909019d06 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java @@ -38,6 +38,13 @@ static ContextPropagators configurePropagators( config, serviceClassLoader); + if (requestedPropagators.contains("none")) { + if (requestedPropagators.size() > 1) { + throw new ConfigurationException( + "otel.propagators contains 'none' along with other propagators"); + } + return ContextPropagators.noop(); + } for (String propagatorName : requestedPropagators) { propagators.add( propagatorCustomizer.apply(getPropagator(propagatorName, spiPropagatorsManager), config)); diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java index e7e285073e5..f8b66b75d49 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java @@ -28,6 +28,31 @@ void defaultPropagators() { .containsExactlyInAnyOrder("traceparent", "tracestate", "baggage"); } + @Test + void configurePropagators_none() { + ContextPropagators contextPropagators = + PropagatorConfiguration.configurePropagators( + DefaultConfigProperties.createForTest( + Collections.singletonMap("otel.propagators", "none")), + PropagatorConfiguration.class.getClassLoader(), + (a, unused) -> a); + + assertThat(contextPropagators.getTextMapPropagator().fields()).isEmpty(); + } + + @Test + void configurePropagators_none_withOthers() { + assertThatThrownBy( + () -> + PropagatorConfiguration.configurePropagators( + DefaultConfigProperties.createForTest( + Collections.singletonMap("otel.propagators", "none,blather")), + PropagatorConfiguration.class.getClassLoader(), + (a, unused) -> a)) + .isInstanceOf(ConfigurationException.class) + .hasMessage("otel.propagators contains 'none' along with other propagators"); + } + @Test void configurePropagators_NotOnClasspath() { assertThatThrownBy(