diff --git a/extensions/trace-propagators/build.gradle.kts b/extensions/trace-propagators/build.gradle.kts index 2933f417a65..67683e5c57f 100644 --- a/extensions/trace-propagators/build.gradle.kts +++ b/extensions/trace-propagators/build.gradle.kts @@ -12,6 +12,8 @@ extra["moduleName"] = "io.opentelemetry.extension.trace.propagation" dependencies { api(project(":api:all")) + compileOnly(project(":sdk-extensions:autoconfigure")) + testImplementation("io.jaegertracing:jaeger-client") testImplementation("com.google.guava:guava") diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3ConfigurablePropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3ConfigurablePropagator.java new file mode 100644 index 00000000000..4bbd434aeac --- /dev/null +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3ConfigurablePropagator.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.extension.trace.propagation; + +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; + +/** + * A {@link ConfigurablePropagatorProvider} which allows enabling the {@linkplain + * B3Propagator#injectingSingleHeader()} B3-single propagator} with the propagator name {@code b3}. + */ +public final class B3ConfigurablePropagator implements ConfigurablePropagatorProvider { + @Override + public TextMapPropagator getPropagator() { + return B3Propagator.injectingSingleHeader(); + } + + @Override + public String getName() { + return "b3"; + } +} diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3MultiConfigurablePropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3MultiConfigurablePropagator.java new file mode 100644 index 00000000000..34945a16f09 --- /dev/null +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3MultiConfigurablePropagator.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.extension.trace.propagation; + +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; + +/** + * A {@link ConfigurablePropagatorProvider} which allows enabling the {@linkplain + * B3Propagator#injectingMultiHeaders() B3-multi propagator} with the propagator name {@code + * b3multi}. + */ +public final class B3MultiConfigurablePropagator implements ConfigurablePropagatorProvider { + @Override + public TextMapPropagator getPropagator() { + return B3Propagator.injectingMultiHeaders(); + } + + @Override + public String getName() { + return "b3multi"; + } +} diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerConfigurablePropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerConfigurablePropagator.java new file mode 100644 index 00000000000..720f8e7d970 --- /dev/null +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerConfigurablePropagator.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.extension.trace.propagation; + +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; + +/** + * A {@link ConfigurablePropagatorProvider} which allows enabling the {@link JaegerPropagator} with + * the propagator name {@code jaeger}. + */ +public final class JaegerConfigurablePropagator implements ConfigurablePropagatorProvider { + @Override + public TextMapPropagator getPropagator() { + return JaegerPropagator.getInstance(); + } + + @Override + public String getName() { + return "jaeger"; + } +} diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTraceConfigurablePropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTraceConfigurablePropagator.java new file mode 100644 index 00000000000..943d771fef9 --- /dev/null +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTraceConfigurablePropagator.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.extension.trace.propagation; + +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; + +/** + * A {@link ConfigurablePropagatorProvider} which allows enabling the {@link OtTracePropagator} with + * the propagator name {@code ottrace}. + */ +public final class OtTraceConfigurablePropagator implements ConfigurablePropagatorProvider { + @Override + public TextMapPropagator getPropagator() { + return OtTracePropagator.getInstance(); + } + + @Override + public String getName() { + return "ottrace"; + } +} diff --git a/extensions/trace-propagators/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider b/extensions/trace-propagators/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider new file mode 100644 index 00000000000..f07ba17a1cd --- /dev/null +++ b/extensions/trace-propagators/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider @@ -0,0 +1,4 @@ +io.opentelemetry.extension.trace.propagation.B3ConfigurablePropagator +io.opentelemetry.extension.trace.propagation.B3MultiConfigurablePropagator +io.opentelemetry.extension.trace.propagation.JaegerConfigurablePropagator +io.opentelemetry.extension.trace.propagation.OtTraceConfigurablePropagator diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index e104346eeb1..b1e0a10e992 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -26,7 +26,6 @@ dependencies { implementation(project(":semconv")) - compileOnly(project(":extensions:trace-propagators")) compileOnly(project(":exporters:jaeger")) compileOnly(project(":exporters:logging")) compileOnly(project(":exporters:otlp:all")) 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 f66ba8d85fc..137a9fa7091 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 @@ -9,9 +9,6 @@ import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.extension.trace.propagation.B3Propagator; -import io.opentelemetry.extension.trace.propagation.JaegerPropagator; -import io.opentelemetry.extension.trace.propagation.OtTracePropagator; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; import java.util.Arrays; import java.util.LinkedHashSet; @@ -54,29 +51,14 @@ private static TextMapPropagator getPropagator( return W3CBaggagePropagator.getInstance(); } - // Other propagators are in the extension artifact. Check one of the propagators. - ClasspathUtil.checkClassExists( - "io.opentelemetry.extension.trace.propagation.B3Propagator", - name + " propagator", - "opentelemetry-extension-trace-propagators"); - - switch (name) { - case "b3": - return B3Propagator.injectingSingleHeader(); - case "b3multi": - return B3Propagator.injectingMultiHeaders(); - case "jaeger": - return JaegerPropagator.getInstance(); - // NB: https://github.com/open-telemetry/opentelemetry-specification/pull/1406 - case "ottrace": - return OtTracePropagator.getInstance(); - default: - TextMapPropagator spiPropagator = spiPropagators.get(name); - if (spiPropagator != null) { - return spiPropagator; - } - throw new ConfigurationException("Unrecognized value for otel.propagators: " + name); + TextMapPropagator spiPropagator = spiPropagators.get(name); + if (spiPropagator != null) { + return spiPropagator; } + throw new ConfigurationException( + "Unrecognized value for otel.propagators: " + + name + + ". Make sure the artifact including the propagator is on the classpath."); } private PropagatorConfiguration() {} diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index c2686149f67..f047c671466 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -93,8 +93,6 @@ void b3propagator() { ConfigProperties.createForTest( Collections.singletonMap("otel.propagators", "b3")))) .isInstanceOf(ConfigurationException.class) - .hasMessageContaining( - "b3 propagator enabled but opentelemetry-extension-trace-propagators not found on " - + "classpath"); + .hasMessageContaining("Unrecognized value for otel.propagators: b3"); } } diff --git a/sdk-extensions/autoconfigure/src/testConfigError/java/io/opentelemetry/sdk/autoconfigure/ConfigErrorTest.java b/sdk-extensions/autoconfigure/src/testConfigError/java/io/opentelemetry/sdk/autoconfigure/ConfigErrorTest.java index 2b1507563e1..7de0a76b5d1 100644 --- a/sdk-extensions/autoconfigure/src/testConfigError/java/io/opentelemetry/sdk/autoconfigure/ConfigErrorTest.java +++ b/sdk-extensions/autoconfigure/src/testConfigError/java/io/opentelemetry/sdk/autoconfigure/ConfigErrorTest.java @@ -30,7 +30,9 @@ class ConfigErrorTest { void invalidPropagator() { assertThatThrownBy(OpenTelemetrySdkAutoConfiguration::initialize) .isInstanceOf(ConfigurationException.class) - .hasMessage("Unrecognized value for otel.propagators: cat"); + .hasMessage( + "Unrecognized value for otel.propagators: cat. Make sure the artifact " + + "including the propagator is on the classpath."); } @Test