Skip to content

Commit bfd542f

Browse files
[Debugger Default-On] DEBUG-3322 Debugger in-product enablement (#7366)
## Summary of changes This PR adds remote enablement support for debugger products. depends on #7441 ## Reason for change Currently, the only option to enable DI (for example) is by setting an environment variable. We want to give customers the ability to enable products on demand. ## Implementation details Gets RC events with new configuration and update the products based on defined rules. ## Test coverage All existing tests New system tests (DataDog/system-tests#4991) DebuggerManagerTests DebuggerManagerDynamicTests --------- Co-authored-by: Andrew Lock <[email protected]>
1 parent bad5402 commit bfd542f

File tree

42 files changed

+1370
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1370
-484
lines changed

tracer/src/Datadog.Trace.Trimming/build/Datadog.Trace.Trimming.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,6 @@
10391039
<type fullname="System.Threading.Monitor" />
10401040
<type fullname="System.Threading.Mutex" />
10411041
<type fullname="System.Threading.ReaderWriterLockSlim" />
1042-
<type fullname="System.Threading.SemaphoreFullException" />
10431042
<type fullname="System.Threading.SemaphoreSlim" />
10441043
<type fullname="System.Threading.SpinLock" />
10451044
<type fullname="System.Threading.SpinWait" />

tracer/src/Datadog.Trace/ClrProfiler/Instrumentation.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -496,26 +496,28 @@ private static void StartDiagnosticManager()
496496
private static void InitializeDebugger(TracerSettings tracerSettings)
497497
{
498498
var manager = DebuggerManager.Instance;
499-
if (manager.DebuggerSettings.CodeOriginForSpansEnabled
500-
|| manager.DebuggerSettings.DynamicInstrumentationEnabled
501-
|| manager.ExceptionReplaySettings.Enabled)
499+
var debuggerSettings = manager.DebuggerSettings;
500+
501+
if (!debuggerSettings.DynamicInstrumentationEnabled)
502502
{
503-
_ = Task.Run(
504-
async () =>
505-
{
506-
try
507-
{
508-
await DebuggerManager.Instance.UpdateConfiguration(tracerSettings).ConfigureAwait(false);
509-
}
510-
catch (Exception ex)
511-
{
512-
Log.Error(ex, "Error initializing debugger");
513-
}
514-
});
503+
// we need this line for tests
504+
Log.Information("Dynamic Instrumentation is disabled. To enable it, please set DD_DYNAMIC_INSTRUMENTATION_ENABLED environment variable to 'true'.");
505+
}
506+
507+
if (!debuggerSettings.DynamicInstrumentationEnabled
508+
&& !debuggerSettings.CodeOriginForSpansEnabled
509+
&& !manager.ExceptionReplaySettings.Enabled)
510+
{
511+
Log.Debug("Debugger products are not enabled");
515512
}
516513
else
517514
{
518-
Log.Information($"Dynamic Instrumentation is disabled. To enable it, please set {Datadog.Trace.Configuration.ConfigurationKeys.Debugger.DynamicInstrumentationEnabled} environment variable to 'true'.");
515+
_ = manager.UpdateConfiguration(tracerSettings)
516+
.ContinueWith(
517+
t => Log.Error(t?.Exception, "Error initializing debugger"),
518+
CancellationToken.None,
519+
TaskContinuationOptions.OnlyOnFaulted,
520+
TaskScheduler.Default);
519521
}
520522
}
521523

tracer/src/Datadog.Trace/Configuration/DynamicConfigurationManager.cs

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
using System.Collections.ObjectModel;
1111
using System.Text;
1212
using System.Threading;
13+
using System.Threading.Tasks;
1314
using Datadog.Trace.Configuration.ConfigurationSources;
1415
using Datadog.Trace.Configuration.Telemetry;
16+
using Datadog.Trace.Debugger;
17+
using Datadog.Trace.Debugger.Configurations;
1518
using Datadog.Trace.Logging;
1619
using Datadog.Trace.RemoteConfigurationManagement;
1720
using Datadog.Trace.Telemetry;
21+
using Datadog.Trace.Vendors.Serilog.Events;
1822

1923
namespace Datadog.Trace.Configuration
2024
{
@@ -41,12 +45,16 @@ public void Start()
4145
{
4246
_subscriptionManager.SubscribeToChanges(_subscription!);
4347

44-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingCustomTags, true); // 15
45-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingHttpHeaderTags, true); // 14
46-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingLogsInjection, true); // 13
47-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingSampleRate, true); // 12
48-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingTracingEnabled, true); // 19
49-
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingSampleRules, true); // 29
48+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingCustomTags, true); // 15
49+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingHttpHeaderTags, true); // 14
50+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingLogsInjection, true); // 13
51+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingSampleRate, true); // 12
52+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingTracingEnabled, true); // 19
53+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingSampleRules, true); // 29
54+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingEnabledDynamicInstrumentation, true); // 38
55+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingEnableExceptionReplay, true); // 39
56+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingEnableCodeOrigin, true); // 40
57+
_subscriptionManager.SetCapability(RcmCapabilitiesIndices.ApmTracingEnableLiveDebugging, true); // 41
5058
}
5159
}
5260

@@ -91,27 +99,60 @@ private static void OnConfigurationChanged(ConfigurationBuilder settings)
9199
// Needs to be done before returning, to feed the value to the telemetry
92100
// var debugLogsEnabled = settings.WithKeys(ConfigurationKeys.DebugEnabled).AsBool();
93101

102+
TracerSettings newSettings;
94103
if (dynamicSettings.Equals(oldSettings.DynamicSettings))
95104
{
96105
Log.Debug("No changes detected in the new dynamic configuration");
97-
return;
106+
newSettings = oldSettings;
98107
}
108+
else
109+
{
110+
Log.Information("Applying new dynamic configuration");
111+
112+
newSettings = oldSettings with { DynamicSettings = dynamicSettings };
113+
114+
/*
115+
if (debugLogsEnabled != null && debugLogsEnabled.Value != GlobalSettings.Instance.DebugEnabled)
116+
{
117+
GlobalSettings.SetDebugEnabled(debugLogsEnabled.Value);
118+
Security.Instance.SetDebugEnabled(debugLogsEnabled.Value);
99119
100-
Log.Information("Applying new dynamic configuration");
120+
NativeMethods.UpdateSettings(new[] { ConfigurationKeys.DebugEnabled }, new[] { debugLogsEnabled.Value ? "1" : "0" });
121+
}
122+
*/
101123

102-
var newSettings = oldSettings with { DynamicSettings = dynamicSettings };
124+
Tracer.Configure(newSettings);
125+
}
103126

104-
/*
105-
if (debugLogsEnabled != null && debugLogsEnabled.Value != GlobalSettings.Instance.DebugEnabled)
127+
var dynamicDebuggerSettings = new ImmutableDynamicDebuggerSettings
106128
{
107-
GlobalSettings.SetDebugEnabled(debugLogsEnabled.Value);
108-
Security.Instance.SetDebugEnabled(debugLogsEnabled.Value);
129+
DynamicInstrumentationEnabled = settings.WithKeys(ConfigurationKeys.Debugger.DynamicInstrumentationEnabled).AsBool(),
130+
ExceptionReplayEnabled = settings.WithKeys(ConfigurationKeys.Debugger.ExceptionReplayEnabled).AsBool(),
131+
CodeOriginEnabled = settings.WithKeys(ConfigurationKeys.Debugger.CodeOriginForSpansEnabled).AsBool(),
132+
};
109133

110-
NativeMethods.UpdateSettings(new[] { ConfigurationKeys.DebugEnabled }, new[] { debugLogsEnabled.Value ? "1" : "0" });
134+
var oldDebuggerSettings = DebuggerManager.Instance.DebuggerSettings;
135+
136+
if (dynamicDebuggerSettings.Equals(oldDebuggerSettings.DynamicSettings))
137+
{
138+
Log.Debug("No changes detected in the new dynamic debugger configuration");
139+
return;
111140
}
112-
*/
113141

114-
Tracer.Configure(newSettings);
142+
Log.Information("Applying new dynamic debugger configuration");
143+
if (Log.IsEnabled(LogEventLevel.Debug))
144+
{
145+
Log.Debug(
146+
"DynamicInstrumentationEnabled={DynamicInstrumentationEnabled}, ExceptionReplayEnabled={ExceptionReplayEnabled}, CodeOriginEnabled={CodeOriginEnabled}",
147+
dynamicDebuggerSettings.DynamicInstrumentationEnabled,
148+
dynamicDebuggerSettings.ExceptionReplayEnabled,
149+
dynamicDebuggerSettings.CodeOriginEnabled);
150+
}
151+
152+
var newDebuggerSettings = oldDebuggerSettings with { DynamicSettings = dynamicDebuggerSettings };
153+
154+
DebuggerManager.Instance.UpdateConfiguration(newSettings, newDebuggerSettings)
155+
.ContinueWith(t => Log.Error(t?.Exception, "Error updating dynamic configuration for debugger"), TaskContinuationOptions.OnlyOnFaulted);
115156
}
116157

117158
private ApplyDetails[] ConfigurationUpdated(Dictionary<string, List<RemoteConfiguration>> configByProduct, Dictionary<string, List<RemoteConfigurationPath>>? removedConfigByProduct)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// <copyright file="ImmutableDynamicDebuggerSettings.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
#nullable enable
7+
8+
namespace Datadog.Trace.Debugger.Configurations
9+
{
10+
internal record ImmutableDynamicDebuggerSettings
11+
{
12+
public bool? DynamicInstrumentationEnabled { get; init; }
13+
14+
public bool? ExceptionReplayEnabled { get; init; }
15+
16+
public bool? CodeOriginEnabled { get; init; }
17+
}
18+
}

0 commit comments

Comments
 (0)