Skip to content

Commit

Permalink
Support parentbased_jaeger_remote sampler. (#5123)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsalvini authored Jan 21, 2023
1 parent 299cfad commit f28e0ad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk-extensions/autoconfigure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ testing {
implementation(project(":exporters:zipkin"))
implementation(project(":sdk:testing"))
implementation(project(":sdk:trace-shaded-deps"))
implementation(project(":sdk-extensions:jaeger-remote-sampler"))
implementation(project(":semconv"))

implementation("com.google.guava:guava")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ static Sampler configureSampler(
config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO);
return Sampler.parentBased(Sampler.traceIdRatioBased(ratio));
}
case "parentbased_jaeger_remote":
Sampler jaegerRemote = spiSamplersManager.getByName("jaeger_remote");
if (jaegerRemote == null) {
throw new ConfigurationException(
"parentbased_jaeger_remote configured but opentelemetry-sdk-extension-jaeger-remote-sampler not on classpath");
}
return Sampler.parentBased(jaegerRemote);
default:
Sampler spiSampler = spiSamplersManager.getByName(sampler);
if (spiSampler == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,14 @@ void configureSampler() {
"catsampler", EMPTY, TracerProviderConfiguration.class.getClassLoader()))
.isInstanceOf(ConfigurationException.class)
.hasMessage("Unrecognized value for otel.traces.sampler: catsampler");
assertThatThrownBy(
() ->
TracerProviderConfiguration.configureSampler(
"parentbased_jaeger_remote",
EMPTY,
TracerProviderConfiguration.class.getClassLoader()))
.isInstanceOf(ConfigurationException.class)
.hasMessage(
"parentbased_jaeger_remote configured but opentelemetry-sdk-extension-jaeger-remote-sampler not on classpath");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import org.junit.jupiter.api.Test;

public class ConfigurableSamplerTest {
public class TracerProviderConfigurationTest {

@Test
void configuration() {
Expand Down Expand Up @@ -58,4 +59,18 @@ void samplerNotFound() {
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining("catSampler");
}

@Test
void configureSampler_JaegerRemoteSampler() {
assertThat(
TracerProviderConfiguration.configureSampler(
"parentbased_jaeger_remote",
DefaultConfigProperties.createForTest(Collections.emptyMap()),
TracerProviderConfigurationTest.class.getClassLoader()))
.satisfies(
sampler -> {
assertThat(sampler.getClass().getSimpleName()).isEqualTo("ParentBasedSampler");
assertThat(sampler).extracting("root").isInstanceOf(JaegerRemoteSampler.class);
});
}
}

0 comments on commit f28e0ad

Please sign in to comment.