Skip to content

Commit

Permalink
Update to opentelemetry-configuration v0.1.0 (#5899)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Oct 11, 2023
1 parent ef3fef9 commit 1523ded
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 45 deletions.
4 changes: 2 additions & 2 deletions sdk-extensions/incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Propagator, ContextPropagators> {

private static final PropagatorFactory INSTANCE = new PropagatorFactory();

private PropagatorFactory() {}

static PropagatorFactory getInstance() {
return INSTANCE;
}

@Override
public ContextPropagators create(
@Nullable Propagator model, SpiHelper spiHelper, List<Closeable> closeables) {
List<String> compositeModel = null;
if (model != null) {
compositeModel = model.getComposite();
}
TextMapPropagator textMapPropagator =
TextMapPropagatorFactory.getInstance().create(compositeModel, spiHelper, closeables);
return ContextPropagators.create(textMapPropagator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,18 +21,18 @@
import java.util.Set;
import javax.annotation.Nullable;

final class PropagatorsFactory implements Factory<List<String>, ContextPropagators> {
final class TextMapPropagatorFactory implements Factory<List<String>, 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<String> model, SpiHelper spiHelper, List<Closeable> closeables) {
if (model == null || model.isEmpty()) {
model = Arrays.asList("tracecontext", "baggage");
Expand All @@ -44,7 +43,7 @@ public ContextPropagators create(
throw new ConfigurationException(
"propagators contains \"none\" along with other propagators");
}
return ContextPropagators.noop();
return TextMapPropagator.noop();
}

NamedSpiManager<TextMapPropagator> spiPropagatorsManager =
Expand All @@ -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(
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -71,9 +71,12 @@ void read_KitchenSinkExampleFile() throws IOException {
new AttributeLimits().withAttributeValueLengthLimit(4096).withAttributeCountLimit(128);
expected.withAttributeLimits(attributeLimits);

List<String> 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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> model, ContextPropagators expectedPropagators) {
ContextPropagators propagators =
PropagatorsFactory.getInstance().create(model, spiHelper, Collections.emptyList());
void create(List<String> 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<Arguments> 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");
Expand All @@ -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");
}
}

0 comments on commit 1523ded

Please sign in to comment.