Fix grouping so any rule can allow module to be active.
MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
@@ -69,28 +69,44 @@ public class InstrumentationChecker {
// Check rules
boolean supported = false;
for (final ArtifactSupport check : rules.get(rule)) {
- if (frameworks.containsKey(check.artifact)) {
- // If no classes to scan, fall back on version regex.
- boolean matched =
- check.identifyingPresentClasses.isEmpty() && check.identifyingMissingClasses.isEmpty()
- ? Pattern.matches(check.supportedVersion, frameworks.get(check.artifact))
- : true;
+ log.debug("Checking rule {}", check);
+
+ boolean matched = true;
for (final String identifyingClass : check.identifyingPresentClasses) {
- matched &= isClassPresent(identifyingClass);
+ final boolean classPresent = isClassPresent(identifyingClass);
+ if (!classPresent) {
+ log.debug(
+ "Instrumentation {} not applied due to missing class {}.", rule, identifyingClass);
+ }
+ matched &= classPresent;
}
for (final String identifyingClass : check.identifyingMissingClasses) {
- matched &= !isClassPresent(identifyingClass);
+ final boolean classMissing = !isClassPresent(identifyingClass);
+ if (!classMissing) {
+ log.debug(
+ "Instrumentation {} not applied due to present class {}.", rule, identifyingClass);
+ }
+ matched &= classMissing;
}
+
+ final boolean useVersionMatching =
+ frameworks.containsKey(check.artifact)
+ && check.identifyingMissingClasses.isEmpty()
+ && check.identifyingPresentClasses.isEmpty();
+ if (useVersionMatching) {
+ // If no classes to scan, fall back on version regex.
+ matched = Pattern.matches(check.supportedVersion, frameworks.get(check.artifact));
if (!matched) {
log.debug(
"Library conflict: supported_version={}, actual_version={}",
check.supportedVersion,
frameworks.get(check.artifact));
- supported = false;
- break;
}
- supported = true;
- log.trace("Instrumentation rule={} is supported", rule);
+ }
+
+ supported |= matched;
+ if (supported) {
+ break;
}
}

MODIFY
dd-java-agent/src/main/resources/otarules.btm
dd-java-agent/src/main/resources/otarules.btm
@@ -91,6 +91,7 @@ ENDRULE
RULE opentracing-web-servlet-filter_tomcat
CLASS org.apache.catalina.core.ApplicationContext
METHOD <init>
+IMPORT javax.servlet.Filter
HELPER com.datadoghq.trace.agent.integration.TomcatServletHelper
AT EXIT
IF TRUE

MODIFY
dd-java-agent/src/test/groovy/com/datadoghq/trace/agent/InstrumentationCheckerTest.groovy
dd-java-agent/src/test/groovy/com/datadoghq/trace/agent/InstrumentationCheckerTest.groovy
@@ -21,7 +21,6 @@ class InstrumentationCheckerTest extends Specification {
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader())
expect:
- rules.size() == 3
rules.sort() == ["unsupportedRuleOne", "unsupportedRuleThree", "unsupportedRuleTwo"]
}

MODIFY
dd-java-agent/src/test/resources/supported-version-test.yaml
dd-java-agent/src/test/resources/supported-version-test.yaml
unsupportedRuleOne:
- artifact: artifact-1
- supported_version: 1\.2\.3\..*
+ supported_version: 1\.2\.5\..*
- artifact: artifact-2
supported_version: none

Fix grouping so any rule can allow module to be active.