Skip to content

Commit

Permalink
GraalVM native support for the OpenTelemetry annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti committed Jul 7, 2024
1 parent 4439dec commit 9ca9b7e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;

class OpenTelemetryAnnotationsRuntimeHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints
.reflection()
.registerType(
TypeReference.of(
"io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations.InstrumentationWithSpanAspect"),
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=\
opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations.OpenTelemetryRuntimeHints
2 changes: 2 additions & 0 deletions smoke-tests-otel-starter/spring-boot-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dependencies {
compileOnly("org.testcontainers:kafka")
compileOnly("org.testcontainers:mongodb")

implementation("org.springframework.boot:spring-boot-starter-aop")

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

implementation("io.opentelemetry:opentelemetry-extension-trace-propagators")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ void shouldSendTelemetry() {
equalTo(ClientAttributes.CLIENT_ADDRESS, "127.0.0.1"),
satisfies(
ServerAttributes.SERVER_PORT,
integerAssert -> integerAssert.isNotZero()))));
integerAssert -> integerAssert.isNotZero())),
span ->
span.hasName("SpringComponent.withSpanMethod")
.hasAttribute(AttributeKey.stringKey("paramName"), "from-controller")));

// Metric
testing.waitAndAssertMetrics(
Expand Down Expand Up @@ -236,8 +239,8 @@ void restTemplate() {
traceAssert.hasSpansSatisfyingExactly(
span -> assertClientSpan(span, "/ping"),
span ->
span.hasKind(SpanKind.SERVER)
.hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping")));
span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"),
span -> span.hasName("SpringComponent.withSpanMethod")));
}

public static void assertClientSpan(SpanDataAssert span, String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ public class OtelSpringStarterSmokeTestController {
public static final String TEST_HISTOGRAM = "histogram-test-otel-spring-starter";
public static final String METER_SCOPE_NAME = "scope";
private final LongHistogram histogram;
private final SpringComponent component;

public OtelSpringStarterSmokeTestController(OpenTelemetry openTelemetry) {
public OtelSpringStarterSmokeTestController(
OpenTelemetry openTelemetry, SpringComponent springComponent) {
Meter meter = openTelemetry.getMeter(METER_SCOPE_NAME);
histogram = meter.histogramBuilder(TEST_HISTOGRAM).ofLongs().build();
this.component = springComponent;
}

@GetMapping(PING)
public String ping() {
histogram.record(10);
component.withSpanMethod("from-controller");
return "pong";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.spring.smoketest;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.springframework.stereotype.Component;

@Component
public class SpringComponent {

@SuppressWarnings("MethodCanBeStatic")
@WithSpan()
public void withSpanMethod(@SpanAttribute String paramName) {}
}

0 comments on commit 9ca9b7e

Please sign in to comment.