11package datadog .trace .bootstrap ;
22
3+ import static datadog .trace .bootstrap .SystemUtils .getPropertyOrEnvVar ;
34import static java .nio .charset .StandardCharsets .UTF_8 ;
45
56import datadog .cli .CLIHelper ;
4445 * </ul>
4546 */
4647public 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 " ;
4950
5051 private static final Class <?> thisClass = AgentBootstrap .class ;
5152 private static final int MAX_EXCEPTION_CHAIN_LENGTH = 99 ;
@@ -155,11 +156,13 @@ private static void agentmainImpl(
155156
156157 static boolean getConfig (String configName ) {
157158 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+ }
163166 default :
164167 return false ;
165168 }
@@ -285,8 +288,9 @@ static int parseJavaMajorVersion(String version) {
285288
286289 static boolean shouldAbortDueToOtherJavaAgents () {
287290 // 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 )
290294 && getAgentFilesFromVMArguments ().size () > 1 ) {
291295 // Formatting agent file list, Java 7 style
292296 StringBuilder agentFiles = new StringBuilder ();
@@ -305,7 +309,7 @@ && getAgentFilesFromVMArguments().size() > 1) {
305309 "Info: multiple JVM agents detected, found "
306310 + agentFiles
307311 + ". 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." );
309313 return true ;
310314 }
311315 return false ;
0 commit comments