Skip to content

Commit

Permalink
Add declarative config support for aws xray propagators (open-telemet…
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored and robsunday committed Sep 17, 2024
1 parent 151b744 commit 5ffa348
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 3 deletions.
2 changes: 2 additions & 0 deletions aws-xray-propagator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ dependencies {
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation("io.opentelemetry:opentelemetry-sdk-trace")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")

testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.0.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
MapGetter.INSTANCE);
}

@Override
public String toString() {
return "AwsXrayLambdaPropagator";
}

private static boolean isEmptyOrNull(@Nullable String value) {
return value == null || value.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
return getContextFromHeader(context, carrier, getter);
}

@Override
public String toString() {
return "AwsXrayPropagator";
}

private static <C> Context getContextFromHeader(
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
String traceHeader = getter.get(carrier, TRACE_HEADER_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator;
package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;

public class AwsXrayComponentProvider implements ComponentProvider<TextMapPropagator> {
@Override
public Class<TextMapPropagator> getType() {
return TextMapPropagator.class;
}

@Override
public String getName() {
return "xray";
}

@Override
public TextMapPropagator create(StructuredConfigProperties config) {
return AwsXrayPropagator.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;

public class AwsXrayLambdaComponentProvider implements ComponentProvider<TextMapPropagator> {
@Override
public Class<TextMapPropagator> getType() {
return TextMapPropagator.class;
}

@Override
public String getName() {
return "xray-lambda";
}

@Override
public TextMapPropagator create(StructuredConfigProperties config) {
return AwsXrayLambdaPropagator.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator;
package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.opentelemetry.contrib.awsxray.propagator.AwsConfigurablePropagator
io.opentelemetry.contrib.awsxray.propagator.internal.AwsConfigurablePropagator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayComponentProvider
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayLambdaComponentProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class AwsComponentProviderTest {

@Test
void endToEnd() {
String yaml = "file_format: 0.1\n" + "propagator:\n" + " composite: [xray, xray-lambda]\n";

OpenTelemetrySdk openTelemetrySdk =
FileConfiguration.parseAndCreate(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
TextMapPropagator expectedPropagator =
TextMapPropagator.composite(
AwsXrayPropagator.getInstance(), AwsXrayLambdaPropagator.getInstance());
assertThat(openTelemetrySdk.getPropagators().getTextMapPropagator().toString())
.isEqualTo(expectedPropagator.toString());
}
}

0 comments on commit 5ffa348

Please sign in to comment.