Search in sources :

Example 1 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class AdapterTest method getSpanData.

private static SpanData getSpanData(long startMs, long endMs, SpanKind kind, int totalRecordedEvents, int totalAttributeCount) {
    Attributes attributes = Attributes.of(booleanKey("valueB"), true);
    LinkData link = LinkData.create(createSpanContext(LINK_TRACE_ID, LINK_SPAN_ID), attributes);
    return TestSpanData.builder().setHasEnded(true).setSpanContext(createSpanContext(TRACE_ID, SPAN_ID)).setParentSpanContext(SpanContext.create(TRACE_ID, PARENT_SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())).setName("GET /api/endpoint").setStartEpochNanos(MILLISECONDS.toNanos(startMs)).setEndEpochNanos(MILLISECONDS.toNanos(endMs)).setAttributes(Attributes.of(booleanKey("valueB"), true)).setTotalAttributeCount(totalAttributeCount).setEvents(Collections.singletonList(getTimedEvent())).setTotalRecordedEvents(totalRecordedEvents).setLinks(Collections.singletonList(link)).setTotalRecordedLinks(1).setKind(kind).setResource(Resource.create(Attributes.empty())).setStatus(StatusData.create(StatusCode.OK, "ok!")).build();
}
Also used : LinkData(io.opentelemetry.sdk.trace.data.LinkData) Attributes(io.opentelemetry.api.common.Attributes)

Example 2 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class ResourceConfigurationTest method resource.

@Test
void resource() {
    Attributes attributes = ResourceConfiguration.configureResource(DefaultConfigProperties.get(Collections.emptyMap()), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r).getAttributes();
    assertThat(attributes.get(ResourceAttributes.OS_TYPE)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_VERSION)).isNotNull();
    assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_DESCRIPTION)).isNotNull();
}
Also used : Test(org.junit.jupiter.api.Test) URLClassLoader(java.net.URLClassLoader) OpenTelemetryAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat) URL(java.net.URL) AttributeKey(io.opentelemetry.api.common.AttributeKey) Map(java.util.Map) Attributes(io.opentelemetry.api.common.Attributes) HashMap(java.util.HashMap) Collections(java.util.Collections) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 3 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class ResourceConfigurationTest method emptyClassLoader.

@Test
void emptyClassLoader() {
    Attributes attributes = ResourceConfiguration.configureResource(DefaultConfigProperties.get(Collections.emptyMap()), new URLClassLoader(new URL[0], null), (r, c) -> r).getAttributes();
    assertProcessAttributeIsNull(attributes);
}
Also used : Test(org.junit.jupiter.api.Test) URLClassLoader(java.net.URLClassLoader) OpenTelemetryAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat) URL(java.net.URL) AttributeKey(io.opentelemetry.api.common.AttributeKey) Map(java.util.Map) Attributes(io.opentelemetry.api.common.Attributes) HashMap(java.util.HashMap) Collections(java.util.Collections) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) URLClassLoader(java.net.URLClassLoader) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 4 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class ResourceConfigurationTest method onlySettingEnabledConfiguration.

@Test
void onlySettingEnabledConfiguration() {
    Map<String, String> customConfigs = new HashMap<>(1);
    customConfigs.put("otel.java.enabled.resource.providers", "io.opentelemetry.sdk.autoconfigure.ResourceProviderCustomizer");
    Attributes attributes = ResourceConfiguration.configureResource(DefaultConfigProperties.get(customConfigs), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r).getAttributes();
    assertProcessAttributeIsNull(attributes);
    assertThat(attributes.get(AttributeKey.stringKey("animal"))).isEqualTo("cat");
}
Also used : Test(org.junit.jupiter.api.Test) URLClassLoader(java.net.URLClassLoader) OpenTelemetryAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat) URL(java.net.URL) AttributeKey(io.opentelemetry.api.common.AttributeKey) Map(java.util.Map) Attributes(io.opentelemetry.api.common.Attributes) HashMap(java.util.HashMap) Collections(java.util.Collections) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) HashMap(java.util.HashMap) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 5 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class EcsResourceTest method testContainerIdMissing.

@Test
void testContainerIdMissing() throws UnknownHostException {
    when(mockDockerHelper.getContainerId()).thenReturn("");
    Map<String, String> mockSysEnv = new HashMap<>();
    mockSysEnv.put(ECS_METADATA_KEY_V4, "ecs_metadata_v4_uri");
    Attributes attributes = EcsResource.buildResource(mockSysEnv, mockDockerHelper).getAttributes();
    assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_ecs"), entry(ResourceAttributes.CONTAINER_NAME, InetAddress.getLocalHost().getHostName()));
}
Also used : HashMap(java.util.HashMap) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)175 Test (org.junit.jupiter.api.Test)128 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)45 Resource (io.opentelemetry.sdk.resources.Resource)33 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)27 Context (io.opentelemetry.context.Context)25 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)24 SpanContext (io.opentelemetry.api.trace.SpanContext)22 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)22 SpanData (io.opentelemetry.sdk.trace.data.SpanData)22 HashMap (java.util.HashMap)21 Duration (java.time.Duration)20 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)18 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)18 TestClock (io.opentelemetry.sdk.testing.time.TestClock)18 AttributeKey (io.opentelemetry.api.common.AttributeKey)17 Span (io.opentelemetry.api.trace.Span)17 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)17 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)16 Map (java.util.Map)16