Skip to content

Commit 59ce8bd

Browse files
committed
Use upstream detectors
1 parent 55131a4 commit 59ce8bd

File tree

13 files changed

+256
-1
lines changed

13 files changed

+256
-1
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiConfigCustomizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public Map<String, String> apply(ConfigProperties otelConfig) {
3636
// enables all resource provider by default
3737
properties.put(
3838
"otel.java.enabled.resource.providers",
39-
"io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider");
39+
"io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider,"
40+
+ "io.opentelemetry.instrumentation.resources.ManifestResourceProvider,"
41+
+ "io.opentelemetry.instrumentation.spring.resources.SpringBootServiceVersionDetector");
4042

4143
if (configuration.preview.captureControllerSpans) {
4244
properties.put(

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ hideFromDependabot(":smoke-tests:apps:RuntimeAttachWithDelayedConnectionString")
121121
hideFromDependabot(":smoke-tests:apps:Sampling")
122122
hideFromDependabot(":smoke-tests:apps:SamplingOverrides")
123123
hideFromDependabot(":smoke-tests:apps:SamplingOverridesBackCompat")
124+
hideFromDependabot(":smoke-tests:apps:ServiceVersionFromManifest")
125+
hideFromDependabot(":smoke-tests:apps:ServiceVersionFromSpring")
124126
hideFromDependabot(":smoke-tests:apps:SpringBoot")
125127
hideFromDependabot(":smoke-tests:apps:SpringBootAuto")
126128
hideFromDependabot(":smoke-tests:apps:SpringBootAuto1_3")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("ai.smoke-test-jar")
3+
}
4+
5+
dependencies {
6+
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
7+
}
8+
9+
tasks.withType<Jar> {
10+
manifest {
11+
attributes(
12+
"Implementation-Version" to "1.2.3"
13+
)
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
@SpringBootApplication
10+
public class SpringBootApp {
11+
12+
public static void main(String[] args) {
13+
14+
SpringApplication.run(SpringBootApp.class, args);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
public class TestController {
11+
12+
@GetMapping("/")
13+
public String root() {
14+
return "OK";
15+
}
16+
17+
@GetMapping("/test")
18+
public String test() {
19+
return "hello";
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketest;
5+
6+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11;
7+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_11_OPENJ9;
8+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17;
9+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17_OPENJ9;
10+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21;
11+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21_OPENJ9;
12+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8;
13+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8_OPENJ9;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
import static org.assertj.core.data.MapEntry.entry;
16+
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.extension.RegisterExtension;
19+
20+
@UseAgent
21+
abstract class ApplicationVerTest {
22+
23+
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
24+
25+
@Test
26+
@TargetUri("/test")
27+
void test() throws Exception {
28+
Telemetry telemetry = testing.getTelemetry(0);
29+
30+
assertThat(telemetry.rd.getName()).isEqualTo("GET /test");
31+
assertThat(telemetry.rd.getUrl()).matches("http://localhost:[0-9]+/test");
32+
assertThat(telemetry.rd.getResponseCode()).isEqualTo("200");
33+
assertThat(telemetry.rd.getSuccess()).isTrue();
34+
assertThat(telemetry.rd.getSource()).isNull();
35+
assertThat(telemetry.rd.getProperties())
36+
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
37+
assertThat(telemetry.rd.getMeasurements()).isEmpty();
38+
39+
assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.application.ver", "1.2.3");
40+
}
41+
42+
@Environment(JAVA_8)
43+
static class Java8Test extends ApplicationVerTest {}
44+
45+
@Environment(JAVA_8_OPENJ9)
46+
static class Java8OpenJ9Test extends ApplicationVerTest {}
47+
48+
@Environment(JAVA_11)
49+
static class Java11Test extends ApplicationVerTest {}
50+
51+
@Environment(JAVA_11_OPENJ9)
52+
static class Java11OpenJ9Test extends ApplicationVerTest {}
53+
54+
@Environment(JAVA_17)
55+
static class Java17Test extends ApplicationVerTest {}
56+
57+
@Environment(JAVA_17_OPENJ9)
58+
static class Java17OpenJ9Test extends ApplicationVerTest {}
59+
60+
@Environment(JAVA_21)
61+
static class Java21Test extends ApplicationVerTest {}
62+
63+
@Environment(JAVA_21_OPENJ9)
64+
static class Java21OpenJ9Test extends ApplicationVerTest {}
65+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
<root level="warn">
9+
<appender-ref ref="CONSOLE"/>
10+
</root>
11+
</configuration>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id("ai.smoke-test-jar")
3+
}
4+
5+
dependencies {
6+
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
@SpringBootApplication
10+
public class SpringBootApp {
11+
12+
public static void main(String[] args) {
13+
14+
SpringApplication.run(SpringBootApp.class, args);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
public class TestController {
11+
12+
@GetMapping("/")
13+
public String root() {
14+
return "OK";
15+
}
16+
17+
@GetMapping("/test")
18+
public String test() {
19+
return "hello";
20+
}
21+
}

0 commit comments

Comments
 (0)