Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.bootstrap;

import static datadog.trace.bootstrap.SystemUtils.getPropertyOrEnvVar;
import static java.nio.charset.StandardCharsets.UTF_8;

import datadog.cli.CLIHelper;
Expand Down Expand Up @@ -45,7 +46,7 @@
*/
public final class AgentBootstrap {
static final String LIB_INJECTION_ENABLED_FLAG = "DD_INJECTION_ENABLED";
static final String LIB_INJECTION_FORCE_FLAG = "DD_INJECT_FORCE";
static final String LIB_INJECTION_FORCE_FLAG = "dd.inject.force";
Copy link
Copy Markdown
Contributor

@dougqh dougqh Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this property and the other env var?
Both being labeled as flags, but being different name types is a bit confusing.

e.g. LIB_INJECTION_ENABLED_ENV_AR & LIB_INJECTION_FORCE_PROPERTY


private static final Class<?> thisClass = AgentBootstrap.class;
private static final int MAX_EXCEPTION_CHAIN_LENGTH = 99;
Expand Down Expand Up @@ -158,8 +159,10 @@ static boolean getConfig(String configName) {
case LIB_INJECTION_ENABLED_FLAG:
return System.getenv(LIB_INJECTION_ENABLED_FLAG) != null;
case LIB_INJECTION_FORCE_FLAG:
String libInjectionForceFlag = System.getenv(LIB_INJECTION_FORCE_FLAG);
return "true".equalsIgnoreCase(libInjectionForceFlag) || "1".equals(libInjectionForceFlag);
{
String injectionForceFlag = getPropertyOrEnvVar(LIB_INJECTION_FORCE_FLAG);
return "true".equalsIgnoreCase(injectionForceFlag) || "1".equals(injectionForceFlag);
}
default:
return false;
}
Expand Down Expand Up @@ -285,6 +288,7 @@ static int parseJavaMajorVersion(String version) {

static boolean shouldAbortDueToOtherJavaAgents() {
// Simply considering having multiple agents

if (getConfig(LIB_INJECTION_ENABLED_FLAG)
&& !getConfig(LIB_INJECTION_FORCE_FLAG)
&& getAgentFilesFromVMArguments().size() > 1) {
Expand All @@ -305,7 +309,7 @@ && getAgentFilesFromVMArguments().size() > 1) {
"Info: multiple JVM agents detected, found "
+ agentFiles
+ ". Loading multiple APM/Tracing agent is not a recommended or supported configuration."
+ "Please set the DD_INJECT_FORCE configuration to TRUE to load Datadog APM/Tracing agent.");
+ "Please set the environment variable DD_INJECT_FORCE or the system property dd.inject.force to TRUE to load Datadog APM/Tracing agent.");
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ public static String getPropertyOrDefault(String property, String defaultValue)
return defaultValue;
}
}

private static String toEnvVar(String string) {
return string.replace('.', '_').replace('-', '_').toUpperCase();
}

public static String getPropertyOrEnvVar(String property) {
String envVarValue = System.getenv(toEnvVar(property));
if (envVarValue != null) {
return envVarValue;
}
return System.getProperty(property);
}
}
Loading