Skip to content

Commit

Permalink
Fix tomcat instrumentation when user includes wrong servlet api (#10757)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Mar 5, 2024
1 parent 17a1a1d commit 965ab55
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions instrumentation/tomcat/tomcat-10.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies {

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

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Tomcat10InstrumentationModule() {
@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// only matches tomcat 10.0+
return hasClassesNamed("jakarta.servlet.ReadListener");
return hasClassesNamed("jakarta.servlet.http.HttpServletRequest");
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/tomcat/tomcat-7.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
testInstrumentation(project(":instrumentation:servlet:servlet-javax-common:javaagent"))
// Make sure nothing breaks due to both 7.0 and 10.0 modules being present together
testInstrumentation(project(":instrumentation:tomcat:tomcat-10.0:javaagent"))
// testing whether instrumentation still works when jakarta servlet api is also present
testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0")

testLibrary("org.apache.tomcat.embed:tomcat-embed-core:8.0.41")
testLibrary("org.apache.tomcat.embed:tomcat-embed-jasper:8.0.41")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static java.util.Collections.singletonList;
import static net.bytebuddy.matcher.ElementMatchers.not;

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

@Override
Expand Down

0 comments on commit 965ab55

Please sign in to comment.