1010using System . Collections . ObjectModel ;
1111using System . Text ;
1212using System . Threading ;
13+ using System . Threading . Tasks ;
1314using Datadog . Trace . Configuration . ConfigurationSources ;
1415using Datadog . Trace . Configuration . Telemetry ;
16+ using Datadog . Trace . Debugger ;
17+ using Datadog . Trace . Debugger . Configurations ;
1518using Datadog . Trace . Logging ;
1619using Datadog . Trace . RemoteConfigurationManagement ;
1720using Datadog . Trace . Telemetry ;
21+ using Datadog . Trace . Vendors . Serilog . Events ;
1822
1923namespace 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 )
0 commit comments