Skip to content

Commit fcfeac0

Browse files
committed
move logging of errors to end of agent.start
1 parent afadc51 commit fcfeac0

File tree

2 files changed

+13
-17
lines changed
  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap
  • internal-api/src/main/java/datadog/trace/api

2 files changed

+13
-17
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import datadog.trace.bootstrap.instrumentation.jfr.InstrumentationBasedProfiling;
4242
import datadog.trace.util.AgentTaskScheduler;
4343
import datadog.trace.util.AgentThreadFactory.AgentThread;
44+
import datadog.trace.util.SystemUtils;
4445
import datadog.trace.util.throwable.FatalAgentMisconfigurationError;
4546
import java.lang.instrument.Instrumentation;
4647
import java.lang.reflect.InvocationTargetException;
@@ -370,6 +371,18 @@ public void run() {
370371
StaticEventLogger.end("Profiling");
371372
}
372373

374+
// log eventual errors that would have happened before we could log them
375+
if (SystemUtils.hasEnvError) {
376+
log.warn(
377+
"The Java Security Manager prevented the Datadog Tracer from accessing at least one environment variable. "
378+
+ "Consider granting AllPermission to the dd-java-agent jar.");
379+
}
380+
if (SystemUtils.hasPropertyError) {
381+
log.warn(
382+
"The Java Security Manager prevented the Datadog Tracer from accessing at least one system property. "
383+
+ "Consider granting AllPermission to the dd-java-agent jar.");
384+
}
385+
373386
StaticEventLogger.end("Agent.start");
374387
}
375388

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,24 +4025,7 @@ private static String getProp(String name, String def) {
40254025
: ConfigProvider.getInstance(),
40264026
InstrumenterConfig.get());
40274027

4028-
private static boolean configErrorsLogged = false;
4029-
40304028
public static Config get() {
4031-
// checking if there are errors that we couldn't log earlier to report
4032-
if (!configErrorsLogged && (SystemUtils.hasEnvError || SystemUtils.hasPropertyError)) {
4033-
// we want to log once, but if 2 threads end up here it's not a big issue.
4034-
configErrorsLogged = true;
4035-
if (SystemUtils.hasEnvError) {
4036-
log.warn(
4037-
"The Java Security Manager prevented the Datadog Tracer from accessing at least one environment variable. "
4038-
+ "Consider granting AllPermission to the dd-java-agent jar.");
4039-
}
4040-
if (SystemUtils.hasPropertyError) {
4041-
log.warn(
4042-
"The Java Security Manager prevented the Datadog Tracer from accessing at least one system property. "
4043-
+ "Consider granting AllPermission to the dd-java-agent jar.");
4044-
}
4045-
}
40464029
return INSTANCE;
40474030
}
40484031

0 commit comments

Comments
 (0)