Skip to content

Commit 5ffa348

Browse files
jack-bergrobsunday
authored andcommitted
Add declarative config support for aws xray propagators (open-telemetry#1442)
1 parent 151b744 commit 5ffa348

10 files changed

+109
-3
lines changed

aws-xray-propagator/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ dependencies {
1313
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
1414
testImplementation("io.opentelemetry:opentelemetry-sdk-trace")
1515
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
16+
17+
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
1618
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.0.3")
1719
}

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayLambdaPropagator.java

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
7979
MapGetter.INSTANCE);
8080
}
8181

82+
@Override
83+
public String toString() {
84+
return "AwsXrayLambdaPropagator";
85+
}
86+
8287
private static boolean isEmptyOrNull(@Nullable String value) {
8388
return value == null || value.isEmpty();
8489
}

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
169169
return getContextFromHeader(context, carrier, getter);
170170
}
171171

172+
@Override
173+
public String toString() {
174+
return "AwsXrayPropagator";
175+
}
176+
172177
private static <C> Context getContextFromHeader(
173178
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
174179
String traceHeader = getter.get(carrier, TRACE_HEADER_KEY);

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsConfigurablePropagator.java renamed to aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/internal/AwsConfigurablePropagator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.contrib.awsxray.propagator;
6+
package io.opentelemetry.contrib.awsxray.propagator.internal;
77

88
import io.opentelemetry.context.propagation.TextMapPropagator;
9+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
910
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1011
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;
1112

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.awsxray.propagator.internal;
7+
8+
import io.opentelemetry.context.propagation.TextMapPropagator;
9+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
10+
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
11+
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
12+
13+
public class AwsXrayComponentProvider implements ComponentProvider<TextMapPropagator> {
14+
@Override
15+
public Class<TextMapPropagator> getType() {
16+
return TextMapPropagator.class;
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "xray";
22+
}
23+
24+
@Override
25+
public TextMapPropagator create(StructuredConfigProperties config) {
26+
return AwsXrayPropagator.getInstance();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.awsxray.propagator.internal;
7+
8+
import io.opentelemetry.context.propagation.TextMapPropagator;
9+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
10+
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
11+
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
12+
13+
public class AwsXrayLambdaComponentProvider implements ComponentProvider<TextMapPropagator> {
14+
@Override
15+
public Class<TextMapPropagator> getType() {
16+
return TextMapPropagator.class;
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "xray-lambda";
22+
}
23+
24+
@Override
25+
public TextMapPropagator create(StructuredConfigProperties config) {
26+
return AwsXrayLambdaPropagator.getInstance();
27+
}
28+
}
+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.contrib.awsxray.propagator;
6+
package io.opentelemetry.contrib.awsxray.propagator.internal;
77

88
import io.opentelemetry.context.propagation.TextMapPropagator;
9+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
910
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1011
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;
1112

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
io.opentelemetry.contrib.awsxray.propagator.AwsConfigurablePropagator
1+
io.opentelemetry.contrib.awsxray.propagator.internal.AwsConfigurablePropagator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayComponentProvider
2+
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayLambdaComponentProvider
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.awsxray.propagator.internal;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import io.opentelemetry.context.propagation.TextMapPropagator;
11+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
12+
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
13+
import io.opentelemetry.sdk.OpenTelemetrySdk;
14+
import io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration;
15+
import java.io.ByteArrayInputStream;
16+
import java.nio.charset.StandardCharsets;
17+
import org.junit.jupiter.api.Test;
18+
19+
class AwsComponentProviderTest {
20+
21+
@Test
22+
void endToEnd() {
23+
String yaml = "file_format: 0.1\n" + "propagator:\n" + " composite: [xray, xray-lambda]\n";
24+
25+
OpenTelemetrySdk openTelemetrySdk =
26+
FileConfiguration.parseAndCreate(
27+
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
28+
TextMapPropagator expectedPropagator =
29+
TextMapPropagator.composite(
30+
AwsXrayPropagator.getInstance(), AwsXrayLambdaPropagator.getInstance());
31+
assertThat(openTelemetrySdk.getPropagators().getTextMapPropagator().toString())
32+
.isEqualTo(expectedPropagator.toString());
33+
}
34+
}

0 commit comments

Comments
 (0)