diff --git a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md index 236ca51c0c0c..aa3775a925d0 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md @@ -11,6 +11,10 @@ ### Bugs Fixed ### Other Changes +- Contribute distro profile information (`component="dst"` and distro version) to the OneSettings control plane during `configure_azure_monitor` + ([#48475](https://github.com/Azure/azure-sdk-for-python/pull/48475)) +- Update `azure-monitor-opentelemetry-exporter` minimum dependency to `1.0.0b56` + ([#48475](https://github.com/Azure/azure-sdk-for-python/pull/48475)) ## 1.8.9 (2026-07-01) diff --git a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 11ed74b9e5c6..27897690f062 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -84,6 +84,9 @@ _is_attach_enabled, _is_on_functions, ) +from azure.monitor.opentelemetry.exporter._configuration._state import ( # pylint: disable=import-error,no-name-in-module + get_configuration_manager, +) from azure.monitor.opentelemetry._diagnostics.diagnostic_logging import ( _DISTRO_DETECTS_ATTACH, AzureDiagnosticLogging, @@ -145,6 +148,17 @@ def configure_azure_monitor(**kwargs) -> None: # pylint: disable=C4758 configurations = _get_configurations(**kwargs) + # Contribute distro-level profile fields to the OneSettings control plane before any exporter is + # created. initialize() is idempotent and _ConfigurationProfile.fill() is first-wins per field, so + # setting component="dst" and the distro version here makes the profile reflect the distro; the + # exporters created below still supply ikey/region without overriding these already-set fields. + config_manager = get_configuration_manager() + if config_manager: + config_manager.initialize( + component="dst", + version=VERSION, + ) + disable_tracing = configurations[DISABLE_TRACING_ARG] disable_logging = configurations[DISABLE_LOGGING_ARG] disable_metrics = configurations[DISABLE_METRICS_ARG] diff --git a/sdk/monitor/azure-monitor-opentelemetry/setup.py b/sdk/monitor/azure-monitor-opentelemetry/setup.py index b0b88c3ff9c9..b710df9b8da5 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/setup.py +++ b/sdk/monitor/azure-monitor-opentelemetry/setup.py @@ -83,7 +83,7 @@ install_requires=[ "azure-core<2.0.0,>=1.28.0", "azure-core-tracing-opentelemetry~=1.0.0b11", - "azure-monitor-opentelemetry-exporter~=1.0.0b54", + "azure-monitor-opentelemetry-exporter~=1.0.0b56", "opentelemetry-sdk~=1.43.0", "opentelemetry-instrumentation-django>=0.64b0,<0.65.0", "opentelemetry-instrumentation-fastapi>=0.64b0,<0.65.0", diff --git a/sdk/monitor/azure-monitor-opentelemetry/tests/test_configure.py b/sdk/monitor/azure-monitor-opentelemetry/tests/test_configure.py index dbb9f1b8538b..62fe78dbb3c5 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/tests/test_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/tests/test_configure.py @@ -28,13 +28,21 @@ configure_azure_monitor, ) from azure.monitor.opentelemetry._diagnostics.diagnostic_logging import _DISTRO_DETECTS_ATTACH - +from azure.monitor.opentelemetry._version import VERSION TEST_RESOURCE = Resource({"foo": "bar"}) # pylint: disable=too-many-public-methods class TestConfigure(unittest.TestCase): + def setUp(self): + # Patch get_configuration_manager for every test so configure_azure_monitor never starts the + # real OneSettings worker thread. Tests that care about the interaction use + # self._get_config_manager_mock to control the returned manager. + patcher = patch("azure.monitor.opentelemetry._configure.get_configuration_manager") + self._get_config_manager_mock = patcher.start() + self.addCleanup(patcher.stop) + @patch( "azure.monitor.opentelemetry._configure._send_attach_warning", ) @@ -73,6 +81,76 @@ def test_configure_azure_monitor( instrumentation_mock.assert_called_once() detect_attach_mock.assert_called_once() + @patch( + "azure.monitor.opentelemetry._configure._send_attach_warning", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_instrumentations", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_live_metrics", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_metrics", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_logging", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_tracing", + ) + def test_configure_azure_monitor_initializes_config_manager( + self, + tracing_mock, + logging_mock, + metrics_mock, + live_metrics_mock, + instrumentation_mock, + detect_attach_mock, + ): + config_manager_mock = self._get_config_manager_mock.return_value + configure_azure_monitor(connection_string="test_cs") + # Distro contributes component="dst" and its version before any exporter is created. + config_manager_mock.initialize.assert_called_once_with( + component="dst", + version=VERSION, + ) + + @patch( + "azure.monitor.opentelemetry._configure._send_attach_warning", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_instrumentations", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_live_metrics", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_metrics", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_logging", + ) + @patch( + "azure.monitor.opentelemetry._configure._setup_tracing", + ) + def test_configure_azure_monitor_config_manager_disabled( + self, + tracing_mock, + logging_mock, + metrics_mock, + live_metrics_mock, + instrumentation_mock, + detect_attach_mock, + ): + # When the control plane is disabled, get_configuration_manager returns None and the distro + # skips initialize() without raising. + self._get_config_manager_mock.return_value = None + configure_azure_monitor(connection_string="test_cs") + tracing_mock.assert_called_once() + logging_mock.assert_called_once() + metrics_mock.assert_called_once() + @patch( "azure.monitor.opentelemetry._configure._setup_instrumentations", )