Skip to content

Commit 64eb586

Browse files
authored
Fix jaxrs annotation instrumentation on openliberty (#7890)
Hopefully resolves #7870 Jax-rs annotation instrumentation is only enabled when jax-rs api is found in the class loader. This check does a `ClassLoader.getResource` call for the resource name corresponding to class `javax.ws.rs.container.AsyncResponse`. As far as I understand this particular class is used only because it was added in jax-rs 2.0, any other class added in jax-rs 2.0 could be used instead of it. On openliberty we fail to find this class because it should be resolved through bundle dynamic imports but we disable looking into dynamic imports in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/internal/internal-eclipse-osgi-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/osgi/EclipseOsgiInstrumentation.java when we do the class presence check. Using a class in `javax.ws.rs.core` package seems to work better as the import for that package is already resolved by the time we make the `getResource` call.
1 parent cbc616c commit 64eb586

File tree

4 files changed

+2
-12
lines changed

4 files changed

+2
-12
lines changed

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0;
77

8-
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
98
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperMethod;
109
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
1110
import static io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0.JaxrsAnnotationsSingletons.instrumenter;
@@ -37,10 +36,6 @@
3736
import net.bytebuddy.matcher.ElementMatcher;
3837

3938
public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
40-
@Override
41-
public ElementMatcher<ClassLoader> classLoaderOptimization() {
42-
return hasClassesNamed("javax.ws.rs.Path");
43-
}
4439

4540
@Override
4641
public ElementMatcher<TypeDescription> typeMatcher() {

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public JaxrsAnnotationsInstrumentationModule() {
2323
// require jax-rs 2
2424
@Override
2525
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
26-
return hasClassesNamed("javax.ws.rs.container.AsyncResponse");
26+
return hasClassesNamed("javax.ws.rs.core.Configurable");
2727
}
2828

2929
@Override

instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.jaxrs.v3_0;
77

8-
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
98
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperMethod;
109
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
1110
import static io.opentelemetry.javaagent.instrumentation.jaxrs.v3_0.JaxrsAnnotationsSingletons.instrumenter;
@@ -37,10 +36,6 @@
3736
import net.bytebuddy.matcher.ElementMatcher;
3837

3938
public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
40-
@Override
41-
public ElementMatcher<ClassLoader> classLoaderOptimization() {
42-
return hasClassesNamed("jakarta.ws.rs.Path");
43-
}
4439

4540
@Override
4641
public ElementMatcher<TypeDescription> typeMatcher() {

instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public JaxrsAnnotationsInstrumentationModule() {
2323
// require jax-rs 3
2424
@Override
2525
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
26-
return hasClassesNamed("jakarta.ws.rs.container.AsyncResponse");
26+
return hasClassesNamed("jakarta.ws.rs.Path");
2727
}
2828

2929
@Override

0 commit comments

Comments
 (0)