use of io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider in project opentelemetry-java by open-telemetry.
the class JaegerRemoteSamplerProviderTest method serviceProvider.
@Test
void serviceProvider() {
ServiceLoader<ConfigurableSamplerProvider> samplerProviders = ServiceLoader.load(ConfigurableSamplerProvider.class);
assertThat(samplerProviders).hasAtLeastOneElementOfType(JaegerRemoteSamplerProvider.class);
assertThat(samplerProviders).singleElement(type(JaegerRemoteSamplerProvider.class)).satisfies(provider -> assertThat(provider.getName()).isEqualTo("jaeger_remote"));
ConfigProperties mockConfig = mock(ConfigProperties.class);
when(mockConfig.getString(JaegerRemoteSamplerProvider.SERVICE_NAME_PROPERTY)).thenReturn("test_service");
HashMap<String, String> samplerArgs = new HashMap<>();
samplerArgs.put("endpoint", "http://localhost:9999");
samplerArgs.put("pollingInterval", "99");
double samplingRate = 0.33;
samplerArgs.put("initialSamplingRate", String.valueOf(samplingRate));
when(mockConfig.getMap(JaegerRemoteSamplerProvider.SAMPLER_ARG_PROPERTY)).thenReturn(samplerArgs);
Sampler sampler = Sampler.parentBased(Sampler.traceIdRatioBased(samplingRate));
assertThat(samplerProviders).singleElement(type(JaegerRemoteSamplerProvider.class)).satisfies(provider -> {
try (JaegerRemoteSampler s = (JaegerRemoteSampler) provider.createSampler(mockConfig)) {
assertThat(s).extracting("sampler", type(Sampler.class)).asString().isEqualTo(sampler.toString());
assertThat(s).extracting("serviceName").isEqualTo("test_service");
assertThat(s).extracting("delegate").extracting("endpoint").isEqualTo("http://localhost:9999/jaeger.api_v2.SamplingManager/GetSamplingStrategy");
}
});
}
use of io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider in project opentelemetry-java by open-telemetry.
the class JaegerRemoteSamplerProviderTest method serviceNameInAttributeProperties.
@Test
void serviceNameInAttributeProperties() {
ConfigProperties mockConfig = mock(ConfigProperties.class);
HashMap<String, String> attributeProperties = new HashMap<>();
attributeProperties.put(JaegerRemoteSamplerProvider.SERVICE_NAME_PROPERTY, "test_service2");
when(mockConfig.getMap(JaegerRemoteSamplerProvider.ATTRIBUTE_PROPERTY)).thenReturn(attributeProperties);
ServiceLoader<ConfigurableSamplerProvider> samplerProviders = ServiceLoader.load(ConfigurableSamplerProvider.class);
assertThat(samplerProviders).singleElement(type(JaegerRemoteSamplerProvider.class)).satisfies(provider -> {
try (JaegerRemoteSampler s = (JaegerRemoteSampler) provider.createSampler(mockConfig)) {
assertThat(s).extracting("serviceName").isEqualTo("test_service2");
}
});
}
Aggregations