restore classLoaderMatcher to make instrumentation safer
MODIFY
dd-java-agent/instrumentation/servlet-2/servlet-2.gradle
dd-java-agent/instrumentation/servlet-2/servlet-2.gradle
@@ -2,9 +2,11 @@ muzzle {
pass {
group = "javax.servlet"
module = "servlet-api"
- versions = "[2.3, 2.5]"
+ versions = "[2.3, 3.0)"
assertInverse = true
}
+ // can't add a fail block for servlet 3, because servlet 3 is backward compatible with servlet 2.3+,
+ // meaning that for every class that exists in servlet 2, it also exists in servlet 3
}
apply from: "${rootDir}/gradle/java.gradle"

MODIFY
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/AbstractServlet2Instrumentation.java
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/AbstractServlet2Instrumentation.java
package datadog.trace.instrumentation.servlet2;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
+import static net.bytebuddy.matcher.ElementMatchers.not;
+
import datadog.trace.agent.tooling.Instrumenter;
+import net.bytebuddy.matcher.ElementMatcher;
public abstract class AbstractServlet2Instrumentation extends Instrumenter.Default {
@@ -8,6 +12,12 @@ public abstract class AbstractServlet2Instrumentation extends Instrumenter.Defau
super("servlet", "servlet-2");
}
+ // this is required to make sure servlet 2 instrumentation won't apply to servlet 3
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ return not(classLoaderHasClasses("javax.servlet.AsyncEvent", "javax.servlet.AsyncListener"));
+ }
+
@Override
public String[] helperClassNames() {
return new String[] {

restore classLoaderMatcher to make instrumentation safer