Skip to content

Commit 71886d7

Browse files
committed
Remove exemption where we didn't defer if the custom logging manager
or JMX builder was on the system classpath (because the main thread would find it there if OkHttp triggered initialization of JUL.). We now make OkHttp calls from our own background threads, which are isolated from the system classloader, not the main thread - so this exemption no longer makes sense.
1 parent 46b5986 commit 71886d7

File tree

3 files changed

+39
-83
lines changed

3 files changed

+39
-83
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static datadog.trace.util.AgentThreadFactory.AgentThread.PROFILER_STARTUP;
1111
import static datadog.trace.util.AgentThreadFactory.AgentThread.TRACE_STARTUP;
1212
import static datadog.trace.util.AgentThreadFactory.newAgentThread;
13-
import static datadog.trace.util.Strings.getResourceName;
1413
import static datadog.trace.util.Strings.propertyNameToSystemPropertyName;
1514
import static datadog.trace.util.Strings.toEnvVar;
1615

@@ -1267,14 +1266,8 @@ private static boolean isAppUsingCustomLogManager(final EnumSet<Library> librari
12671266

12681267
final String logManagerProp = System.getProperty("java.util.logging.manager");
12691268
if (logManagerProp != null) {
1270-
final boolean onSysClasspath =
1271-
ClassLoader.getSystemResource(getResourceName(logManagerProp)) != null;
12721269
log.debug("Prop - logging.manager: {}", logManagerProp);
1273-
log.debug("logging.manager on system classpath: {}", onSysClasspath);
1274-
// Some applications set java.util.logging.manager but never actually initialize the logger.
1275-
// Check to see if the configured manager is on the system classpath.
1276-
// If so, it should be safe to initialize jmxfetch which will setup the log manager.
1277-
return !onSysClasspath;
1270+
return true;
12781271
}
12791272

12801273
return false;
@@ -1305,14 +1298,8 @@ private static boolean isAppUsingCustomJMXBuilder(final EnumSet<Library> librari
13051298

13061299
final String jmxBuilderProp = System.getProperty("javax.management.builder.initial");
13071300
if (jmxBuilderProp != null) {
1308-
final boolean onSysClasspath =
1309-
ClassLoader.getSystemResource(getResourceName(jmxBuilderProp)) != null;
13101301
log.debug("Prop - javax.management.builder.initial: {}", jmxBuilderProp);
1311-
log.debug("javax.management.builder.initial on system classpath: {}", onSysClasspath);
1312-
// Some applications set javax.management.builder.initial but never actually initialize JMX.
1313-
// Check to see if the configured JMX builder is on the system classpath.
1314-
// If so, it should be safe to initialize jmxfetch which will setup JMX.
1315-
return !onSysClasspath;
1302+
return true;
13161303
}
13171304

13181305
return false;

dd-java-agent/src/test/java/jvmbootstraptest/LogManagerSetter.java

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,50 +39,31 @@ public static void main(final String... args) throws Exception {
3939
} else if (System.getProperty("java.util.logging.manager") != null) {
4040
System.out.println("java.util.logging.manager != null");
4141

42-
if (ClassLoader.getSystemResource(
43-
System.getProperty("java.util.logging.manager").replaceAll("\\.", "/") + ".class")
44-
== null) {
45-
assertTraceInstallationDelayed(
46-
"tracer install must be delayed when log manager system property is present.");
47-
customAssert(
48-
isJmxfetchStarted(false),
49-
false,
50-
"jmxfetch startup must be delayed when log manager system property is present.");
51-
if (isJFRSupported()) {
52-
assertProfilingStartupDelayed(
53-
"profiling startup must be delayed when log manager system property is present.");
54-
}
55-
// Change back to a valid LogManager.
56-
System.setProperty("java.util.logging.manager", CUSTOM_LOG_MANAGER_CLASS_NAME);
57-
customAssert(
58-
LogManager.getLogManager().getClass(),
59-
LogManagerSetter.class
60-
.getClassLoader()
61-
.loadClass(System.getProperty("java.util.logging.manager")),
62-
"Javaagent should not prevent setting a custom log manager");
63-
customAssert(
64-
isTracerInstalled(true), true, "tracer should be installed after loading LogManager.");
65-
customAssert(
66-
isJmxfetchStarted(true), true, "jmxfetch should start after loading LogManager.");
67-
if (isJFRSupported()) {
68-
customAssert(
69-
isProfilingStarted(true), true, "profiling should start after loading LogManager.");
70-
}
71-
} else {
72-
customAssert(
73-
isTracerInstalled(false),
74-
true,
75-
"tracer should be installed in premain when custom log manager found on classpath.");
42+
assertTraceInstallationDelayed(
43+
"tracer install must be delayed when log manager system property is present.");
44+
customAssert(
45+
isJmxfetchStarted(false),
46+
false,
47+
"jmxfetch startup must be delayed when log manager system property is present.");
48+
if (isJFRSupported()) {
49+
assertProfilingStartupDelayed(
50+
"profiling startup must be delayed when log manager system property is present.");
51+
}
52+
// Change back to a valid LogManager.
53+
System.setProperty("java.util.logging.manager", CUSTOM_LOG_MANAGER_CLASS_NAME);
54+
customAssert(
55+
LogManager.getLogManager().getClass(),
56+
LogManagerSetter.class
57+
.getClassLoader()
58+
.loadClass(System.getProperty("java.util.logging.manager")),
59+
"Javaagent should not prevent setting a custom log manager");
60+
customAssert(
61+
isTracerInstalled(true), true, "tracer should be installed after loading LogManager.");
62+
customAssert(
63+
isJmxfetchStarted(true), true, "jmxfetch should start after loading LogManager.");
64+
if (isJFRSupported()) {
7665
customAssert(
77-
isJmxfetchStarted(false),
78-
true,
79-
"jmxfetch should start in premain when custom log manager found on classpath.");
80-
if (isJFRSupported()) {
81-
customAssert(
82-
isProfilingStarted(false),
83-
true,
84-
"profiling should start in premain when custom log manager found on classpath.");
85-
}
66+
isProfilingStarted(true), true, "profiling should start after loading LogManager.");
8667
}
8768
} else if (System.getenv("JBOSS_HOME") != null) {
8869
System.out.println("JBOSS_HOME != null");

dd-java-agent/src/test/java/jvmbootstraptest/MBeanServerBuilderSetter.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,19 @@ public static void main(final String... args) throws Exception {
2626
} else if (System.getProperty("javax.management.builder.initial") != null) {
2727
System.out.println("javax.management.builder.initial != null");
2828

29-
if (ClassLoader.getSystemResource(
30-
System.getProperty("javax.management.builder.initial").replaceAll("\\.", "/")
31-
+ ".class")
32-
== null) {
33-
customAssert(
34-
isJmxfetchStarted(false),
35-
false,
36-
"jmxfetch startup must be delayed when management builder system property is present.");
37-
// Change back to a valid MBeanServerBuilder.
38-
System.setProperty(
39-
"javax.management.builder.initial", "jvmbootstraptest.CustomMBeanServerBuilder");
40-
customAssert(
41-
isCustomMBeanRegistered(),
42-
true,
43-
"Javaagent should not prevent setting a custom MBeanServerBuilder");
44-
customAssert(
45-
isJmxfetchStarted(true),
46-
true,
47-
"jmxfetch should start after loading MBeanServerBuilder.");
48-
} else {
49-
customAssert(
50-
isJmxfetchStarted(false),
51-
true,
52-
"jmxfetch should start in premain when custom MBeanServerBuilder found on classpath.");
53-
}
29+
customAssert(
30+
isJmxfetchStarted(false),
31+
false,
32+
"jmxfetch startup must be delayed when management builder system property is present.");
33+
// Change back to a valid MBeanServerBuilder.
34+
System.setProperty(
35+
"javax.management.builder.initial", "jvmbootstraptest.CustomMBeanServerBuilder");
36+
customAssert(
37+
isCustomMBeanRegistered(),
38+
true,
39+
"Javaagent should not prevent setting a custom MBeanServerBuilder");
40+
customAssert(
41+
isJmxfetchStarted(true), true, "jmxfetch should start after loading MBeanServerBuilder.");
5442
} else {
5543
System.out.println("No custom MBeanServerBuilder");
5644

0 commit comments

Comments
 (0)