Skip to content
Draft
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 aws-xray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
api("io.opentelemetry:opentelemetry-sdk-trace")

compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-incubator")

implementation("com.squareup.okhttp3:okhttp")
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
Expand All @@ -28,6 +29,7 @@ dependencies {

testImplementation("com.linecorp.armeria:armeria-junit5")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("com.google.guava:guava")
testImplementation("org.slf4j:slf4j-simple")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {

private final Resource resource;
private final Clock clock;
private final String endpoint;
private final Sampler initialSampler;
private final XraySamplerClient client;
private final ScheduledExecutorService executor;
Expand Down Expand Up @@ -81,6 +82,7 @@ public static AwsXrayRemoteSamplerBuilder newBuilder(Resource resource) {
long pollingIntervalNanos) {
this.resource = resource;
this.clock = clock;
this.endpoint = endpoint;
this.initialSampler = initialSampler;
client = new XraySamplerClient(endpoint);
executor =
Expand Down Expand Up @@ -240,4 +242,9 @@ XraySamplerClient getClient() {
Resource getResource() {
return resource;
}

@Override
public String toString() {
return "AwsXrayRemoteSampler{endpoint=" + endpoint + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.internal;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.contrib.awsxray.AwsXrayRemoteSampler;
import io.opentelemetry.contrib.awsxray.AwsXrayRemoteSamplerBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.samplers.Sampler;

/**
* File configuration SPI implementation for {@link AwsXrayRemoteSampler}.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
@SuppressWarnings("rawtypes")
@AutoService(ComponentProvider.class)
public class AwsXrayRemoteSamplerComponentProvider implements ComponentProvider<Sampler> {
@Override
public Class<Sampler> getType() {
return Sampler.class;
}

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

@Override
public Sampler create(DeclarativeConfigProperties config) {
Resource resource = io.opentelemetry.contrib.awsxray.ResourceHolder.getResource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work? The resource in resource holder is set from an AutoConfigurationCustomizerProvider, would that be called for declarative config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not - the test was just not catching it

AwsXrayRemoteSamplerBuilder builder = AwsXrayRemoteSampler.newBuilder(resource);

String endpoint = config.getString("endpoint");
if (endpoint != null) {
builder.setEndpoint(endpoint);
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.internal;

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

import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class AwsXrayRemoteSamplerComponentProviderTest {
@Test
void endToEnd() {
String yaml =
"file_format: 1.0-rc.1\n"
+ "tracer_provider:\n"
+ " sampler:\n"
+ " xray:\n"
+ " endpoint: 'https://example.com'\n";

OpenTelemetrySdk openTelemetrySdk =
DeclarativeConfiguration.parseAndCreate(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));

assertThat(openTelemetrySdk.getSdkTracerProvider().toString())
.contains("AwsXrayRemoteSampler{endpoint=https://example.com}");
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Comparing source compatibility of opentelemetry-aws-xray-1.51.0-SNAPSHOT.jar against opentelemetry-aws-xray-1.50.0.jar
No changes.
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.contrib.awsxray.AwsXrayRemoteSampler (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
Loading