@@ -24,6 +24,11 @@ internal class SettingsManager(
2424 {
2525 private readonly TracerSettings _tracerSettings = tracerSettings ;
2626 private readonly List < SettingChangeSubscription > _subscribers = [ ] ;
27+
28+ private IConfigurationSource _dynamicConfigurationSource = NullConfigurationSource . Instance ;
29+ private ManualInstrumentationConfigurationSourceBase _manualConfigurationSource =
30+ new ManualInstrumentationConfigurationSource ( new Dictionary < string , object ? > ( ) , useDefaultSources : true ) ;
31+
2732 private SettingChanges ? _latest ;
2833
2934 /// <summary>
@@ -71,15 +76,44 @@ public IDisposable SubscribeToChanges(Action<SettingChanges> callback)
7176 return subscription ;
7277 }
7378
79+ /// <summary>
80+ /// Regenerate the application's new <see cref="MutableSettings"/> and <see cref="ExporterSettings"/>
81+ /// based on runtime configuration sources.
82+ /// </summary>
83+ /// <param name="manualSource">An <see cref="IConfigurationSource"/> containing the new settings created by manual configuration (in code)</param>
84+ /// <param name="centralTelemetry">The central <see cref="IConfigurationTelemetry"/> to report config telemetry updates to</param>
85+ /// <returns>True if changes were detected and consumers were updated, false otherwise</returns>
86+ public bool UpdateManualConfigurationSettings (
87+ ManualInstrumentationConfigurationSourceBase manualSource ,
88+ IConfigurationTelemetry centralTelemetry )
89+ {
90+ // we lock this whole method so that we can't conflict with UpdateDynamicConfigurationSettings calls too
91+ lock ( _subscribers )
92+ {
93+ _manualConfigurationSource = manualSource ;
94+ return UpdateSettings ( _dynamicConfigurationSource , manualSource , centralTelemetry ) ;
95+ }
96+ }
97+
7498 /// <summary>
7599 /// Regenerate the application's new <see cref="MutableSettings"/> and <see cref="ExporterSettings"/>
76100 /// based on runtime configuration sources.
77101 /// </summary>
78102 /// <param name="dynamicConfigSource">An <see cref="IConfigurationSource"/> for dynamic config via remote config</param>
79- /// <param name="manualSource">An <see cref="IConfigurationSource"/> for manual configuration (in code)</param>
80103 /// <param name="centralTelemetry">The central <see cref="IConfigurationTelemetry"/> to report config telemetry updates to</param>
81104 /// <returns>True if changes were detected and consumers were updated, false otherwise</returns>
82- public bool UpdateSettings (
105+ public bool UpdateDynamicConfigurationSettings (
106+ IConfigurationSource dynamicConfigSource ,
107+ IConfigurationTelemetry centralTelemetry )
108+ {
109+ lock ( _subscribers )
110+ {
111+ _dynamicConfigurationSource = dynamicConfigSource ;
112+ return UpdateSettings ( dynamicConfigSource , _manualConfigurationSource , centralTelemetry ) ;
113+ }
114+ }
115+
116+ private bool UpdateSettings (
83117 IConfigurationSource dynamicConfigSource ,
84118 ManualInstrumentationConfigurationSourceBase manualSource ,
85119 IConfigurationTelemetry centralTelemetry )
@@ -157,21 +191,17 @@ private void NotifySubscribers(SettingChanges settings)
157191 // there's nothing to prevent NotifySubscribers being called concurrently,
158192 // which could result in weird out-of-order notifications for customers. So for simplicity
159193 // we just lock the whole method to ensure serialized updates.
194+ Volatile . Write ( ref _latest , settings ) ;
160195
161- lock ( _subscribers )
196+ foreach ( var subscriber in _subscribers )
162197 {
163- Volatile . Write ( ref _latest , settings ) ;
164-
165- foreach ( var subscriber in _subscribers )
198+ try
166199 {
167- try
168- {
169- subscriber . Notify ( settings ) ;
170- }
171- catch ( Exception ex )
172- {
173- Log . Error ( ex , "Error notifying subscriber of MutableSettings change" ) ;
174- }
200+ subscriber . Notify ( settings ) ;
201+ }
202+ catch ( Exception ex )
203+ {
204+ Log . Error ( ex , "Error notifying subscriber of MutableSettings change" ) ;
175205 }
176206 }
177207 }
0 commit comments