1
1
package datadog .trace .bootstrap ;
2
2
3
+ import static datadog .trace .bootstrap .SystemUtils .getPropertyOrEnvVar ;
3
4
import static java .nio .charset .StandardCharsets .UTF_8 ;
4
5
5
6
import datadog .cli .CLIHelper ;
44
45
* </ul>
45
46
*/
46
47
public final class AgentBootstrap {
47
- static final String LIB_INJECTION_ENABLED_FLAG = "DD_INJECTION_ENABLED" ;
48
- static final String LIB_INJECTION_FORCE_FLAG = "DD_INJECT_FORCE " ;
48
+ static final String LIB_INJECTION_ENABLED_ENV_VAR = "DD_INJECTION_ENABLED" ;
49
+ static final String LIB_INJECTION_FORCE_SYS_PROP = "dd.inject.force " ;
49
50
50
51
private static final Class <?> thisClass = AgentBootstrap .class ;
51
52
private static final int MAX_EXCEPTION_CHAIN_LENGTH = 99 ;
@@ -155,11 +156,13 @@ private static void agentmainImpl(
155
156
156
157
static boolean getConfig (String configName ) {
157
158
switch (configName ) {
158
- case LIB_INJECTION_ENABLED_FLAG :
159
- return System .getenv (LIB_INJECTION_ENABLED_FLAG ) != null ;
160
- case LIB_INJECTION_FORCE_FLAG :
161
- String libInjectionForceFlag = System .getenv (LIB_INJECTION_FORCE_FLAG );
162
- return "true" .equalsIgnoreCase (libInjectionForceFlag ) || "1" .equals (libInjectionForceFlag );
159
+ case LIB_INJECTION_ENABLED_ENV_VAR :
160
+ return System .getenv (LIB_INJECTION_ENABLED_ENV_VAR ) != null ;
161
+ case LIB_INJECTION_FORCE_SYS_PROP :
162
+ {
163
+ String injectionForceFlag = getPropertyOrEnvVar (LIB_INJECTION_FORCE_SYS_PROP );
164
+ return "true" .equalsIgnoreCase (injectionForceFlag ) || "1" .equals (injectionForceFlag );
165
+ }
163
166
default :
164
167
return false ;
165
168
}
@@ -285,8 +288,9 @@ static int parseJavaMajorVersion(String version) {
285
288
286
289
static boolean shouldAbortDueToOtherJavaAgents () {
287
290
// Simply considering having multiple agents
288
- if (getConfig (LIB_INJECTION_ENABLED_FLAG )
289
- && !getConfig (LIB_INJECTION_FORCE_FLAG )
291
+
292
+ if (getConfig (LIB_INJECTION_ENABLED_ENV_VAR )
293
+ && !getConfig (LIB_INJECTION_FORCE_SYS_PROP )
290
294
&& getAgentFilesFromVMArguments ().size () > 1 ) {
291
295
// Formatting agent file list, Java 7 style
292
296
StringBuilder agentFiles = new StringBuilder ();
@@ -305,7 +309,7 @@ && getAgentFilesFromVMArguments().size() > 1) {
305
309
"Info: multiple JVM agents detected, found "
306
310
+ agentFiles
307
311
+ ". Loading multiple APM/Tracing agent is not a recommended or supported configuration."
308
- + "Please set the DD_INJECT_FORCE configuration to TRUE to load Datadog APM/Tracing agent." );
312
+ + "Please set the environment variable DD_INJECT_FORCE or the system property dd.inject.force to TRUE to load Datadog APM/Tracing agent." );
309
313
return true ;
310
314
}
311
315
return false ;
0 commit comments