Search in sources :

Example 1 with ResourceAttributes

use of io.opentelemetry.semconv.resource.attributes.ResourceAttributes in project opentelemetry-plugin by jenkinsci.

the class GlobalOpenTelemetrySdkTest method testSdkSetConfiguration_twice_with_same_configProperties_and_resourceAttributes.

@Test
public void testSdkSetConfiguration_twice_with_same_configProperties_and_resourceAttributes() {
    try {
        Map<String, String> config = new HashMap<>();
        config.put("otel.traces.exporter", "none");
        config.put("otel.metrics.exporter", "none");
        config.put("otel.logs.exporter", "none");
        Resource resource = Resource.builder().put(ResourceAttributes.SERVICE_NAME, "jenkins").put(ResourceAttributes.SERVICE_VERSION, "1.2.3").put(ResourceAttributes.SERVICE_NAME.getKey(), "cicd").build();
        Map<String, String> resourceAttributes = new HashMap<>();
        resource.getAttributes().forEach((k, v) -> resourceAttributes.put(k.getKey(), v.toString()));
        int configurationCountBefore = GlobalOpenTelemetrySdk.configurationCounter.get();
        // CONFIGURE ONCE
        {
            GlobalOpenTelemetrySdk.configure(config, resourceAttributes, false);
            ConfigProperties actualConfigProperties = GlobalOpenTelemetrySdk.getConfigProperties();
            config.forEach((k, v) -> assertEquals("Config[" + k + "]", v, actualConfigProperties.getString(k)));
            GlobalOpenTelemetrySdk.getLogEmitter();
            GlobalOpenTelemetrySdk.getMeter();
            GlobalOpenTelemetrySdk.getTracer();
            Resource actualResource = GlobalOpenTelemetrySdk.getResource();
            resource.getAttributes().forEach((k, v) -> assertEquals("Resource[" + k + "]", v, actualResource.getAttribute(k)));
            assertEquals("Configuration counter", configurationCountBefore + 1, GlobalOpenTelemetrySdk.configurationCounter.get());
        }
        // CONFIGURE A SECOND TIME WITH SAME CONFIGURATION
        {
            GlobalOpenTelemetrySdk.configure(config, resourceAttributes, false);
            ConfigProperties actualConfigProperties = GlobalOpenTelemetrySdk.getConfigProperties();
            config.forEach((k, v) -> assertEquals("Config[" + k + "]", v, actualConfigProperties.getString(k)));
            GlobalOpenTelemetrySdk.getLogEmitter();
            GlobalOpenTelemetrySdk.getMeter();
            GlobalOpenTelemetrySdk.getTracer();
            Resource actualResource = GlobalOpenTelemetrySdk.getResource();
            resource.getAttributes().forEach((k, v) -> assertEquals("Resource[" + k + "]", v, actualResource.getAttribute(k)));
            // verify has been configured just once
            assertEquals("Configuration counter", configurationCountBefore + 1, GlobalOpenTelemetrySdk.configurationCounter.get());
        }
    } finally {
        GlobalOpenTelemetrySdk.shutdown();
    }
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) Resource(io.opentelemetry.sdk.resources.Resource) Map(java.util.Map) Test(org.junit.Test) HashMap(java.util.HashMap) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) HashMap(java.util.HashMap) Resource(io.opentelemetry.sdk.resources.Resource) Test(org.junit.Test)

Example 2 with ResourceAttributes

use of io.opentelemetry.semconv.resource.attributes.ResourceAttributes in project opentelemetry-java by open-telemetry.

the class ZipkinSpanExporter method getEndpoint.

private Endpoint getEndpoint(SpanData spanData) {
    Attributes resourceAttributes = spanData.getResource().getAttributes();
    Endpoint.Builder endpoint = Endpoint.newBuilder().ip(localAddress);
    // use the service.name from the Resource, if it's been set.
    String serviceNameValue = resourceAttributes.get(ResourceAttributes.SERVICE_NAME);
    if (serviceNameValue == null) {
        serviceNameValue = Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME);
    }
    // In practice should never be null unless the default Resource spec is changed.
    if (serviceNameValue != null) {
        endpoint.serviceName(serviceNameValue);
    }
    return endpoint.build();
}
Also used : Endpoint(zipkin2.Endpoint) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes)

Example 3 with ResourceAttributes

use of io.opentelemetry.semconv.resource.attributes.ResourceAttributes in project opentelemetry-plugin by jenkinsci.

the class GlobalOpenTelemetrySdkTest method testSdkSetConfiguration_twice_with_different_configProperties_and_same_resourceAttributes.

@Test
public void testSdkSetConfiguration_twice_with_different_configProperties_and_same_resourceAttributes() {
    try {
        final Resource resource = Resource.builder().put(ResourceAttributes.SERVICE_NAME, "jenkins").put(ResourceAttributes.SERVICE_VERSION, "1.2.3").put(ResourceAttributes.SERVICE_NAME.getKey(), "cicd").build();
        final Map<String, String> resourceAttributes = new HashMap<>();
        resource.getAttributes().forEach((k, v) -> resourceAttributes.put(k.getKey(), v.toString()));
        int configurationCountBefore = GlobalOpenTelemetrySdk.configurationCounter.get();
        // CONFIGURE ONCE
        {
            Map<String, String> config = new HashMap<>();
            config.put("otel.traces.exporter", "none");
            config.put("otel.metrics.exporter", "none");
            config.put("otel.logs.exporter", "none");
            GlobalOpenTelemetrySdk.configure(config, resourceAttributes, false);
            ConfigProperties actualConfigProperties = GlobalOpenTelemetrySdk.getConfigProperties();
            config.forEach((k, v) -> assertEquals("Config[" + k + "]", v, actualConfigProperties.getString(k)));
            GlobalOpenTelemetrySdk.getLogEmitter();
            GlobalOpenTelemetrySdk.getMeter();
            GlobalOpenTelemetrySdk.getTracer();
            Resource actualResource = GlobalOpenTelemetrySdk.getResource();
            resource.getAttributes().forEach((k, v) -> assertEquals("Resource[" + k + "]", v, actualResource.getAttribute(k)));
            assertEquals("Configuration counter", configurationCountBefore + 1, GlobalOpenTelemetrySdk.configurationCounter.get());
        }
        // CONFIGURE A SECOND TIME WITH DIFFERENT CONFIG PROPERTIES AND SAME RESOURCE ATTRIBUTES
        {
            Map<String, String> differentConfig = new HashMap<>();
            differentConfig.put("otel.traces.exporter", "none");
            differentConfig.put("otel.metrics.exporter", "none");
            differentConfig.put("otel.logs.exporter", "none");
            differentConfig.put("a", "b");
            GlobalOpenTelemetrySdk.configure(differentConfig, resourceAttributes, false);
            ConfigProperties actualConfigProperties = GlobalOpenTelemetrySdk.getConfigProperties();
            differentConfig.forEach((k, v) -> assertEquals("Config[" + k + "]", v, actualConfigProperties.getString(k)));
            GlobalOpenTelemetrySdk.getLogEmitter();
            GlobalOpenTelemetrySdk.getMeter();
            GlobalOpenTelemetrySdk.getTracer();
            Resource actualResource = GlobalOpenTelemetrySdk.getResource();
            resource.getAttributes().forEach((k, v) -> assertEquals("Resource[" + k + "]", v, actualResource.getAttribute(k)));
            // verify has been configured twice
            assertEquals("Configuration counter", configurationCountBefore + 2, GlobalOpenTelemetrySdk.configurationCounter.get());
        }
    } finally {
        GlobalOpenTelemetrySdk.shutdown();
    }
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) Resource(io.opentelemetry.sdk.resources.Resource) Map(java.util.Map) Test(org.junit.Test) HashMap(java.util.HashMap) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) HashMap(java.util.HashMap) Resource(io.opentelemetry.sdk.resources.Resource) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)3 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)2 Resource (io.opentelemetry.sdk.resources.Resource)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Test (org.junit.Test)2 Attributes (io.opentelemetry.api.common.Attributes)1 Endpoint (zipkin2.Endpoint)1