@@ -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 )
@@ -153,25 +187,17 @@ public bool UpdateSettings(
153187
154188 private void NotifySubscribers ( SettingChanges settings )
155189 {
156- // Strictly, for safety, we only need to lock in the subscribers list access. However,
157- // there's nothing to prevent NotifySubscribers being called concurrently,
158- // which could result in weird out-of-order notifications for customers. So for simplicity
159- // we just lock the whole method to ensure serialized updates.
190+ _latest = settings ;
160191
161- lock ( _subscribers )
192+ foreach ( var subscriber in _subscribers )
162193 {
163- Volatile . Write ( ref _latest , settings ) ;
164-
165- foreach ( var subscriber in _subscribers )
194+ try
166195 {
167- try
168- {
169- subscriber . Notify ( settings ) ;
170- }
171- catch ( Exception ex )
172- {
173- Log . Error ( ex , "Error notifying subscriber of MutableSettings change" ) ;
174- }
196+ subscriber . Notify ( settings ) ;
197+ }
198+ catch ( Exception ex )
199+ {
200+ Log . Error ( ex , "Error notifying subscriber of MutableSettings change" ) ;
175201 }
176202 }
177203 }
0 commit comments