Do not delay tracer on OpenJDK8 with JBOSS
MODIFY
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java
@@ -70,7 +70,7 @@ public class Agent {
* events which in turn loads LogManager. This is not a problem on newer JDKs because there JFR uses different
* logging facility.
*/
- if (isJavaBefore9() && appUsingCustomLogManager) {
+ if (isJavaBefore9WithJFR() && appUsingCustomLogManager) {
LOGGER.debug("Custom logger detected. Delaying Datadog Tracer initialization.");
registerLogManagerCallback(new InstallDatadogTracerCallback(inst, bootstrapURL));
} else {
@@ -341,4 +341,16 @@ public class Agent {
private static boolean isJavaBefore9() {
return System.getProperty("java.version").startsWith("1.");
}
+
+ private static boolean isJavaBefore9WithJFR() {
+ if (!isJavaBefore9()) {
+ return false;
+ }
+ // FIXME: this is quite a hack because there maybe jfr classes on classpath somehow that have
+ // nothing to do with JDK but this should be safe because only thing this does is to delay
+ // tracer install
+ final String jfrClassResourceName = "jdk.jfr.Recording".replace('.', '/') + ".class";
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(jfrClassResourceName)
+ != null;
+ }
}

MODIFY
dd-java-agent/src/test/java/jvmbootstraptest/LogManagerSetter.java
dd-java-agent/src/test/java/jvmbootstraptest/LogManagerSetter.java
@@ -106,7 +106,7 @@ public class LogManagerSetter {
}
private static void assertTraceInstallationDelayed(final String message) {
- if (isJavaBefore9()) {
+ if (isJavaBefore9WithJFR()) {
customAssert(isTracerInstalled(false), false, message);
} else {
customAssert(
@@ -154,7 +154,13 @@ public class LogManagerSetter {
return false;
}
- private static boolean isJavaBefore9() {
- return System.getProperty("java.version").startsWith("1.");
+ private static boolean isJavaBefore9WithJFR() {
+ if (!System.getProperty("java.version").startsWith("1.")) {
+ return false;
+ }
+
+ final String jfrClassResourceName = "jdk.jfr.Recording".replace('.', '/') + ".class";
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(jfrClassResourceName)
+ != null;
}
}

Do not delay tracer on OpenJDK8 with JBOSS