Do not delay tracer on OpenJDK8 with JBOSS

This commit is contained in:
Nikolay Martynov 2019-11-07 13:45:56 -05:00
parent f371e391a8
commit 8f80a42c4d
2 changed files with 22 additions and 4 deletions

View File

@ -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 * events which in turn loads LogManager. This is not a problem on newer JDKs because there JFR uses different
* logging facility. * logging facility.
*/ */
if (isJavaBefore9() && appUsingCustomLogManager) { if (isJavaBefore9WithJFR() && appUsingCustomLogManager) {
LOGGER.debug("Custom logger detected. Delaying Datadog Tracer initialization."); LOGGER.debug("Custom logger detected. Delaying Datadog Tracer initialization.");
registerLogManagerCallback(new InstallDatadogTracerCallback(inst, bootstrapURL)); registerLogManagerCallback(new InstallDatadogTracerCallback(inst, bootstrapURL));
} else { } else {
@ -341,4 +341,16 @@ public class Agent {
private static boolean isJavaBefore9() { private static boolean isJavaBefore9() {
return System.getProperty("java.version").startsWith("1."); 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;
}
} }

View File

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