Skip to content

Commit e36fc46

Browse files
jeanbisuttitrask
andauthored
GraalVM native support for the OpenTelemetry annotations (#11757)
Co-authored-by: Trask Stalnaker <[email protected]>
1 parent 948a58e commit e36fc46

File tree

11 files changed

+66
-5
lines changed

11 files changed

+66
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;
7+
8+
import org.springframework.aot.hint.MemberCategory;
9+
import org.springframework.aot.hint.RuntimeHints;
10+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
11+
import org.springframework.aot.hint.TypeReference;
12+
13+
class OpenTelemetryAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
14+
15+
@Override
16+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
17+
hints
18+
.reflection()
19+
.registerType(
20+
TypeReference.of(
21+
"io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations.InstrumentationWithSpanAspect"),
22+
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations.OpenTelemetryAnnotationsRuntimeHints

smoke-tests-otel-starter/spring-boot-2/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
implementation("org.apache.commons:commons-dbcp2")
1313
implementation("org.springframework.kafka:spring-kafka")
1414
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
15+
implementation("org.springframework.boot:spring-boot-starter-aop")
1516
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
1617

1718
implementation(project(":smoke-tests-otel-starter:spring-boot-common"))

smoke-tests-otel-starter/spring-boot-3.2/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
implementation("org.apache.commons:commons-dbcp2")
1818
implementation("org.springframework.kafka:spring-kafka")
1919
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
20+
implementation("org.springframework.boot:spring-boot-starter-aop")
2021
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
2122

2223
implementation(project(":smoke-tests-otel-starter:spring-boot-common"))

smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void restClient() {
5252
private static void assertClient(TraceAssert traceAssert) {
5353
traceAssert.hasSpansSatisfyingExactly(
5454
span -> AbstractOtelSpringStarterSmokeTest.assertClientSpan(span, "/ping"),
55-
span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"));
55+
span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"),
56+
span -> withSpanAssert(span));
5657
}
5758
}

smoke-tests-otel-starter/spring-boot-3/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
implementation("org.apache.commons:commons-dbcp2")
1818
implementation("org.springframework.kafka:spring-kafka")
1919
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
20+
implementation("org.springframework.boot:spring-boot-starter-aop")
2021
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
2122

2223
implementation(project(":smoke-tests-otel-starter:spring-boot-common"))

smoke-tests-otel-starter/spring-boot-common/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
compileOnly("org.testcontainers:junit-jupiter")
2020
compileOnly("org.testcontainers:kafka")
2121
compileOnly("org.testcontainers:mongodb")
22+
compileOnly("org.springframework.boot:spring-boot-starter-aop")
2223

2324
api(project(":smoke-tests-otel-starter:spring-smoke-testing"))
2425

smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ void shouldSendTelemetry() {
175175
equalTo(ClientAttributes.CLIENT_ADDRESS, "127.0.0.1"),
176176
satisfies(
177177
ServerAttributes.SERVER_PORT,
178-
integerAssert -> integerAssert.isNotZero()))));
178+
integerAssert -> integerAssert.isNotZero())),
179+
span -> withSpanAssert(span)));
179180

180181
// Metric
181182
testing.waitAndAssertMetrics(
@@ -236,8 +237,8 @@ void restTemplate() {
236237
traceAssert.hasSpansSatisfyingExactly(
237238
span -> assertClientSpan(span, "/ping"),
238239
span ->
239-
span.hasKind(SpanKind.SERVER)
240-
.hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping")));
240+
span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"),
241+
span -> withSpanAssert(span)));
241242
}
242243

243244
public static void assertClientSpan(SpanDataAssert span, String path) {

smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTestController.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ public class OtelSpringStarterSmokeTestController {
2020
public static final String TEST_HISTOGRAM = "histogram-test-otel-spring-starter";
2121
public static final String METER_SCOPE_NAME = "scope";
2222
private final LongHistogram histogram;
23+
private final SpringComponent component;
2324

24-
public OtelSpringStarterSmokeTestController(OpenTelemetry openTelemetry) {
25+
public OtelSpringStarterSmokeTestController(
26+
OpenTelemetry openTelemetry, SpringComponent springComponent) {
2527
Meter meter = openTelemetry.getMeter(METER_SCOPE_NAME);
2628
histogram = meter.histogramBuilder(TEST_HISTOGRAM).ofLongs().build();
29+
this.component = springComponent;
2730
}
2831

2932
@GetMapping(PING)
3033
public String ping() {
3134
histogram.record(10);
35+
component.withSpanMethod("from-controller");
3236
return "pong";
3337
}
3438
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.spring.smoketest;
7+
8+
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
9+
import io.opentelemetry.instrumentation.annotations.WithSpan;
10+
import org.springframework.stereotype.Component;
11+
12+
@Component
13+
public class SpringComponent {
14+
15+
@SuppressWarnings("MethodCanBeStatic")
16+
@WithSpan
17+
public void withSpanMethod(@SpanAttribute String paramName) {}
18+
}

smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/AbstractSpringStarterSmokeTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import static org.assertj.core.api.Assertions.assertThat;
99

1010
import io.opentelemetry.api.OpenTelemetry;
11+
import io.opentelemetry.api.common.AttributeKey;
12+
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
1113
import java.util.Arrays;
1214
import java.util.List;
1315
import org.junit.jupiter.api.AfterEach;
@@ -61,4 +63,9 @@ void checkSpringLogs(CapturedOutput output) {
6163
}
6264
});
6365
}
66+
67+
static SpanDataAssert withSpanAssert(SpanDataAssert span) {
68+
return span.hasName("SpringComponent.withSpanMethod")
69+
.hasAttribute(AttributeKey.stringKey("paramName"), "from-controller");
70+
}
6471
}

0 commit comments

Comments
 (0)