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();
}
}
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();
}
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();
}
}
Aggregations