Search in sources :

Example 66 with Attributes

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

the class TemporaryMetricsViewTest method shouldApplyActiveRequestsView.

@Test
void shouldApplyActiveRequestsView() {
    Attributes attributes = Attributes.builder().put(SemanticAttributes.HTTP_METHOD, "GET").put(SemanticAttributes.HTTP_URL, "/high/cardinality/12345").put(SemanticAttributes.NET_PEER_NAME, "somehost").build();
    OpenTelemetryAssertions.assertThat(applyActiveRequestsView(attributes)).containsOnly(attributeEntry("http.method", "GET"));
}
Also used : SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 67 with Attributes

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

the class RpcClientMetricsTest method collectsMetrics.

@Test
void collectsMetrics() {
    InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
    SdkMeterProvider meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).setMinimumCollectionInterval(Duration.ZERO).build();
    RequestListener listener = RpcClientMetrics.get().create(meterProvider.get("test"));
    Attributes requestAttributes = Attributes.builder().put(SemanticAttributes.RPC_SYSTEM, "grpc").put(SemanticAttributes.RPC_SERVICE, "myservice.EchoService").put(SemanticAttributes.RPC_METHOD, "exampleMethod").build();
    Attributes responseAttributes1 = Attributes.builder().put(SemanticAttributes.NET_PEER_NAME, "example.com").put(SemanticAttributes.NET_PEER_IP, "127.0.0.1").put(SemanticAttributes.NET_PEER_PORT, 8080).put(SemanticAttributes.NET_TRANSPORT, "ip_tcp").build();
    Attributes responseAttributes2 = Attributes.builder().put(SemanticAttributes.NET_PEER_IP, "127.0.0.1").put(SemanticAttributes.NET_PEER_PORT, 8080).put(SemanticAttributes.NET_TRANSPORT, "ip_tcp").build();
    Context parent = Context.root().with(Span.wrap(SpanContext.create("ff01020304050600ff0a0b0c0d0e0f00", "090a0b0c0d0e0f00", TraceFlags.getSampled(), TraceState.getDefault())));
    Context context1 = listener.start(parent, requestAttributes, nanos(100));
    assertThat(metricReader.collectAllMetrics()).isEmpty();
    Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
    assertThat(metricReader.collectAllMetrics()).isEmpty();
    listener.end(context1, responseAttributes1, nanos(250));
    assertThat(metricReader.collectAllMetrics()).hasSize(1).anySatisfy(metric -> assertThat(metric).hasName("rpc.client.duration").hasUnit("ms").hasDoubleHistogram().points().satisfiesExactly(point -> {
        assertThat(point).hasSum(150).attributes().containsOnly(attributeEntry("rpc.system", "grpc"), attributeEntry("rpc.service", "myservice.EchoService"), attributeEntry("rpc.method", "exampleMethod"), attributeEntry("net.peer.name", "example.com"), attributeEntry("net.peer.port", 8080), attributeEntry("net.transport", "ip_tcp"));
        assertThat(point).exemplars().hasSize(1);
        assertThat(point.getExemplars().get(0)).hasTraceId("ff01020304050600ff0a0b0c0d0e0f00").hasSpanId("090a0b0c0d0e0f00");
    }));
    listener.end(context2, responseAttributes2, nanos(300));
    assertThat(metricReader.collectAllMetrics()).hasSize(1).anySatisfy(metric -> assertThat(metric).hasName("rpc.client.duration").hasUnit("ms").hasDoubleHistogram().points().satisfiesExactly(point -> {
        assertThat(point).hasSum(150).attributes().containsOnly(attributeEntry("rpc.system", "grpc"), attributeEntry("rpc.service", "myservice.EchoService"), attributeEntry("rpc.method", "exampleMethod"), attributeEntry("net.peer.ip", "127.0.0.1"), attributeEntry("net.peer.port", 8080), attributeEntry("net.transport", "ip_tcp"));
    }));
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) OpenTelemetryAssertions.attributeEntry(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry) TraceFlags(io.opentelemetry.api.trace.TraceFlags) Context(io.opentelemetry.context.Context) Span(io.opentelemetry.api.trace.Span) SpanContext(io.opentelemetry.api.trace.SpanContext) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) RequestListener(io.opentelemetry.instrumentation.api.instrumenter.RequestListener) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) TraceState(io.opentelemetry.api.trace.TraceState) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Duration(java.time.Duration) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) RequestListener(io.opentelemetry.instrumentation.api.instrumenter.RequestListener) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 68 with Attributes

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

the class RpcServerMetricsTest method collectsMetrics.

@Test
void collectsMetrics() {
    InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
    SdkMeterProvider meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).setMinimumCollectionInterval(Duration.ZERO).build();
    RequestListener listener = RpcServerMetrics.get().create(meterProvider.get("test"));
    Attributes requestAttributes = Attributes.builder().put(SemanticAttributes.RPC_SYSTEM, "grpc").put(SemanticAttributes.RPC_SERVICE, "myservice.EchoService").put(SemanticAttributes.RPC_METHOD, "exampleMethod").build();
    Attributes responseAttributes1 = Attributes.builder().put(SemanticAttributes.NET_HOST_NAME, "example.com").put(SemanticAttributes.NET_HOST_IP, "127.0.0.1").put(SemanticAttributes.NET_HOST_PORT, 8080).put(SemanticAttributes.NET_TRANSPORT, "ip_tcp").build();
    Attributes responseAttributes2 = Attributes.builder().put(SemanticAttributes.NET_HOST_IP, "127.0.0.1").put(SemanticAttributes.NET_HOST_PORT, 8080).put(SemanticAttributes.NET_TRANSPORT, "ip_tcp").build();
    Context parent = Context.root().with(Span.wrap(SpanContext.create("ff01020304050600ff0a0b0c0d0e0f00", "090a0b0c0d0e0f00", TraceFlags.getSampled(), TraceState.getDefault())));
    Context context1 = listener.start(parent, requestAttributes, nanos(100));
    assertThat(metricReader.collectAllMetrics()).isEmpty();
    Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
    assertThat(metricReader.collectAllMetrics()).isEmpty();
    listener.end(context1, responseAttributes1, nanos(250));
    assertThat(metricReader.collectAllMetrics()).hasSize(1).anySatisfy(metric -> assertThat(metric).hasName("rpc.server.duration").hasUnit("ms").hasDoubleHistogram().points().satisfiesExactly(point -> {
        assertThat(point).hasSum(150).attributes().containsOnly(attributeEntry("rpc.system", "grpc"), attributeEntry("rpc.service", "myservice.EchoService"), attributeEntry("rpc.method", "exampleMethod"), attributeEntry("net.host.name", "example.com"), attributeEntry("net.transport", "ip_tcp"));
        assertThat(point).exemplars().hasSize(1);
        assertThat(point.getExemplars().get(0)).hasTraceId("ff01020304050600ff0a0b0c0d0e0f00").hasSpanId("090a0b0c0d0e0f00");
    }));
    listener.end(context2, responseAttributes2, nanos(300));
    assertThat(metricReader.collectAllMetrics()).hasSize(1).anySatisfy(metric -> assertThat(metric).hasName("rpc.server.duration").hasUnit("ms").hasDoubleHistogram().points().satisfiesExactly(point -> {
        assertThat(point).hasSum(150).attributes().containsOnly(attributeEntry("rpc.system", "grpc"), attributeEntry("rpc.service", "myservice.EchoService"), attributeEntry("rpc.method", "exampleMethod"), attributeEntry("net.host.ip", "127.0.0.1"), attributeEntry("net.transport", "ip_tcp"));
    }));
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) OpenTelemetryAssertions.attributeEntry(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry) TraceFlags(io.opentelemetry.api.trace.TraceFlags) Context(io.opentelemetry.context.Context) Span(io.opentelemetry.api.trace.Span) SpanContext(io.opentelemetry.api.trace.SpanContext) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) RequestListener(io.opentelemetry.instrumentation.api.instrumenter.RequestListener) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) TraceState(io.opentelemetry.api.trace.TraceState) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Duration(java.time.Duration) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) RequestListener(io.opentelemetry.instrumentation.api.instrumenter.RequestListener) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 69 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.

the class BaseIntegrationTest method assertNodeMetadata.

protected void assertNodeMetadata(Tree<SpanDataWrapper> spans, String jobName, boolean withNode) throws Exception {
    Optional<Tree.Node<SpanDataWrapper>> shell = spans.breadthFirstSearchNodes(node -> jobName.equals(node.getData().spanData.getName()));
    MatcherAssert.assertThat(shell, CoreMatchers.is(CoreMatchers.notNullValue()));
    Attributes attributes = shell.get().getData().spanData.getAttributes();
    if (withNode) {
        MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_AGENT_LABEL), CoreMatchers.is(CoreMatchers.notNullValue()));
    } else {
        MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_AGENT_LABEL), CoreMatchers.is(CoreMatchers.nullValue()));
    }
    MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.CI_PIPELINE_AGENT_NAME), CoreMatchers.is(CoreMatchers.notNullValue()));
    MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.CI_PIPELINE_AGENT_ID), CoreMatchers.is(CoreMatchers.notNullValue()));
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes)

Example 70 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.

the class BaseIntegrationTest method assertBuildStepMetadata.

protected void assertBuildStepMetadata(Tree<SpanDataWrapper> spans, String stepName, String pluginName) throws Exception {
    Optional<Tree.Node<SpanDataWrapper>> step = spans.breadthFirstSearchNodes(node -> stepName.equals(node.getData().spanData.getName()));
    MatcherAssert.assertThat(step, CoreMatchers.is(CoreMatchers.notNullValue()));
    Attributes attributes = step.get().getData().spanData.getAttributes();
    MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_NAME), CoreMatchers.is(pluginName));
    MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_VERSION), CoreMatchers.is(CoreMatchers.notNullValue()));
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes)

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