Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -70,6 +70,7 @@ public class DebuggerAgent {
static final AtomicBoolean exceptionReplayEnabled = new AtomicBoolean();
static final AtomicBoolean codeOriginEnabled = new AtomicBoolean();
static final AtomicBoolean distributedDebuggerEnabled = new AtomicBoolean();
static final AtomicBoolean symDBEnabled = new AtomicBoolean();
private static ClassesToRetransformFinder classesToRetransformFinder;

public static synchronized void run(
Expand All @@ -89,10 +90,14 @@ public static synchronized void run(
if (config.isDynamicInstrumentationEnabled()) {
startDynamicInstrumentation(config);
startCodeOriginForSpans(config);
startSymbolDatabase(config);
if (config.getDynamicInstrumentationInstrumentTheWorld() != null) {
setupInstrumentTheWorldTransformer(config, instrumentation, sink);
}
}
if (config.isSymbolDatabaseEnabled()) {
startSymbolDatabase(config);
}
try {
/*
Note: shutdown hooks are tricky because JVM holds reference for them forever preventing
Expand Down Expand Up @@ -165,24 +170,7 @@ public static void startDynamicInstrumentation(Config config) {
return;
}
if (configurationPoller != null) {
if (config.isSymbolDatabaseEnabled()) {
initClassNameFilter();
List<ScopeFilter> scopeFilters =
Arrays.asList(new AvroFilter(), new ProtoFilter(), new WireFilter());
SymbolAggregator symbolAggregator =
new SymbolAggregator(
classNameFilter,
scopeFilters,
sink.getSymbolSink(),
config.getSymbolDatabaseFlushThreshold());
symbolAggregator.start();
symDBEnablement =
new SymDBEnablement(instrumentation, config, symbolAggregator, classNameFilter);
if (config.isSymbolDatabaseForceUpload()) {
symDBEnablement.startSymbolExtraction();
}
}
subscribeConfigurationPoller(config, configurationUpdater, symDBEnablement);
subscribeLiveDebugging(config, configurationUpdater);
} else {
LOGGER.debug("No configuration poller available from SharedCommunicationObjects");
}
Expand All @@ -205,6 +193,62 @@ public static void stopDynamicInstrumentation() {
}
}

private static void subscribeLiveDebugging(
Config config, ConfigurationUpdater configurationUpdater) {
LOGGER.debug("Subscribing to Live Debugging...");
configurationPoller.addListener(
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed here with the other listener added down below?

Product.LIVE_DEBUGGING, new DebuggerProductChangesListener(config, configurationUpdater));
}

public static void startSymbolDatabase(Config config) {
if (!symDBEnabled.compareAndSet(false, true)) {
return;
}
LOGGER.debug("Starting Symbol Database");
commonInit(config);
initClassNameFilter();
List<ScopeFilter> scopeFilters =
Arrays.asList(new AvroFilter(), new ProtoFilter(), new WireFilter());
SymbolAggregator symbolAggregator =
new SymbolAggregator(
classNameFilter,
scopeFilters,
sink.getSymbolSink(),
config.getSymbolDatabaseFlushThreshold());
symbolAggregator.start();
symDBEnablement =
new SymDBEnablement(instrumentation, config, symbolAggregator, classNameFilter);
if (config.isSymbolDatabaseForceUpload()) {
symDBEnablement.startSymbolExtraction();
}
subscribeSymDB(symDBEnablement);
LOGGER.debug("Started Symbol Database");
}

private static void subscribeSymDB(SymDBEnablement symDBEnablement) {
LOGGER.debug("Subscribing to Symbol DB...");
if (configurationPoller != null) {
configurationPoller.addListener(Product.LIVE_DEBUGGING_SYMBOL_DB, symDBEnablement);
} else {
LOGGER.debug("No configuration poller available from SharedCommunicationObjects");
}
}

public static void stopSymbolDatabase() {
if (!symDBEnabled.compareAndSet(true, false)) {
return;
}
LOGGER.info("Stopping Symbol Database");
if (configurationPoller != null) {
configurationPoller.removeListeners(Product.LIVE_DEBUGGING_SYMBOL_DB);
}
SymDBEnablement localSymDBEnablement = symDBEnablement;
if (localSymDBEnablement != null) {
localSymDBEnablement.stopSymbolExtraction();
symDBEnablement = null;
}
}

public static void startExceptionReplay(Config config) {
if (!exceptionReplayEnabled.compareAndSet(false, true)) {
return;
Expand Down Expand Up @@ -369,17 +413,6 @@ private static void setupSourceFileTracking(
instrumentation.addTransformer(sourceFileTrackingTransformer);
}

private static void subscribeConfigurationPoller(
Config config, ConfigurationUpdater configurationUpdater, SymDBEnablement symDBEnablement) {
LOGGER.debug("Subscribing to Live Debugging...");
configurationPoller.addListener(
Product.LIVE_DEBUGGING, new DebuggerProductChangesListener(config, configurationUpdater));
if (symDBEnablement != null && !config.isSymbolDatabaseForceUpload()) {
LOGGER.debug("Subscribing to Symbol DB...");
configurationPoller.addListener(Product.LIVE_DEBUGGING_SYMBOL_DB, symDBEnablement);
}
}

private static void unsubscribeConfigurationPoller() {
if (configurationPoller != null) {
configurationPoller.removeListeners(Product.LIVE_DEBUGGING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import datadog.communication.ddagent.DDAgentFeaturesDiscovery;
import datadog.communication.ddagent.SharedCommunicationObjects;
import datadog.remoteconfig.ConfigurationPoller;
import datadog.trace.api.Config;
import datadog.trace.api.debugger.DebuggerConfigUpdate;
import java.lang.instrument.Instrumentation;
Expand All @@ -17,6 +18,7 @@ class DefaultDebuggerConfigUpdaterTest {
@Test
public void enableDisable() {
SharedCommunicationObjects sco = mock(SharedCommunicationObjects.class);
when(sco.configurationPoller(null)).thenReturn(mock(ConfigurationPoller.class));
when(sco.featuresDiscovery(any())).thenReturn(mock(DDAgentFeaturesDiscovery.class));
DebuggerAgent.run(Config.get(), mock(Instrumentation.class), sco);
DefaultDebuggerConfigUpdater productConfigUpdater =
Expand Down