diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiConfigCustomizer.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiConfigCustomizer.java index fe862e8ac3d..01781e8ce21 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiConfigCustomizer.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiConfigCustomizer.java @@ -36,7 +36,9 @@ public Map apply(ConfigProperties otelConfig) { // enables all resource provider by default properties.put( "otel.java.enabled.resource.providers", - "io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider"); + "io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider," + + "io.opentelemetry.instrumentation.resources.ManifestResourceProvider," + + "io.opentelemetry.instrumentation.spring.resources.SpringBootServiceVersionDetector"); if (configuration.preview.captureControllerSpans) { properties.put( diff --git a/settings.gradle.kts b/settings.gradle.kts index 696a3802a50..b99dcf59e68 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -121,6 +121,8 @@ hideFromDependabot(":smoke-tests:apps:RuntimeAttachWithDelayedConnectionString") hideFromDependabot(":smoke-tests:apps:Sampling") hideFromDependabot(":smoke-tests:apps:SamplingOverrides") hideFromDependabot(":smoke-tests:apps:SamplingOverridesBackCompat") +hideFromDependabot(":smoke-tests:apps:ServiceVersionFromManifest") +hideFromDependabot(":smoke-tests:apps:ServiceVersionFromSpring") hideFromDependabot(":smoke-tests:apps:SpringBoot") hideFromDependabot(":smoke-tests:apps:SpringBootAuto") hideFromDependabot(":smoke-tests:apps:SpringBootAuto1_3") diff --git a/smoke-tests/apps/ServiceVersionFromManifest/build.gradle.kts b/smoke-tests/apps/ServiceVersionFromManifest/build.gradle.kts new file mode 100644 index 00000000000..36df84fe844 --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromManifest/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("ai.smoke-test-jar") +} + +dependencies { + implementation("org.springframework.boot:spring-boot-starter-web:2.5.12") +} + +tasks.withType { + manifest { + attributes( + "Implementation-Version" to "1.2.3" + ) + } +} diff --git a/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java b/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java new file mode 100644 index 00000000000..cee97c97990 --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketestapp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootApp { + + public static void main(String[] args) { + + SpringApplication.run(SpringBootApp.class, args); + } +} diff --git a/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java b/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java new file mode 100644 index 00000000000..a31b2d9d31c --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromManifest/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketestapp; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @GetMapping("/") + public String root() { + return "OK"; + } + + @GetMapping("/test") + public String test() { + return "hello"; + } +} diff --git a/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java b/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java new file mode 100644 index 00000000000..645456e34ee --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketest; + +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8_OPENJ9; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +@UseAgent +abstract class ApplicationVerTest { + + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); + + @Test + @TargetUri("/test") + void test() throws Exception { + Telemetry telemetry = testing.getTelemetry(0); + + assertThat(telemetry.rd.getName()).isEqualTo("GET /test"); + assertThat(telemetry.rd.getUrl()).matches("http://localhost:[0-9]+/test"); + assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); + assertThat(telemetry.rd.getSuccess()).isTrue(); + assertThat(telemetry.rd.getSource()).isNull(); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + assertThat(telemetry.rd.getMeasurements()).isEmpty(); + + assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.application.ver", "1.2.3"); + } + + @Environment(JAVA_8) + static class Java8Test extends ApplicationVerTest {} + + @Environment(JAVA_8_OPENJ9) + static class Java8OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_11) + static class Java11Test extends ApplicationVerTest {} + + @Environment(JAVA_11_OPENJ9) + static class Java11OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_17) + static class Java17Test extends ApplicationVerTest {} + + @Environment(JAVA_17_OPENJ9) + static class Java17OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_21) + static class Java21Test extends ApplicationVerTest {} + + @Environment(JAVA_21_OPENJ9) + static class Java21OpenJ9Test extends ApplicationVerTest {} +} diff --git a/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/resources/logback-test.xml b/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/resources/logback-test.xml new file mode 100644 index 00000000000..0cbbecd57ce --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromManifest/src/smokeTest/resources/logback-test.xml @@ -0,0 +1,11 @@ + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + + + + + + diff --git a/smoke-tests/apps/ServiceVersionFromSpring/build.gradle.kts b/smoke-tests/apps/ServiceVersionFromSpring/build.gradle.kts new file mode 100644 index 00000000000..e696b4e09e0 --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("ai.smoke-test-jar") +} + +dependencies { + implementation("org.springframework.boot:spring-boot-starter-web:2.5.12") +} diff --git a/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java b/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java new file mode 100644 index 00000000000..cee97c97990 --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketestapp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootApp { + + public static void main(String[] args) { + + SpringApplication.run(SpringBootApp.class, args); + } +} diff --git a/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java b/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java new file mode 100644 index 00000000000..a31b2d9d31c --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketestapp; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @GetMapping("/") + public String root() { + return "OK"; + } + + @GetMapping("/test") + public String test() { + return "hello"; + } +} diff --git a/smoke-tests/apps/ServiceVersionFromSpring/src/main/resources/META-INF/build-info.properties b/smoke-tests/apps/ServiceVersionFromSpring/src/main/resources/META-INF/build-info.properties new file mode 100644 index 00000000000..6bf0914e84a --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/src/main/resources/META-INF/build-info.properties @@ -0,0 +1,3 @@ +build.artifact=something +build.name=some-name +build.version=2.3.4 diff --git a/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java b/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java new file mode 100644 index 00000000000..15989188136 --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ApplicationVerTest.java @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.applicationinsights.smoketest; + +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8; +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8_OPENJ9; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +@UseAgent +abstract class ApplicationVerTest { + + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); + + @Test + @TargetUri("/test") + void test() throws Exception { + Telemetry telemetry = testing.getTelemetry(0); + + assertThat(telemetry.rd.getName()).isEqualTo("GET /test"); + assertThat(telemetry.rd.getUrl()).matches("http://localhost:[0-9]+/test"); + assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); + assertThat(telemetry.rd.getSuccess()).isTrue(); + assertThat(telemetry.rd.getSource()).isNull(); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + assertThat(telemetry.rd.getMeasurements()).isEmpty(); + + assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.application.ver", "2.3.4"); + } + + @Environment(JAVA_8) + static class Java8Test extends ApplicationVerTest {} + + @Environment(JAVA_8_OPENJ9) + static class Java8OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_11) + static class Java11Test extends ApplicationVerTest {} + + @Environment(JAVA_11_OPENJ9) + static class Java11OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_17) + static class Java17Test extends ApplicationVerTest {} + + @Environment(JAVA_17_OPENJ9) + static class Java17OpenJ9Test extends ApplicationVerTest {} + + @Environment(JAVA_21) + static class Java21Test extends ApplicationVerTest {} + + @Environment(JAVA_21_OPENJ9) + static class Java21OpenJ9Test extends ApplicationVerTest {} +} diff --git a/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/resources/logback-test.xml b/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/resources/logback-test.xml new file mode 100644 index 00000000000..0cbbecd57ce --- /dev/null +++ b/smoke-tests/apps/ServiceVersionFromSpring/src/smokeTest/resources/logback-test.xml @@ -0,0 +1,11 @@ + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + + + + + +