-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathDefaultDebuggerConfigUpdater.java
More file actions
96 lines (84 loc) · 2.91 KB
/
Copy pathDefaultDebuggerConfigUpdater.java
File metadata and controls
96 lines (84 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.datadog.debugger.agent;
import static datadog.trace.api.Config.isExplicitlyDisabled;
import datadog.environment.JavaVirtualMachine;
import datadog.trace.api.Config;
import datadog.trace.api.config.DebuggerConfig;
import datadog.trace.api.config.TraceInstrumentationConfig;
import datadog.trace.api.debugger.DebuggerConfigUpdate;
import datadog.trace.api.debugger.DebuggerConfigUpdater;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class DefaultDebuggerConfigUpdater implements DebuggerConfigUpdater {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDebuggerConfigUpdater.class);
private final Config config;
public DefaultDebuggerConfigUpdater(Config config) {
this.config = config;
}
@Override
public void updateConfig(DebuggerConfigUpdate update) {
startOrStopFeature(
config,
DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED,
update.getDynamicInstrumentationEnabled(),
DebuggerAgent::startDynamicInstrumentation,
DebuggerAgent::stopDynamicInstrumentation);
if (JavaVirtualMachine.isJavaVersionAtLeast(11)) {
// Cannot remotely enable Exception Replay for JDK < 11 (JVM 8 bug)
startOrStopFeature(
config,
DebuggerConfig.EXCEPTION_REPLAY_ENABLED,
update.getExceptionReplayEnabled(),
DebuggerAgent::startExceptionReplay,
DebuggerAgent::stopExceptionReplay);
} else {
LOGGER.debug("Cannot start Exception Replay on JDK version < 11");
}
startOrStopFeature(
config,
TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED,
update.getCodeOriginEnabled(),
DebuggerAgent::startCodeOriginForSpans,
DebuggerAgent::stopCodeOriginForSpans);
startOrStopFeature(
config,
DebuggerConfig.DISTRIBUTED_DEBUGGER_ENABLED,
update.getDistributedDebuggerEnabled(),
DebuggerAgent::startDistributedDebugger,
DebuggerAgent::stopDistributedDebugger);
}
@Override
public boolean isDynamicInstrumentationEnabled() {
return DebuggerAgent.dynamicInstrumentationEnabled.get();
}
@Override
public boolean isExceptionReplayEnabled() {
return DebuggerAgent.exceptionReplayEnabled.get();
}
@Override
public boolean isCodeOriginEnabled() {
return DebuggerAgent.codeOriginEnabled.get();
}
@Override
public boolean isDistributedDebuggerEnabled() {
return DebuggerAgent.distributedDebuggerEnabled.get();
}
private static void startOrStopFeature(
Config config,
String booleanKey,
Boolean currentStatus,
Consumer<Config> start,
Runnable stop) {
if (isExplicitlyDisabled(booleanKey)) {
LOGGER.debug("Feature {} is explicitly disabled", booleanKey);
return;
}
if (currentStatus != null) {
if (currentStatus) {
start.accept(config);
} else {
stop.run();
}
}
}
}