diff --git a/sdk-extensions/incubator/build.gradle.kts b/sdk-extensions/incubator/build.gradle.kts index 7a07f3c8fa6..847a3b039e6 100644 --- a/sdk-extensions/incubator/build.gradle.kts +++ b/sdk-extensions/incubator/build.gradle.kts @@ -54,8 +54,8 @@ dependencies { // 6. deleteJs2pTmp - delete tmp directory // ... proceed with normal sourcesJar, compileJava, etc -// TODO(jack-berg): update ref to be released version when available -val configurationRef = "0508846f82ed54b230fa638e1e7556c52efee25e" +val configurationTag = "0.1.0" +val configurationRef = "refs/tags/v$configurationTag" // Replace with commit SHA to point to experiment with a specific commit val configurationRepoZip = "https://github.com/open-telemetry/opentelemetry-configuration/archive/$configurationRef.zip" val buildDirectory = layout.buildDirectory.asFile.get() diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java index 17c68f9ada2..cb2b52a8472 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java @@ -45,7 +45,7 @@ public OpenTelemetrySdk create( } builder.setPropagators( - PropagatorsFactory.getInstance().create(model.getPropagators(), spiHelper, closeables)); + PropagatorFactory.getInstance().create(model.getPropagator(), spiHelper, closeables)); Resource resource = ResourceFactory.getInstance().create(model.getResource(), spiHelper, closeables); diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactory.java new file mode 100644 index 00000000000..d53c3beda76 --- /dev/null +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactory.java @@ -0,0 +1,37 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.extension.incubator.fileconfig; + +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Propagator; +import java.io.Closeable; +import java.util.List; +import javax.annotation.Nullable; + +final class PropagatorFactory implements Factory { + + private static final PropagatorFactory INSTANCE = new PropagatorFactory(); + + private PropagatorFactory() {} + + static PropagatorFactory getInstance() { + return INSTANCE; + } + + @Override + public ContextPropagators create( + @Nullable Propagator model, SpiHelper spiHelper, List closeables) { + List compositeModel = null; + if (model != null) { + compositeModel = model.getComposite(); + } + TextMapPropagator textMapPropagator = + TextMapPropagatorFactory.getInstance().create(compositeModel, spiHelper, closeables); + return ContextPropagators.create(textMapPropagator); + } +} diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java similarity index 80% rename from sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactory.java rename to sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java index cbd6c82bbc0..4451ac98516 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.autoconfigure.internal.NamedSpiManager; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; @@ -22,18 +21,18 @@ import java.util.Set; import javax.annotation.Nullable; -final class PropagatorsFactory implements Factory, ContextPropagators> { +final class TextMapPropagatorFactory implements Factory, TextMapPropagator> { - private static final PropagatorsFactory INSTANCE = new PropagatorsFactory(); + private static final TextMapPropagatorFactory INSTANCE = new TextMapPropagatorFactory(); - private PropagatorsFactory() {} + private TextMapPropagatorFactory() {} - static PropagatorsFactory getInstance() { + static TextMapPropagatorFactory getInstance() { return INSTANCE; } @Override - public ContextPropagators create( + public TextMapPropagator create( @Nullable List model, SpiHelper spiHelper, List closeables) { if (model == null || model.isEmpty()) { model = Arrays.asList("tracecontext", "baggage"); @@ -44,7 +43,7 @@ public ContextPropagators create( throw new ConfigurationException( "propagators contains \"none\" along with other propagators"); } - return ContextPropagators.noop(); + return TextMapPropagator.noop(); } NamedSpiManager spiPropagatorsManager = @@ -58,7 +57,7 @@ public ContextPropagators create( propagators.add(getPropagator(propagator, spiPropagatorsManager)); } - return ContextPropagators.create(TextMapPropagator.composite(propagators)); + return TextMapPropagator.composite(propagators); } private static TextMapPropagator getPropagator( @@ -74,6 +73,6 @@ private static TextMapPropagator getPropagator( if (spiPropagator != null) { return spiPropagator; } - throw new ConfigurationException("Unrecognized value for otel.propagators: " + name); + throw new ConfigurationException("Unrecognized propagator: " + name); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ConfigurationReaderTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ConfigurationReaderTest.java index 27d6e14cc0a..afdb4cac33e 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ConfigurationReaderTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ConfigurationReaderTest.java @@ -31,6 +31,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ParentBased; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PeriodicMetricReader; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Prometheus; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Propagator; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PullMetricReader; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Resource; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Sampler; @@ -50,7 +51,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; class ConfigurationReaderTest { @@ -71,9 +71,12 @@ void read_KitchenSinkExampleFile() throws IOException { new AttributeLimits().withAttributeValueLengthLimit(4096).withAttributeCountLimit(128); expected.withAttributeLimits(attributeLimits); - List propagators = - Arrays.asList("tracecontext", "baggage", "b3", "b3multi", "jaeger", "xray", "ottrace"); - expected.withPropagators(propagators); + Propagator propagator = + new Propagator() + .withComposite( + Arrays.asList( + "tracecontext", "baggage", "b3", "b3multi", "jaeger", "xray", "ottrace")); + expected.withPropagator(propagator); // TracerProvider config TracerProvider tracerProvider = new TracerProvider(); @@ -253,7 +256,7 @@ void read_KitchenSinkExampleFile() throws IOException { assertThat(config.getFileFormat()).isEqualTo("0.1"); assertThat(config.getResource()).isEqualTo(resource); assertThat(config.getAttributeLimits()).isEqualTo(attributeLimits); - assertThat(config.getPropagators()).isEqualTo(propagators); + assertThat(config.getPropagator()).isEqualTo(propagator); // TracerProvider config TracerProvider configTracerProvider = config.getTracerProvider(); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java index 3bede9ea2e5..ac249c94b9a 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java @@ -38,6 +38,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Otlp; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpMetric; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PeriodicMetricReader; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Propagator; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Resource; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Sampler; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Selector; @@ -223,9 +224,16 @@ void create_Configured() { .create( new OpenTelemetryConfiguration() .withFileFormat("0.1") - .withPropagators( - Arrays.asList( - "tracecontext", "baggage", "ottrace", "b3multi", "b3", "jaeger")) + .withPropagator( + new Propagator() + .withComposite( + Arrays.asList( + "tracecontext", + "baggage", + "ottrace", + "b3multi", + "b3", + "jaeger"))) .withResource( new Resource() .withAttributes( diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactoryTest.java new file mode 100644 index 00000000000..ba9f6190e95 --- /dev/null +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorFactoryTest.java @@ -0,0 +1,60 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.extension.incubator.fileconfig; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; + +import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +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.internal.SpiHelper; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Propagator; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class PropagatorFactoryTest { + + private final SpiHelper spiHelper = + SpiHelper.create(PropagatorFactoryTest.class.getClassLoader()); + + @ParameterizedTest + @MethodSource("createArguments") + void create(Propagator model, ContextPropagators expectedPropagators) { + ContextPropagators propagators = + PropagatorFactory.getInstance().create(model, spiHelper, Collections.emptyList()); + + assertThat(propagators.toString()).isEqualTo(expectedPropagators.toString()); + } + + private static Stream createArguments() { + return Stream.of( + Arguments.of( + null, + ContextPropagators.create( + TextMapPropagator.composite( + W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()))), + Arguments.of( + new Propagator() + .withComposite( + Arrays.asList("tracecontext", "baggage", "ottrace", "b3multi", "b3", "jaeger")), + ContextPropagators.create( + TextMapPropagator.composite( + W3CTraceContextPropagator.getInstance(), + W3CBaggagePropagator.getInstance(), + OtTracePropagator.getInstance(), + B3Propagator.injectingMultiHeaders(), + B3Propagator.injectingSingleHeader(), + JaegerPropagator.getInstance())))); + } +} diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java similarity index 58% rename from sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactoryTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java index 293d40717ab..a0a0f6de49d 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/PropagatorsFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java @@ -10,7 +10,6 @@ import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; 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; @@ -26,50 +25,47 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -class PropagatorsFactoryTest { +class TextMapPropagatorFactoryTest { private final SpiHelper spiHelper = - SpiHelper.create(PropagatorsFactoryTest.class.getClassLoader()); + SpiHelper.create(TextMapPropagatorFactoryTest.class.getClassLoader()); @ParameterizedTest @MethodSource("createArguments") - void create(List model, ContextPropagators expectedPropagators) { - ContextPropagators propagators = - PropagatorsFactory.getInstance().create(model, spiHelper, Collections.emptyList()); + void create(List model, TextMapPropagator expectedPropagator) { + TextMapPropagator propagator = + TextMapPropagatorFactory.getInstance().create(model, spiHelper, Collections.emptyList()); - assertThat(propagators.toString()).isEqualTo(expectedPropagators.toString()); + assertThat(propagator.toString()).isEqualTo(expectedPropagator.toString()); } private static Stream createArguments() { return Stream.of( Arguments.of( null, - ContextPropagators.create( - TextMapPropagator.composite( - W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()))), + TextMapPropagator.composite( + W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance())), Arguments.of( Collections.emptyList(), - ContextPropagators.create( - TextMapPropagator.composite( - W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()))), - Arguments.of(Collections.singletonList("none"), ContextPropagators.noop()), + TextMapPropagator.composite( + W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance())), + Arguments.of(Collections.singletonList("none"), TextMapPropagator.noop()), Arguments.of( Arrays.asList("tracecontext", "baggage", "ottrace", "b3multi", "b3", "jaeger"), - ContextPropagators.create( - TextMapPropagator.composite( - W3CTraceContextPropagator.getInstance(), - W3CBaggagePropagator.getInstance(), - OtTracePropagator.getInstance(), - B3Propagator.injectingMultiHeaders(), - B3Propagator.injectingSingleHeader(), - JaegerPropagator.getInstance())))); + TextMapPropagator.composite( + W3CTraceContextPropagator.getInstance(), + W3CBaggagePropagator.getInstance(), + OtTracePropagator.getInstance(), + B3Propagator.injectingMultiHeaders(), + B3Propagator.injectingSingleHeader(), + JaegerPropagator.getInstance()))); } @Test void create_NoneAndOther() { assertThatThrownBy( () -> - PropagatorsFactory.getInstance() + TextMapPropagatorFactory.getInstance() .create(Arrays.asList("none", "foo"), spiHelper, Collections.emptyList())) .isInstanceOf(ConfigurationException.class) .hasMessage("propagators contains \"none\" along with other propagators"); @@ -79,9 +75,9 @@ void create_NoneAndOther() { void create_UnknownSpiPropagator() { assertThatThrownBy( () -> - PropagatorsFactory.getInstance() + TextMapPropagatorFactory.getInstance() .create(Collections.singletonList("foo"), spiHelper, Collections.emptyList())) .isInstanceOf(ConfigurationException.class) - .hasMessage("Unrecognized value for otel.propagators: foo"); + .hasMessage("Unrecognized propagator: foo"); } }