Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use autoconfigure SPI for trace-propagators extension. #3294

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/trace-propagators/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion sdk-extensions/autoconfigure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down