|  | 
| 13 | 13 | using System.Threading; | 
| 14 | 14 | using System.Threading.Tasks; | 
| 15 | 15 | using Datadog.Trace.Configuration.ConfigurationSources; | 
| 16 |  | -using Datadog.Trace.Configuration.ConfigurationSources.Telemetry; | 
| 17 | 16 | using Datadog.Trace.Configuration.Telemetry; | 
| 18 | 17 | using Datadog.Trace.Debugger; | 
| 19 | 18 | using Datadog.Trace.Debugger.Configurations; | 
| @@ -74,72 +73,16 @@ internal static void OnlyForTests_ApplyConfiguration(IConfigurationSource dynami | 
| 74 | 73 | 
 | 
| 75 | 74 |         private static void OnConfigurationChanged(IConfigurationSource dynamicConfig) | 
| 76 | 75 |         { | 
| 77 |  | -            var tracerSettings = Tracer.Instance.Settings; | 
| 78 |  | -            var manualSource = GlobalConfigurationSource.ManualConfigurationSource; | 
| 79 |  | -            var mutableSettings = manualSource.UseDefaultSources | 
| 80 |  | -                                      ? tracerSettings.InitialMutableSettings | 
| 81 |  | -                                      : MutableSettings.CreateWithoutDefaultSources(tracerSettings); | 
|  | 76 | +            var manualConfig = GlobalConfigurationSource.ManualConfigurationSource; | 
| 82 | 77 | 
 | 
| 83 | 78 |             // We save this immediately, even if there's no manifest changes in the final settings | 
|  | 79 | +            // so that it can be picked up by other configuration updaters, e.g. config in code | 
| 84 | 80 |             GlobalConfigurationSource.UpdateDynamicConfigConfigurationSource(dynamicConfig); | 
| 85 | 81 | 
 | 
| 86 |  | -            OnConfigurationChanged( | 
| 87 |  | -                dynamicConfig, | 
| 88 |  | -                manualSource, | 
| 89 |  | -                mutableSettings, | 
| 90 |  | -                tracerSettings, | 
| 91 |  | -                // TODO: In the future this will 'live' elsewhere | 
| 92 |  | -                currentSettings: tracerSettings.MutableSettings, | 
| 93 |  | -                new ConfigurationTelemetry(), | 
| 94 |  | -                new OverrideErrorLog()); // TODO: We'll later report these | 
| 95 |  | -        } | 
| 96 |  | - | 
| 97 |  | -        private static void OnConfigurationChanged( | 
| 98 |  | -            IConfigurationSource dynamicConfig, | 
| 99 |  | -            ManualInstrumentationConfigurationSourceBase manualConfig, | 
| 100 |  | -            MutableSettings initialSettings, | 
| 101 |  | -            TracerSettings tracerSettings, | 
| 102 |  | -            MutableSettings currentSettings, | 
| 103 |  | -            ConfigurationTelemetry telemetry, | 
| 104 |  | -            OverrideErrorLog errorLog) | 
| 105 |  | -        { | 
| 106 |  | -            var newMutableSettings = MutableSettings.CreateUpdatedMutableSettings( | 
| 107 |  | -                dynamicConfig, | 
| 108 |  | -                manualConfig, | 
| 109 |  | -                initialSettings, | 
| 110 |  | -                tracerSettings, | 
| 111 |  | -                telemetry, | 
| 112 |  | -                errorLog); | 
| 113 |  | - | 
| 114 |  | -            TracerSettings newSettings; | 
| 115 |  | -            if (currentSettings.Equals(newMutableSettings)) | 
|  | 82 | +            var wasUpdated = Tracer.Instance.TracerManager.SettingsManager.UpdateSettings(dynamicConfig, manualConfig, TelemetryFactory.Config); | 
|  | 83 | +            if (wasUpdated) | 
| 116 | 84 |             { | 
| 117 |  | -                Log.Debug("No changes detected in the new dynamic configuration"); | 
| 118 |  | -                // Even though there were no "real" changes, there may be _effective_ changes in telemetry that | 
| 119 |  | -                // need to be recorded (e.g. the customer set the value in code but it was already set via | 
| 120 |  | -                // env vars). We _should_ record exporter settings too, but that introduces a bunch of complexity | 
| 121 |  | -                // which we'll resolve later anyway, so just have that gap for now (it's very niche). | 
| 122 |  | -                // If there are changes, they're recorded automatically in Tracer.Configure() | 
| 123 |  | -                telemetry.CopyTo(TelemetryFactory.Config); | 
| 124 |  | -                newSettings = tracerSettings; | 
| 125 |  | -            } | 
| 126 |  | -            else | 
| 127 |  | -            { | 
| 128 |  | -                Log.Information("Applying new dynamic configuration"); | 
| 129 |  | - | 
| 130 |  | -                newSettings = tracerSettings with { MutableSettings = newMutableSettings }; | 
| 131 |  | - | 
| 132 |  | -                /* | 
| 133 |  | -                if (debugLogsEnabled != null && debugLogsEnabled.Value != GlobalSettings.Instance.DebugEnabled) | 
| 134 |  | -                { | 
| 135 |  | -                    GlobalSettings.SetDebugEnabled(debugLogsEnabled.Value); | 
| 136 |  | -                    Security.Instance.SetDebugEnabled(debugLogsEnabled.Value); | 
| 137 |  | -
 | 
| 138 |  | -                    NativeMethods.UpdateSettings(new[] { ConfigurationKeys.DebugEnabled }, new[] { debugLogsEnabled.Value ? "1" : "0" }); | 
| 139 |  | -                } | 
| 140 |  | -                */ | 
| 141 |  | - | 
| 142 |  | -                Tracer.Configure(newSettings); | 
|  | 85 | +                Log.Information("Setting updates made via configuration in code were applied"); | 
| 143 | 86 |             } | 
| 144 | 87 | 
 | 
| 145 | 88 |             // TODO: This might not record the config in the correct order in future, but would require | 
| @@ -172,7 +115,7 @@ private static void OnConfigurationChanged( | 
| 172 | 115 | 
 | 
| 173 | 116 |             var newDebuggerSettings = oldDebuggerSettings with { DynamicSettings = dynamicDebuggerSettings }; | 
| 174 | 117 | 
 | 
| 175 |  | -            DebuggerManager.Instance.UpdateConfiguration(newSettings, newDebuggerSettings) | 
|  | 118 | +            DebuggerManager.Instance.UpdateConfiguration(Tracer.Instance.Settings, newDebuggerSettings) | 
| 176 | 119 |                            .ContinueWith(t => Log.Error(t?.Exception, "Error updating dynamic configuration for debugger"), TaskContinuationOptions.OnlyOnFaulted); | 
| 177 | 120 |         } | 
| 178 | 121 | 
 | 
|  | 
0 commit comments