Skip to content

Commit 965ab55

Browse files
authored
Fix tomcat instrumentation when user includes wrong servlet api (#10757)
1 parent 17a1a1d commit 965ab55

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

instrumentation/tomcat/tomcat-10.0/javaagent/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies {
2121

2222
// Make sure nothing breaks due to both 7.0 and 10.0 modules being present together
2323
testInstrumentation(project(":instrumentation:tomcat:tomcat-7.0:javaagent"))
24+
// testing whether instrumentation still works when javax servlet api is also present
25+
testImplementation("javax.servlet:javax.servlet-api:3.0.1")
2426
}
2527

2628
tasks {

instrumentation/tomcat/tomcat-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/Tomcat10InstrumentationModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Tomcat10InstrumentationModule() {
2525
@Override
2626
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
2727
// only matches tomcat 10.0+
28-
return hasClassesNamed("jakarta.servlet.ReadListener");
28+
return hasClassesNamed("jakarta.servlet.http.HttpServletRequest");
2929
}
3030

3131
@Override

instrumentation/tomcat/tomcat-7.0/javaagent/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
testInstrumentation(project(":instrumentation:servlet:servlet-javax-common:javaagent"))
2323
// Make sure nothing breaks due to both 7.0 and 10.0 modules being present together
2424
testInstrumentation(project(":instrumentation:tomcat:tomcat-10.0:javaagent"))
25+
// testing whether instrumentation still works when jakarta servlet api is also present
26+
testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0")
2527

2628
testLibrary("org.apache.tomcat.embed:tomcat-embed-core:8.0.41")
2729
testLibrary("org.apache.tomcat.embed:tomcat-embed-jasper:8.0.41")

instrumentation/tomcat/tomcat-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/Tomcat7InstrumentationModule.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
99
import static java.util.Collections.singletonList;
10-
import static net.bytebuddy.matcher.ElementMatchers.not;
1110

1211
import com.google.auto.service.AutoService;
1312
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
@@ -26,7 +25,7 @@ public Tomcat7InstrumentationModule() {
2625
@Override
2726
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
2827
// does not match tomcat 10.0+
29-
return not(hasClassesNamed("jakarta.servlet.ReadListener"));
28+
return hasClassesNamed("javax.servlet.http.HttpServletRequest");
3029
}
3130

3231
@Override

0 commit comments

Comments
 (0)