Skip to content

Commit 015d218

Browse files
authored
[Dynamic Instrumentation] DEBUG-3514 Refactor debugger code (#7304)
## Summary of changes Refactoring of all debugger related code to reflect the current debugger suite and as a pre work for in product enablement. ## Test coverage All existing tests
1 parent 82d3351 commit 015d218

File tree

68 files changed

+1285
-742
lines changed

Some content is hidden

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

68 files changed

+1285
-742
lines changed

tracer/missing-nullability-files.csv

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ src/Datadog.Trace/ContinuousProfiler/ProfilerStatus.cs
103103
src/Datadog.Trace/DatabaseMonitoring/MultiPartIdentifier.cs
104104
src/Datadog.Trace/DatabaseMonitoring/VendoredSqlHelpers.cs
105105
src/Datadog.Trace/DataStreamsMonitoring/CheckpointKind.cs
106-
src/Datadog.Trace/Debugger/ILineProbeResolver.cs
107-
src/Datadog.Trace/Debugger/LiveDebugger.cs
108-
src/Datadog.Trace/Debugger/ProbeLocationType.cs
109106
src/Datadog.Trace/DiagnosticListeners/AspNetCoreDiagnosticObserver.cs
110107
src/Datadog.Trace/DiagnosticListeners/DiagnosticManager.cs
111108
src/Datadog.Trace/DiagnosticListeners/DiagnosticObserver.cs

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@
10361036
<type fullname="System.Threading.Monitor" />
10371037
<type fullname="System.Threading.Mutex" />
10381038
<type fullname="System.Threading.ReaderWriterLockSlim" />
1039+
<type fullname="System.Threading.SemaphoreFullException" />
10391040
<type fullname="System.Threading.SemaphoreSlim" />
10401041
<type fullname="System.Threading.SpinLock" />
10411042
<type fullname="System.Threading.SpinWait" />

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -408,39 +408,13 @@ private static void InitializeTracer(Stopwatch sw)
408408
{
409409
try
410410
{
411-
DynamicInstrumentationHelper.ServiceName = TraceUtil.NormalizeTag(tracer.Settings.ServiceName ?? tracer.DefaultServiceName);
412-
}
413-
catch (Exception e)
414-
{
415-
DynamicInstrumentationHelper.ServiceName = tracer.DefaultServiceName;
416-
Log.Error(e, "Could not set `DynamicInstrumentationHelper.ServiceName`.");
417-
}
418-
419-
try
420-
{
421-
InitLiveDebugger(tracer);
411+
InitializeDebugger(tracer.Settings);
422412
}
423413
catch (Exception e)
424414
{
425415
Log.Error(e, "Failed to initialize Remote Configuration Management.");
426416
}
427417

428-
try
429-
{
430-
if (ExceptionDebugging.Enabled)
431-
{
432-
ExceptionDebugging.Initialize();
433-
}
434-
else
435-
{
436-
Log.Information("Exception Replay is disabled. To enable it, please set DD_EXCEPTION_REPLAY_ENABLED environment variable to '1'/'true'.");
437-
}
438-
}
439-
catch (Exception ex)
440-
{
441-
Log.Error(ex, "Error initializing Exception Debugging");
442-
}
443-
444418
// RCM isn't _actually_ initialized at this point, as we do it in the background, so we record that separately
445419
sw.Restart();
446420

@@ -490,51 +464,18 @@ private static void StartDiagnosticManager()
490464
}
491465
#endif
492466

493-
private static void InitLiveDebugger(Tracer tracer)
467+
private static void InitializeDebugger(TracerSettings tracerSettings)
494468
{
495-
var settings = tracer.Settings;
496-
var debuggerSettings = DebuggerSettings.FromDefaultSource();
497-
498-
if (!settings.IsRemoteConfigurationAvailable)
499-
{
500-
// live debugger requires RCM, so there's no point trying to initialize it if RCM is not available
501-
if (debuggerSettings.Enabled)
502-
{
503-
Log.Warning("Live Debugger is enabled but remote configuration is not available in this environment, so live debugger cannot be enabled.");
504-
}
505-
506-
tracer.TracerManager.Telemetry.ProductChanged(TelemetryProductType.DynamicInstrumentation, enabled: false, error: null);
507-
return;
508-
}
509-
510-
// Service Name must be lowercase, otherwise the agent will not be able to find the service
511-
var serviceName = DynamicInstrumentationHelper.ServiceName;
512-
var discoveryService = tracer.TracerManager.DiscoveryService;
513-
514-
Task.Run(
469+
_ = Task.Run(
515470
async () =>
516471
{
517-
// TODO: LiveDebugger should be initialized in TracerManagerFactory so it can respond
518-
// to changes in ExporterSettings etc.
519-
520472
try
521473
{
522-
var sw = Stopwatch.StartNew();
523-
var isDiscoverySuccessful = await WaitForDiscoveryService(discoveryService).ConfigureAwait(false);
524-
TelemetryFactory.Metrics.RecordDistributionSharedInitTime(MetricTags.InitializationComponent.DiscoveryService, sw.ElapsedMilliseconds);
525-
526-
if (isDiscoverySuccessful)
527-
{
528-
var liveDebugger = LiveDebuggerFactory.Create(discoveryService, RcmSubscriptionManager.Instance, settings, serviceName, tracer.TracerManager.Telemetry, debuggerSettings, tracer.TracerManager.GitMetadataTagsProvider);
529-
530-
Log.Debug("Initializing live debugger.");
531-
532-
await InitializeLiveDebugger(liveDebugger).ConfigureAwait(false);
533-
}
474+
await DebuggerManager.Instance.UpdateConfiguration(tracerSettings).ConfigureAwait(false);
534475
}
535476
catch (Exception ex)
536477
{
537-
Log.Error(ex, "Error initializing live debugger.");
478+
Log.Error(ex, "Error initializing debugger");
538479
}
539480
});
540481
}
@@ -557,21 +498,6 @@ void Callback(AgentConfiguration x)
557498
}
558499
}
559500

560-
internal static async Task InitializeLiveDebugger(LiveDebugger liveDebugger)
561-
{
562-
var sw = Stopwatch.StartNew();
563-
try
564-
{
565-
await liveDebugger.InitializeAsync().ConfigureAwait(false);
566-
}
567-
catch (Exception ex)
568-
{
569-
Log.Error(ex, "Failed to initialize Live Debugger");
570-
}
571-
572-
TelemetryFactory.Metrics.RecordDistributionSharedInitTime(MetricTags.InitializationComponent.DynamicInstrumentation, sw.ElapsedMilliseconds);
573-
}
574-
575501
internal static void EnableTracerInstrumentations(InstrumentationCategory categories, Stopwatch sw = null)
576502
{
577503
var defs = NativeMethods.EnableCallTargetDefinitions((uint)categories);

tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.Debugger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ internal static partial class ConfigurationKeys
1414
internal static class Debugger
1515
{
1616
/// <summary>
17-
/// Configuration key for enabling or disabling Live Debugger.
17+
/// Configuration key for enabling or disabling Dynamic Instrumentation.
1818
/// Default value is false (disabled).
1919
/// </summary>
20-
/// <seealso cref="DebuggerSettings.Enabled"/>
21-
public const string Enabled = "DD_DYNAMIC_INSTRUMENTATION_ENABLED";
20+
/// <seealso cref="DebuggerSettings.DynamicInstrumentationEnabled"/>
21+
public const string DynamicInstrumentationEnabled = "DD_DYNAMIC_INSTRUMENTATION_ENABLED";
2222

2323
/// <summary>
2424
/// Configuration key for the max object depth to serialize for probe snapshots.

tracer/src/Datadog.Trace/Debugger/Configurations/ConfigurationUpdater.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ bool IsEnvAndVersionMatch(ProbeDefinition probe)
124124

125125
private void HandleAddedProbesChanges(ProbeConfigurationComparer comparer)
126126
{
127-
LiveDebugger.Instance.UpdateAddedProbeInstrumentations(comparer.AddedDefinitions);
127+
DebuggerManager.Instance.DynamicInstrumentation?.UpdateAddedProbeInstrumentations(comparer.AddedDefinitions);
128128
}
129129

130130
private void HandleRemovedProbesChanges(string[] removedProbesIds)
131131
{
132-
LiveDebugger.Instance.UpdateRemovedProbeInstrumentations(removedProbesIds);
132+
DebuggerManager.Instance.DynamicInstrumentation?.UpdateRemovedProbeInstrumentations(removedProbesIds);
133133
}
134134

135135
private void HandleRateLimitChanged(ProbeConfigurationComparer comparer)

tracer/src/Datadog.Trace/Debugger/Configurations/Models/FilterList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override bool Equals(object obj)
4141
return true;
4242
}
4343

44-
if (obj.GetType() != this.GetType())
44+
if (obj.GetType() != GetType())
4545
{
4646
return false;
4747
}

tracer/src/Datadog.Trace/Debugger/Configurations/Models/LogProbe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override bool Equals(object? obj)
5050
return true;
5151
}
5252

53-
if (obj.GetType() != this.GetType())
53+
if (obj.GetType() != GetType())
5454
{
5555
return false;
5656
}

tracer/src/Datadog.Trace/Debugger/Configurations/Models/MetricProbe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override bool Equals(object obj)
4242
return true;
4343
}
4444

45-
if (obj.GetType() != this.GetType())
45+
if (obj.GetType() != GetType())
4646
{
4747
return false;
4848
}

tracer/src/Datadog.Trace/Debugger/Configurations/Models/ProbeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override bool Equals(object obj)
5656
return true;
5757
}
5858

59-
if (obj.GetType() != this.GetType())
59+
if (obj.GetType() != GetType())
6060
{
6161
return false;
6262
}

0 commit comments

Comments
 (0)