Skip to content

Commit b8f5fb8

Browse files
authored
Fix Agent so it looks up feature enablement from StableConfig using config keys (#8450)
The premain Agent class was looking up config values using system property names prefixed with `dd.` whereas `StableConfigSource` was expecting internal property names without that prefix.
1 parent cb1d8ed commit b8f5fb8

File tree

1 file changed

+43
-40
lines changed
  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap

1 file changed

+43
-40
lines changed

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

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -83,43 +83,39 @@ public class Agent {
8383
private static final Logger log;
8484

8585
private enum AgentFeature {
86-
TRACING(propertyNameToSystemPropertyName(TraceInstrumentationConfig.TRACE_ENABLED), true),
87-
JMXFETCH(propertyNameToSystemPropertyName(JmxFetchConfig.JMX_FETCH_ENABLED), true),
88-
STARTUP_LOGS(
89-
propertyNameToSystemPropertyName(GeneralConfig.STARTUP_LOGS_ENABLED),
90-
DEFAULT_STARTUP_LOGS_ENABLED),
91-
PROFILING(propertyNameToSystemPropertyName(ProfilingConfig.PROFILING_ENABLED), false),
92-
APPSEC(propertyNameToSystemPropertyName(AppSecConfig.APPSEC_ENABLED), false),
93-
IAST(propertyNameToSystemPropertyName(IastConfig.IAST_ENABLED), false),
94-
REMOTE_CONFIG(
95-
propertyNameToSystemPropertyName(RemoteConfigConfig.REMOTE_CONFIGURATION_ENABLED), true),
96-
DEPRECATED_REMOTE_CONFIG(
97-
propertyNameToSystemPropertyName(RemoteConfigConfig.REMOTE_CONFIG_ENABLED), true),
98-
CWS(propertyNameToSystemPropertyName(CwsConfig.CWS_ENABLED), false),
99-
CIVISIBILITY(propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED), false),
100-
CIVISIBILITY_AGENTLESS(
101-
propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED), false),
102-
USM(propertyNameToSystemPropertyName(UsmConfig.USM_ENABLED), false),
103-
TELEMETRY(propertyNameToSystemPropertyName(GeneralConfig.TELEMETRY_ENABLED), true),
104-
DEBUGGER(
105-
propertyNameToSystemPropertyName(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED), false),
106-
EXCEPTION_DEBUGGING(
107-
propertyNameToSystemPropertyName(DebuggerConfig.EXCEPTION_REPLAY_ENABLED), false),
108-
SPAN_ORIGIN(
109-
propertyNameToSystemPropertyName(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED),
110-
false),
111-
DATA_JOBS(propertyNameToSystemPropertyName(GeneralConfig.DATA_JOBS_ENABLED), false),
112-
AGENTLESS_LOG_SUBMISSION(
113-
propertyNameToSystemPropertyName(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED), false);
114-
86+
TRACING(TraceInstrumentationConfig.TRACE_ENABLED, true),
87+
JMXFETCH(JmxFetchConfig.JMX_FETCH_ENABLED, true),
88+
STARTUP_LOGS(GeneralConfig.STARTUP_LOGS_ENABLED, DEFAULT_STARTUP_LOGS_ENABLED),
89+
PROFILING(ProfilingConfig.PROFILING_ENABLED, false),
90+
APPSEC(AppSecConfig.APPSEC_ENABLED, false),
91+
IAST(IastConfig.IAST_ENABLED, false),
92+
REMOTE_CONFIG(RemoteConfigConfig.REMOTE_CONFIGURATION_ENABLED, true),
93+
DEPRECATED_REMOTE_CONFIG(RemoteConfigConfig.REMOTE_CONFIG_ENABLED, true),
94+
CWS(CwsConfig.CWS_ENABLED, false),
95+
CIVISIBILITY(CiVisibilityConfig.CIVISIBILITY_ENABLED, false),
96+
CIVISIBILITY_AGENTLESS(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED, false),
97+
USM(UsmConfig.USM_ENABLED, false),
98+
TELEMETRY(GeneralConfig.TELEMETRY_ENABLED, true),
99+
DEBUGGER(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED, false),
100+
EXCEPTION_DEBUGGING(DebuggerConfig.EXCEPTION_REPLAY_ENABLED, false),
101+
SPAN_ORIGIN(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED, false),
102+
DATA_JOBS(GeneralConfig.DATA_JOBS_ENABLED, false),
103+
AGENTLESS_LOG_SUBMISSION(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED, false);
104+
105+
private final String configKey;
115106
private final String systemProp;
116107
private final boolean enabledByDefault;
117108

118-
AgentFeature(final String systemProp, final boolean enabledByDefault) {
119-
this.systemProp = systemProp;
109+
AgentFeature(final String configKey, final boolean enabledByDefault) {
110+
this.configKey = configKey;
111+
this.systemProp = propertyNameToSystemPropertyName(configKey);
120112
this.enabledByDefault = enabledByDefault;
121113
}
122114

115+
public String getConfigKey() {
116+
return configKey;
117+
}
118+
123119
public String getSystemProp() {
124120
return systemProp;
125121
}
@@ -1213,16 +1209,17 @@ private static boolean isDebugMode() {
12131209
/** @return {@code true} if the agent feature is enabled */
12141210
private static boolean isFeatureEnabled(AgentFeature feature) {
12151211
// must be kept in sync with logic from Config!
1216-
final String featureEnabledSysprop = feature.getSystemProp();
1217-
String featureEnabled = System.getProperty(featureEnabledSysprop);
1212+
final String featureConfigKey = feature.getConfigKey();
1213+
final String featureSystemProp = feature.getSystemProp();
1214+
String featureEnabled = System.getProperty(featureSystemProp);
12181215
if (featureEnabled == null) {
1219-
featureEnabled = getStableConfig(StableConfigSource.MANAGED, featureEnabledSysprop);
1216+
featureEnabled = getStableConfig(StableConfigSource.MANAGED, featureConfigKey);
12201217
}
12211218
if (featureEnabled == null) {
1222-
featureEnabled = ddGetEnv(featureEnabledSysprop);
1219+
featureEnabled = ddGetEnv(featureSystemProp);
12231220
}
12241221
if (featureEnabled == null) {
1225-
featureEnabled = getStableConfig(StableConfigSource.USER, featureEnabledSysprop);
1222+
featureEnabled = getStableConfig(StableConfigSource.USER, featureConfigKey);
12261223
}
12271224

12281225
if (feature.isEnabledByDefault()) {
@@ -1242,11 +1239,17 @@ private static boolean isFeatureEnabled(AgentFeature feature) {
12421239
/** @see datadog.trace.api.ProductActivation#fromString(String) */
12431240
private static boolean isFullyDisabled(final AgentFeature feature) {
12441241
// must be kept in sync with logic from Config!
1245-
final String featureEnabledSysprop = feature.systemProp;
1246-
String settingValue = getNullIfEmpty(System.getProperty(featureEnabledSysprop));
1242+
final String featureConfigKey = feature.getConfigKey();
1243+
final String featureSystemProp = feature.getSystemProp();
1244+
String settingValue = getNullIfEmpty(System.getProperty(featureSystemProp));
1245+
if (settingValue == null) {
1246+
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.MANAGED, featureConfigKey));
1247+
}
1248+
if (settingValue == null) {
1249+
settingValue = getNullIfEmpty(ddGetEnv(featureSystemProp));
1250+
}
12471251
if (settingValue == null) {
1248-
settingValue = getNullIfEmpty(ddGetEnv(featureEnabledSysprop));
1249-
settingValue = settingValue != null && settingValue.isEmpty() ? null : settingValue;
1252+
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.USER, featureConfigKey));
12501253
}
12511254

12521255
// defaults to inactive

0 commit comments

Comments
 (0)