Skip to content

Commit 40f624d

Browse files
authored
Log a warning when profiling enablement is misconfigured. (#7511)
1 parent 8ca1278 commit 40f624d

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

dd-java-agent/instrumentation/graal/native-image/src/main/java/datadog/trace/instrumentation/graal/nativeimage/NativeImageGeneratorRunnerInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String[
8181
+ "datadog.trace.api.MethodFilterConfigParser:build_time,"
8282
+ "datadog.trace.api.WithGlobalTracer:build_time,"
8383
+ "datadog.trace.api.PropagationStyle:build_time,"
84+
+ "datadog.trace.api.profiling.ProfilingEnablement:build_time,"
8485
+ "datadog.trace.bootstrap.config.provider.ConfigConverter:build_time,"
8586
+ "datadog.trace.bootstrap.config.provider.ConfigProvider:build_time,"
8687
+ "datadog.trace.bootstrap.config.provider.ConfigProvider$Singleton:build_time,"

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,11 +1522,14 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
15221522
// the profiler was enabled at build time or not.
15231523
// Otherwise just do the standard config lookup by key.
15241524
// An extra step is needed to properly handle the 'auto' value for profiling enablement via SSI.
1525-
profilingEnabled =
1526-
ProfilingEnablement.of(
1527-
configProvider.getString(
1528-
ProfilingConfig.PROFILING_ENABLED,
1529-
String.valueOf(instrumenterConfig.isProfilingEnabled())));
1525+
String value =
1526+
configProvider.getString(
1527+
ProfilingConfig.PROFILING_ENABLED,
1528+
String.valueOf(instrumenterConfig.isProfilingEnabled()));
1529+
// Run a validator that will emit a warning if the value is not a valid ProfilingEnablement
1530+
// We don't want it to run in each call to ProfilingEnablement.of(value) not to flood the logs
1531+
ProfilingEnablement.validate(value);
1532+
profilingEnabled = ProfilingEnablement.of(value);
15301533
profilingAgentless =
15311534
configProvider.getBoolean(PROFILING_AGENTLESS, PROFILING_AGENTLESS_DEFAULT);
15321535
isDatadogProfilerEnabled =

internal-api/src/main/java/datadog/trace/api/profiling/ProfilingEnablement.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package datadog.trace.api.profiling;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
36
public enum ProfilingEnablement {
47
ENABLED(true),
58
DISABLED(false),
69
AUTO(true);
710

11+
private static final Logger logger = LoggerFactory.getLogger(Profiling.class);
12+
813
private final boolean active;
914

1015
ProfilingEnablement(boolean active) {
@@ -29,4 +34,24 @@ public static ProfilingEnablement of(String value) {
2934
return DISABLED;
3035
}
3136
}
37+
38+
public static void validate(String value) {
39+
if (value == null) {
40+
return;
41+
}
42+
switch (value.toLowerCase()) {
43+
case "false":
44+
case "true":
45+
case "auto":
46+
return;
47+
// values 1 and 0 are accepted for backwards compatibility
48+
case "1":
49+
case "0":
50+
return;
51+
default:
52+
logger.warn(
53+
"Invalid value for 'dd.profiling.enabled' (DD_PROFILING_ENABLED) detected: {}. Valid values are 'true', 'false' and 'auto'.",
54+
value);
55+
}
56+
}
3257
}

0 commit comments

Comments
 (0)