Search in sources :

Example 1 with ConfigurableSamplerProvider

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");
        }
    });
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) HashMap(java.util.HashMap) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) ConfigurableSamplerProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigurableSamplerProvider

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");
        }
    });
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) HashMap(java.util.HashMap) ConfigurableSamplerProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)2 ConfigurableSamplerProvider (io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 Sampler (io.opentelemetry.sdk.trace.samplers.Sampler)1