|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.javaagent.instrumentation.opentelemetryapi; |
| 7 | + |
| 8 | +import static io.opentelemetry.api.trace.SpanKind.PRODUCER; |
| 9 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
| 10 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
| 11 | +import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME; |
| 12 | +import static io.opentelemetry.semconv.TelemetryAttributes.TELEMETRY_SDK_LANGUAGE; |
| 13 | +import static io.opentelemetry.semconv.TelemetryAttributes.TELEMETRY_SDK_NAME; |
| 14 | +import static io.opentelemetry.semconv.TelemetryAttributes.TELEMETRY_SDK_VERSION; |
| 15 | +import static io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes.SERVICE_INSTANCE_ID; |
| 16 | +import static io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes.TELEMETRY_DISTRO_NAME; |
| 17 | +import static io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes.TELEMETRY_DISTRO_VERSION; |
| 18 | + |
| 19 | +import io.opentelemetry.api.GlobalOpenTelemetry; |
| 20 | +import io.opentelemetry.api.trace.Span; |
| 21 | +import io.opentelemetry.api.trace.Tracer; |
| 22 | +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
| 23 | +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests the resource providers in javaagent-tooling: DistroComponentProvider |
| 29 | + * andResourceCustomizerProvider |
| 30 | + */ |
| 31 | +class ResourceTest { |
| 32 | + |
| 33 | + @RegisterExtension |
| 34 | + private static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); |
| 35 | + |
| 36 | + @Test |
| 37 | + void distroAndServiceResourceAttributes() { |
| 38 | + // When |
| 39 | + Tracer tracer = GlobalOpenTelemetry.getTracer("test"); |
| 40 | + Span testSpan = tracer.spanBuilder("test").setSpanKind(PRODUCER).startSpan(); |
| 41 | + testSpan.end(); |
| 42 | + |
| 43 | + // Then |
| 44 | + testing.waitAndAssertTraces( |
| 45 | + trace -> |
| 46 | + trace.hasSpansSatisfyingExactly( |
| 47 | + span -> |
| 48 | + span.hasName("test") |
| 49 | + .hasKind(PRODUCER) |
| 50 | + .hasNoParent() |
| 51 | + .hasResourceSatisfying( |
| 52 | + r -> |
| 53 | + r.hasAttributesSatisfyingExactly( |
| 54 | + equalTo(TELEMETRY_SDK_LANGUAGE, "java"), |
| 55 | + equalTo(TELEMETRY_SDK_NAME, "opentelemetry"), |
| 56 | + satisfies(TELEMETRY_SDK_VERSION, v -> v.isNotBlank()), |
| 57 | + equalTo(SERVICE_NAME, "unknown_service:java"), |
| 58 | + satisfies(SERVICE_INSTANCE_ID, v -> v.isNotBlank()), |
| 59 | + equalTo( |
| 60 | + TELEMETRY_DISTRO_NAME, |
| 61 | + "opentelemetry-java-instrumentation"), |
| 62 | + satisfies(TELEMETRY_DISTRO_VERSION, v -> v.isNotBlank()))))); |
| 63 | + } |
| 64 | +} |
0 commit comments