Search in sources :

Example 56 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_empty.

@Test
void resourceFromConfig_empty() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(emptyMap()));
    assertThat(attributes).isEmpty();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 57 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_overrideServiceName.

@Test
void resourceFromConfig_overrideServiceName() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(ImmutableMap.of(ResourceConfiguration.ATTRIBUTE_PROPERTY, "service.name=myService,appName=MyApp", ResourceConfiguration.SERVICE_NAME_PROPERTY, "ReallyMyService")));
    assertThat(attributes).hasSize(2).containsEntry(ResourceAttributes.SERVICE_NAME, "ReallyMyService").containsEntry("appName", "MyApp");
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 58 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_emptyEnvVar.

@Test
void resourceFromConfig_emptyEnvVar() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(singletonMap(ResourceConfiguration.ATTRIBUTE_PROPERTY, "")));
    assertThat(attributes).isEmpty();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 59 with Attributes

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

the class NestedCallbacksTest method test.

@Test
void test() {
    Span span = tracer.spanBuilder("one").startSpan();
    submitCallbacks(span);
    await().atMost(Duration.ofSeconds(15)).until(TestUtils.finishedSpansSize(otelTesting), equalTo(1));
    List<SpanData> spans = otelTesting.getSpans();
    assertThat(spans).hasSize(1);
    assertThat(spans.get(0).getName()).isEqualTo("one");
    Attributes attrs = spans.get(0).getAttributes();
    assertThat(attrs.size()).isEqualTo(3);
    for (int i = 1; i <= 3; i++) {
        assertThat(attrs.get(stringKey("key" + i))).isEqualTo(Integer.toString(i));
    }
    assertThat(Span.current()).isSameAs(Span.getInvalid());
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) Attributes(io.opentelemetry.api.common.Attributes) Span(io.opentelemetry.api.trace.Span) Test(org.junit.jupiter.api.Test)

Example 60 with Attributes

use of io.opentelemetry.api.common.Attributes in project otel-mule4-observability-agent by rickbansal-mulesoft.

the class LoggerParser method addLoggerEventsToSpan.

// --------------------------------------------------------------------------------------------
// Annotate the span with Logger event
// --------------------------------------------------------------------------------------------
private void addLoggerEventsToSpan(EnrichedServerNotification notification, MuleSoftTraceStore traceStore) {
    String loggerOutput = NotificationParserUtils.getMessage(notification);
    Span span = traceStore.getMessageProcessorSpan(NotificationParserUtils.getMuleSoftTraceId(notification), NotificationParserUtils.getFlowId(notification), NotificationParserUtils.getSpanId(notification));
    // ----------------------------------------------------------------------------------------
    if (loggerOutput != null && notification.getException() == null) {
        Attributes eventAttributes = Attributes.of(AttributeKey.stringKey("logger.output"), loggerOutput);
        span.addEvent("logger.output.event", eventAttributes);
    }
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) Span(io.opentelemetry.api.trace.Span)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)232 Test (org.junit.jupiter.api.Test)154 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)50 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)43 Resource (io.opentelemetry.sdk.resources.Resource)33 SpanData (io.opentelemetry.sdk.trace.data.SpanData)31 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)28 Test (org.junit.Test)28 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)27 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)25 Context (io.opentelemetry.context.Context)25 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)24 SpanContext (io.opentelemetry.api.trace.SpanContext)22 Duration (java.time.Duration)21 HashMap (java.util.HashMap)21 OpenTelemetryAssertions.attributeEntry (io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry)20 SamplingOverride (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride)18 AttributeKey (io.opentelemetry.api.common.AttributeKey)18 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)18 TestClock (io.opentelemetry.sdk.testing.time.TestClock)18