|
10 | 10 | _ONE_SETTINGS_CHANGE_URL, |
11 | 11 | _ONE_SETTINGS_CONFIG_URL, |
12 | 12 | ) |
| 13 | +from azure.monitor.opentelemetry.exporter._configuration._utils import _ConfigurationProfile |
13 | 14 | from azure.monitor.opentelemetry.exporter._configuration._utils import make_onesettings_request |
14 | 15 | from azure.monitor.opentelemetry.exporter._utils import Singleton |
15 | 16 |
|
@@ -40,26 +41,34 @@ class _ConfigurationManager(metaclass=Singleton): |
40 | 41 |
|
41 | 42 | def __init__(self): |
42 | 43 | """Initialize the ConfigurationManager instance.""" |
43 | | - |
44 | 44 | self._configuration_worker = None |
45 | 45 | self._state_lock = Lock() # Single lock for all state |
46 | 46 | self._current_state = _ConfigurationState() |
47 | 47 | self._callbacks = [] |
48 | | - self._initialize_worker() |
| 48 | + self._initialized = False |
49 | 49 |
|
50 | | - def _initialize_worker(self): |
| 50 | + def initialize(self, **kwargs): |
51 | 51 | """Initialize the ConfigurationManager and start the configuration worker.""" |
52 | | - # Lazy import to avoid circular import |
53 | | - from azure.monitor.opentelemetry.exporter._configuration._worker import _ConfigurationWorker |
54 | | - |
55 | | - # Get initial refresh interval from state |
56 | 52 | with self._state_lock: |
| 53 | + if self._initialized: |
| 54 | + return |
| 55 | + |
| 56 | + # Fill the configuration profile with the initializer's parameters |
| 57 | + _ConfigurationProfile.fill(**kwargs) |
| 58 | + |
| 59 | + # Lazy import to avoid circular import |
| 60 | + from azure.monitor.opentelemetry.exporter._configuration._worker import _ConfigurationWorker |
| 61 | + |
| 62 | + # Get initial refresh interval from current state |
57 | 63 | initial_refresh_interval = self._current_state.refresh_interval |
58 | 64 |
|
59 | | - self._configuration_worker = _ConfigurationWorker(self, initial_refresh_interval) |
| 65 | + self._configuration_worker = _ConfigurationWorker(self, initial_refresh_interval) |
| 66 | + self._initialized = True |
60 | 67 |
|
61 | 68 | def register_callback(self, callback): |
62 | 69 | # Register a callback to be invoked when configuration changes. |
| 70 | + if not self._initialized: |
| 71 | + return |
63 | 72 | self._callbacks.append(callback) |
64 | 73 |
|
65 | 74 | def _notify_callbacks(self, settings: Dict[str, str]): |
@@ -148,7 +157,7 @@ def get_configuration_and_refresh_interval(self, query_dict: Optional[Dict[str, |
148 | 157 | new_state_updates['refresh_interval'] = response.refresh_interval # type: ignore |
149 | 158 |
|
150 | 159 | if response.status_code == 304: |
151 | | - # Not modified: Only update etag and refresh interval below |
| 160 | + # Not modified: Settings unchanged, but update etag and refresh interval if provided |
152 | 161 | pass |
153 | 162 | # Handle version and settings updates |
154 | 163 | elif response.settings and response.version is not None: |
@@ -225,6 +234,8 @@ def shutdown(self) -> None: |
225 | 234 | if self._configuration_worker: |
226 | 235 | self._configuration_worker.shutdown() |
227 | 236 | self._configuration_worker = None |
| 237 | + self._initialized = False |
| 238 | + self._callbacks.clear() |
228 | 239 | # Clear the singleton instance from the metaclass |
229 | | - if self.__class__ in Singleton._instances: # pylint: disable=protected-access |
230 | | - del Singleton._instances[self.__class__] # pylint: disable=protected-access |
| 240 | + if self.__class__ in _ConfigurationManager._instances: # pylint: disable=protected-access |
| 241 | + del _ConfigurationManager._instances[self.__class__] # pylint: disable=protected-access |
0 commit comments