|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.smoketest; |
| 7 | + |
| 8 | +import io.opentelemetry.sdk.testing.assertj.TracesAssert; |
| 9 | +import io.opentelemetry.sdk.trace.data.SpanData; |
| 10 | +import io.opentelemetry.semconv.ServiceAttributes; |
| 11 | +import io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes; |
| 12 | +import io.opentelemetry.semconv.incubating.HostIncubatingAttributes; |
| 13 | +import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes; |
| 14 | +import io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes; |
| 15 | +import org.junit.jupiter.api.condition.DisabledIf; |
| 16 | +import org.junit.jupiter.params.ParameterizedTest; |
| 17 | +import org.junit.jupiter.params.provider.ValueSource; |
| 18 | + |
| 19 | +import java.time.Duration; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
| 24 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
| 25 | + |
| 26 | +@DisabledIf("io.opentelemetry.smoketest.TestContainerManager#useWindowsContainers") |
| 27 | +class DeclarativeConfigurationSmokeTest extends JavaSmokeTest { |
| 28 | + @Override |
| 29 | + protected String getTargetImage(String jdk) { |
| 30 | + return "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk" |
| 31 | + + jdk |
| 32 | + + "-20241021.11448062567"; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + protected List<ResourceMapping> getExtraResources() { |
| 37 | + return List.of(ResourceMapping.of("declarative-config.yaml", "/declarative-config.yaml")); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected Map<String, String> getExtraEnv() { |
| 42 | + return Map.of("OTEL_EXPERIMENTAL_CONFIG_FILE", "declarative-config.yaml"); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + protected TargetWaitStrategy getWaitStrategy() { |
| 47 | + return new TargetWaitStrategy.Log( |
| 48 | + Duration.ofMinutes(1), ".*Started SpringbootApplication in.*"); |
| 49 | + } |
| 50 | + |
| 51 | + @ParameterizedTest |
| 52 | + @ValueSource(ints = {8, 11, 17}) |
| 53 | + void springBootSmokeTest(int jdk) throws Exception { |
| 54 | + runTarget( |
| 55 | + jdk, |
| 56 | + output -> { |
| 57 | + client().get("/greeting").aggregate().join(); |
| 58 | + List<SpanData> traces = waitForTraces(); |
| 59 | + assertThat(traces).hasSize(1); |
| 60 | + |
| 61 | + // There is one span (io.opentelemetry.opentelemetry-instrumentation-annotations-1.16 is |
| 62 | + // not used, |
| 63 | + // because instrumentation_mode=none) |
| 64 | + TracesAssert.assertThat(traces) |
| 65 | + .hasTracesSatisfyingExactly( |
| 66 | + trace -> |
| 67 | + trace.hasSpansSatisfyingExactly( |
| 68 | + span -> |
| 69 | + span.hasResourceSatisfying( |
| 70 | + resource -> |
| 71 | + resource |
| 72 | + .hasAttribute( |
| 73 | + ServiceAttributes.SERVICE_NAME, |
| 74 | + "declarative-config-smoke-test") |
| 75 | + .hasAttribute( |
| 76 | + satisfies( |
| 77 | + ContainerIncubatingAttributes.CONTAINER_ID, |
| 78 | + v -> v.isNotBlank())) |
| 79 | + .hasAttribute( |
| 80 | + satisfies( |
| 81 | + ProcessIncubatingAttributes |
| 82 | + .PROCESS_EXECUTABLE_PATH, |
| 83 | + v -> v.isNotBlank())) |
| 84 | + .hasAttribute( |
| 85 | + satisfies( |
| 86 | + HostIncubatingAttributes.HOST_NAME, |
| 87 | + v -> v.isNotBlank())) |
| 88 | + .hasAttribute( |
| 89 | + TelemetryIncubatingAttributes.TELEMETRY_DISTRO_NAME, |
| 90 | + "opentelemetry-javaagent")))); |
| 91 | + }); |
| 92 | + } |
| 93 | +} |
0 commit comments