-
Notifications
You must be signed in to change notification settings - Fork 843
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
Add instrumentation for quarkus-resteasy-reactive #8487
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
instrumentation/quarkus-resteasy-reactive/common-testing/build.gradle.kts
This file contains 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,7 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":testing-common")) | ||
} |
99 changes: 99 additions & 0 deletions
99
.../io/opentelemetry/instrumentation/quarkus/resteasy/reactive/AbstractQuarkusJaxRsTest.java
This file contains 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,99 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.quarkus.resteasy.reactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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.ClientFactory; | ||
import io.opentelemetry.testing.internal.armeria.client.WebClient; | ||
import io.opentelemetry.testing.internal.armeria.client.logging.LoggingClient; | ||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest; | ||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; | ||
import io.opentelemetry.testing.internal.armeria.common.HttpMethod; | ||
import java.time.Duration; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public abstract class AbstractQuarkusJaxRsTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
private static WebClient client; | ||
private static int port; | ||
|
||
@BeforeAll | ||
static void setUp() { | ||
client = | ||
WebClient.builder() | ||
.responseTimeout(Duration.ofMinutes(1)) | ||
.writeTimeout(Duration.ofMinutes(1)) | ||
.factory(ClientFactory.builder().connectTimeout(Duration.ofMinutes(1)).build()) | ||
.decorator(LoggingClient.newDecorator()) | ||
.build(); | ||
port = Integer.parseInt(System.getProperty("quarkus.http.test-port")); | ||
} | ||
|
||
private static AggregatedHttpResponse request(String path) { | ||
AggregatedHttpRequest request = | ||
AggregatedHttpRequest.of(HttpMethod.GET, "h1c://localhost:" + port + path); | ||
return client.execute(request).aggregate().join(); | ||
} | ||
|
||
@Test | ||
void testPathOnMethod() { | ||
AggregatedHttpResponse response = request("/test"); | ||
assertThat(response.status().code()).isEqualTo(200); | ||
assertThat(response.contentUtf8()).isEqualTo("success"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> span.hasName("GET /test").hasKind(SpanKind.SERVER))); | ||
} | ||
|
||
@Test | ||
void testPathOnClass() { | ||
AggregatedHttpResponse response = request("/hello"); | ||
assertThat(response.status().code()).isEqualTo(200); | ||
assertThat(response.contentUtf8()).isEqualTo("hello"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> span.hasName("GET /hello").hasKind(SpanKind.SERVER))); | ||
} | ||
|
||
@Test | ||
void testPathParameter() { | ||
AggregatedHttpResponse response = request("/hello/greeting/test"); | ||
assertThat(response.status().code()).isEqualTo(200); | ||
assertThat(response.contentUtf8()).isEqualTo("hello test"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> span.hasName("GET /hello/greeting/{name}").hasKind(SpanKind.SERVER))); | ||
} | ||
|
||
@Test | ||
void testSubResourceLocator() { | ||
AggregatedHttpResponse response = request("/test-sub-resource-locator/call/sub"); | ||
assertThat(response.status().code()).isEqualTo(200); | ||
assertThat(response.contentUtf8()).isEqualTo("success"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("GET /test-sub-resource-locator/call/sub") | ||
.hasKind(SpanKind.SERVER))); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
instrumentation/quarkus-resteasy-reactive/javaagent/build.gradle.kts
This file contains 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,16 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("io.quarkus") | ||
module.set("quarkus-resteasy-reactive") | ||
versions.set("(,)") | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly("io.quarkus:quarkus-resteasy-reactive:1.11.0.Final") | ||
implementation(project(":instrumentation:jaxrs:jaxrs-common:javaagent")) | ||
} |
40 changes: 40 additions & 0 deletions
40
...javaagent/instrumentation/quarkus/resteasy/reactive/InvocationHandlerInstrumentation.java
This file contains 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,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.quarkus.resteasy.reactive; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import io.opentelemetry.context.Scope; | ||
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; | ||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; | ||
|
||
public class InvocationHandlerInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.jboss.resteasy.reactive.server.handlers.InvocationHandler"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("handle"), InvocationHandlerInstrumentation.class.getName() + "$HandleAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class HandleAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.Argument(0) ResteasyReactiveRequestContext requestContext, | ||
@Advice.Local("otelScope") Scope scope) { | ||
ResteasyReactiveSpanName.INSTANCE.updateServerSpanName(requestContext); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...strumentation/quarkus/resteasy/reactive/QuarkusResteasyReactiveInstrumentationModule.java
This file contains 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,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.quarkus.resteasy.reactive; | ||
|
||
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; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public class QuarkusResteasyReactiveInstrumentationModule extends InstrumentationModule { | ||
|
||
public QuarkusResteasyReactiveInstrumentationModule() { | ||
super("quarkus", "jaxrs", "quarkus-resteasy-reactive", "quarkus-resteasy-reactive-3.0"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return singletonList(new InvocationHandlerInstrumentation()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...lemetry/javaagent/instrumentation/quarkus/resteasy/reactive/ResteasyReactiveSpanName.java
This file contains 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,59 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.quarkus.resteasy.reactive; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.jaxrs.JaxrsPathUtil.normalizePath; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; | ||
import io.opentelemetry.instrumentation.api.util.VirtualField; | ||
import javax.annotation.Nullable; | ||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; | ||
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource; | ||
import org.jboss.resteasy.reactive.server.mapping.URITemplate; | ||
|
||
public class ResteasyReactiveSpanName implements HttpRouteGetter<String> { | ||
// remember previous path to handle sub path locators | ||
private static final VirtualField<ResteasyReactiveRequestContext, String> pathField = | ||
VirtualField.find(ResteasyReactiveRequestContext.class, String.class); | ||
|
||
public static final ResteasyReactiveSpanName INSTANCE = new ResteasyReactiveSpanName(); | ||
|
||
public void updateServerSpanName(ResteasyReactiveRequestContext requestContext) { | ||
Context context = Context.current(); | ||
String jaxRsName = calculateJaxRsName(requestContext); | ||
HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.NESTED_CONTROLLER, this, jaxRsName); | ||
pathField.set(requestContext, jaxRsName); | ||
} | ||
|
||
private static String calculateJaxRsName(ResteasyReactiveRequestContext requestContext) { | ||
RuntimeResource target = requestContext.getTarget(); | ||
URITemplate classPath = target.getClassPath(); | ||
URITemplate path = target.getPath(); | ||
String name = normalize(classPath) + normalize(path); | ||
if (name.isEmpty()) { | ||
return null; | ||
} | ||
String existingPath = pathField.get(requestContext); | ||
return existingPath == null || existingPath.isEmpty() ? name : existingPath + name; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public String get(Context context, String jaxRsName) { | ||
return jaxRsName; | ||
} | ||
|
||
private static String normalize(URITemplate uriTemplate) { | ||
if (uriTemplate == null) { | ||
return ""; | ||
} | ||
|
||
return normalizePath(uriTemplate.template); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
instrumentation/quarkus-resteasy-reactive/quarkus2-testing/build.gradle.kts
This file contains 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,33 @@ | ||
plugins { | ||
id("otel.javaagent-testing") | ||
|
||
id("io.quarkus") version "2.16.7.Final" | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_11) | ||
} | ||
|
||
dependencies { | ||
implementation(enforcedPlatform("io.quarkus.platform:quarkus-bom:2.16.7.Final")) | ||
implementation("io.quarkus:quarkus-resteasy-reactive") | ||
|
||
testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent")) | ||
testInstrumentation(project(":instrumentation:quarkus-resteasy-reactive:javaagent")) | ||
|
||
testImplementation(project(":instrumentation:quarkus-resteasy-reactive:common-testing")) | ||
testImplementation("io.quarkus:quarkus-junit5") | ||
} | ||
|
||
tasks.named("compileJava").configure { | ||
dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) | ||
} | ||
tasks.named("sourcesJar").configure { | ||
dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) | ||
} | ||
tasks.named("checkstyleTest").configure { | ||
dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) | ||
} | ||
tasks.named("compileTestJava").configure { | ||
dependsOn(tasks.named("compileQuarkusTestGeneratedSourcesJava")) | ||
} |
24 changes: 24 additions & 0 deletions
24
...ava/io/opentelemetry/instrumentation/quarkus/resteasy/reactive/v2_0/GreetingResource.java
This file contains 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,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.quarkus.resteasy.reactive.v2_0; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/hello") | ||
public class GreetingResource { | ||
|
||
@GET | ||
@Path("/greeting/{name}") | ||
public String greeting(String name) { | ||
return "hello " + name; | ||
} | ||
|
||
@GET | ||
public String hello() { | ||
return "hello"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...emetry/instrumentation/quarkus/resteasy/reactive/v2_0/SubResourceLocatorTestResource.java
This file contains 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,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.quarkus.resteasy.reactive.v2_0; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("test-sub-resource-locator") | ||
public class SubResourceLocatorTestResource { | ||
|
||
@Path("call") | ||
public Object call() { | ||
return new SubResource(); | ||
} | ||
|
||
public static class SubResource { | ||
@Path("sub") | ||
@GET | ||
public String call() { | ||
return "success"; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ava/io/opentelemetry/instrumentation/quarkus/resteasy/reactive/v2_0/TestRootResource.java
This file contains 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,19 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.quarkus.resteasy.reactive.v2_0; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("") | ||
public class TestRootResource { | ||
|
||
@GET | ||
@Path("test") | ||
public String test() { | ||
return "success"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...tion/quarkus-resteasy-reactive/quarkus2-testing/src/main/resources/application.properties
This file contains 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 @@ | ||
quarkus.http.test-port=0 |
12 changes: 12 additions & 0 deletions
12
...ava/io/opentelemetry/instrumentation/quarkus/resteasy/reactive/v2_0/QuarkusJaxRsTest.java
This file contains 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,12 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.quarkus.resteasy.reactive.v2_0; | ||
|
||
import io.opentelemetry.instrumentation.quarkus.resteasy.reactive.AbstractQuarkusJaxRsTest; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class QuarkusJaxRsTest extends AbstractQuarkusJaxRsTest {} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpRouteHolder
has a variant where it simply accepts aString
route; you can use it and skip implementing the "fake"HttpRouteGetter