-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Avaje Jex Instrumentation #13733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6f449bd
Add Avaje Jex Instrumentation
SentryMan 3017e3e
Update JexTest.java
SentryMan 386cc0f
Update JexTest.java
SentryMan 9b775aa
Update build.gradle.kts
SentryMan e3ca443
Fix test
SentryMan 452c4b5
fix instrumentation name
SentryMan 19575fb
Update supported-libraries.md
SentryMan 5c0b0fc
Update supported-libraries.md
SentryMan dd45c23
pr comments
SentryMan 1b9453a
Update JexInstrumentation.java
SentryMan 624fe36
small change
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("io.avaje") | ||
| module.set("avaje-jex") | ||
| versions.set("[3.0,)") | ||
| assertInverse.set(true) | ||
| } | ||
| } | ||
|
|
||
| otelJava { | ||
| minJavaVersionSupported.set(JavaVersion.VERSION_21) | ||
| } | ||
|
|
||
| dependencies { | ||
| library("io.avaje:avaje-jex:3.0") | ||
| testLibrary("org.eclipse.jetty:jetty-http-spi:12.0.19") | ||
| testInstrumentation(project(":instrumentation:jetty:jetty-12.0:javaagent")) | ||
| } |
48 changes: 48 additions & 0 deletions
48
...in/java/io/opentelemetry/javaagent/instrumentation/avaje/jex/v3_0/JexInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.avaje.jex.v3_0; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isInterface; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.not; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
|
||
| import io.avaje.jex.http.Context; | ||
| import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; | ||
| import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| public class JexInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return hasSuperType(named("io.avaje.jex.http.ExchangeHandler")).and(not(isInterface())); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("handle").and(takesArgument(0, named("io.avaje.jex.http.Context"))), | ||
| this.getClass().getName() + "$HandlerAdapterAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class HandlerAdapterAdvice { | ||
|
|
||
| @Advice.OnMethodEnter | ||
| public static void onAfterExecute(@Advice.Argument(0) Context ctx) { | ||
SentryMan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| HttpServerRoute.update( | ||
| io.opentelemetry.context.Context.current(), | ||
| HttpServerRouteSource.CONTROLLER, | ||
| ctx.matchedPath()); | ||
| } | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
...a/io/opentelemetry/javaagent/instrumentation/avaje/jex/v3_0/JexInstrumentationModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.avaje.jex.v3_0; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import java.util.List; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| @SuppressWarnings("unused") | ||
| @AutoService(InstrumentationModule.class) | ||
| public class JexInstrumentationModule extends InstrumentationModule { | ||
|
|
||
| public JexInstrumentationModule() { | ||
| super("avaje-jex", "avaje-jex-3.0"); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return singletonList(new JexInstrumentation()); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
| return hasClassesNamed("io.avaje.jex.http.ExchangeHandler"); | ||
| } | ||
| } |
136 changes: 136 additions & 0 deletions
136
...gent/src/test/java/io/opentelemetry/javaagent/instrumentation/avaje/jex/v3_0/JexTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.avaje.jex.v3_0; | ||
|
|
||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; | ||
| import static io.opentelemetry.semconv.ClientAttributes.CLIENT_ADDRESS; | ||
| import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE; | ||
| import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD; | ||
| import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE; | ||
| import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE; | ||
| import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; | ||
| import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; | ||
| import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PROTOCOL_VERSION; | ||
| import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS; | ||
| import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT; | ||
| import static io.opentelemetry.semconv.UrlAttributes.URL_PATH; | ||
| import static io.opentelemetry.semconv.UrlAttributes.URL_SCHEME; | ||
| import static io.opentelemetry.semconv.UserAgentAttributes.USER_AGENT_ORIGINAL; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.avaje.jex.Jex.Server; | ||
| import io.opentelemetry.api.trace.SpanKind; | ||
| import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
| import io.opentelemetry.testing.internal.armeria.client.WebClient; | ||
| import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| class JexTest { | ||
|
|
||
| @RegisterExtension | ||
| private static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
|
||
| private static Server app; | ||
| private static int port; | ||
| private static WebClient client; | ||
|
|
||
| @BeforeAll | ||
| static void setup() { | ||
| app = TestJexJavaApplication.initJex(); | ||
| port = app.port(); | ||
| client = WebClient.of("http://localhost:" + port); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void cleanup() { | ||
| app.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| void testSpanNameAndHttpRouteSpanWithPathParamResponseSuccessful() { | ||
| String id = "123"; | ||
| AggregatedHttpResponse response = client.get("/test/param/" + id).aggregate().join(); | ||
| String content = response.contentUtf8(); | ||
|
|
||
| assertThat(content).isEqualTo(id); | ||
| assertThat(response.status().code()).isEqualTo(200); | ||
| testing.waitAndAssertTraces( | ||
| trace -> | ||
| trace.hasSpansSatisfyingExactly( | ||
| span -> | ||
| span.hasName("GET /test/param/{id}") | ||
| .hasKind(SpanKind.SERVER) | ||
| .hasNoParent() | ||
| .hasAttributesSatisfyingExactly( | ||
| equalTo(URL_SCHEME, "http"), | ||
| equalTo(URL_PATH, "/test/param/" + id), | ||
| equalTo(HTTP_REQUEST_METHOD, "GET"), | ||
| equalTo(HTTP_RESPONSE_STATUS_CODE, 200), | ||
| satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), | ||
| equalTo(HTTP_ROUTE, "/test/param/{id}"), | ||
| equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), | ||
| equalTo(SERVER_ADDRESS, "localhost"), | ||
| equalTo(SERVER_PORT, port), | ||
| equalTo(CLIENT_ADDRESS, "127.0.0.1"), | ||
| equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), | ||
| satisfies(NETWORK_PEER_PORT, val -> val.isInstanceOf(Long.class))))); | ||
| } | ||
|
|
||
| @Test | ||
| void testSpanNameAndHttpRouteSpanResponseError() { | ||
| client.get("/test/error").aggregate().join(); | ||
|
|
||
| testing.waitAndAssertTraces( | ||
| trace -> | ||
| trace.hasSpansSatisfyingExactly( | ||
| span -> | ||
| span.hasName("GET /test/error") | ||
| .hasKind(SpanKind.SERVER) | ||
| .hasNoParent() | ||
| .hasAttributesSatisfyingExactly( | ||
| equalTo(URL_SCHEME, "http"), | ||
| equalTo(URL_PATH, "/test/error"), | ||
| equalTo(HTTP_REQUEST_METHOD, "GET"), | ||
| equalTo(HTTP_RESPONSE_STATUS_CODE, 500), | ||
| satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), | ||
| equalTo(HTTP_ROUTE, "/test/error"), | ||
| equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), | ||
| equalTo(SERVER_ADDRESS, "localhost"), | ||
| equalTo(SERVER_PORT, port), | ||
| equalTo(ERROR_TYPE, "500"), | ||
| equalTo(CLIENT_ADDRESS, "127.0.0.1"), | ||
| equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), | ||
| satisfies(NETWORK_PEER_PORT, val -> val.isInstanceOf(Long.class))))); | ||
| } | ||
|
|
||
| @Test | ||
| void testHttpRouteMetricWithPathParamResponseSuccessful() { | ||
| String id = "123"; | ||
| AggregatedHttpResponse response = client.get("/test/param/" + id).aggregate().join(); | ||
| String content = response.contentUtf8(); | ||
| String instrumentation = "io.opentelemetry.jetty-12.0"; | ||
SentryMan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assertThat(content).isEqualTo(id); | ||
| assertThat(response.status().code()).isEqualTo(200); | ||
| testing.waitAndAssertMetrics( | ||
| instrumentation, | ||
| "http.server.request.duration", | ||
| metrics -> | ||
| metrics.anySatisfy( | ||
| metric -> | ||
| assertThat(metric) | ||
| .hasHistogramSatisfying( | ||
| histogram -> | ||
| histogram.hasPointsSatisfying( | ||
| point -> point.hasAttribute(HTTP_ROUTE, "/test/param/{id}"))))); | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
...ava/io/opentelemetry/javaagent/instrumentation/avaje/jex/v3_0/TestJexJavaApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.avaje.jex.v3_0; | ||
|
|
||
| import io.avaje.jex.Jex; | ||
| import io.avaje.jex.Jex.Server; | ||
|
|
||
| public class TestJexJavaApplication { | ||
|
|
||
| private TestJexJavaApplication() {} | ||
|
|
||
| public static Server initJex() { | ||
| Jex app = Jex.create().contextPath("/test"); | ||
| app.get( | ||
| "/param/{id}", | ||
| ctx -> { | ||
| String paramId = ctx.pathParam("id"); | ||
| ctx.write(paramId); | ||
| }); | ||
| app.get( | ||
| "/error", | ||
| ctx -> { | ||
| throw new RuntimeException("boom"); | ||
| }); | ||
| return app.port(0).start(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.