From 05a53b41b22ba4c33f10e741458caefd31c9ddc2 Mon Sep 17 00:00:00 2001 From: Radhika Gupta Date: Fri, 27 Mar 2026 09:45:51 -0700 Subject: [PATCH 1/4] Suppress internal sdkstats HTTP pipeline logs from appearing in user's traces --- .../azure-monitor-opentelemetry-exporter/CHANGELOG.md | 2 ++ .../azure/monitor/opentelemetry/exporter/export/_base.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index 0c40b701207c..cab281b6706e 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -7,9 +7,11 @@ ### Breaking Changes ### Bugs Fixed +- Suppress internal sdkstats HTTP pipeline logs from appearing in user's traces - Kubernetes pod name takes precedence when populating `cloud_RoleInstance` ([#45884](https://github.com/Azure/azure-sdk-for-python/pull/45884)) + ### Other Changes ## 1.0.0b49 (2026-03-19) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py index 9055c41fc3ce..62d5efae82c6 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py @@ -160,9 +160,13 @@ def __init__(self, **kwargs: Any) -> None: config.logging_policy, # Explicitly disabling to avoid infinite loop of Span creation when data is exported # DistributedTracingPolicy(**kwargs), - config.http_logging_policy or HttpLoggingPolicy(**kwargs), ] + # Exclude HttpLoggingPolicy for the sdkstats exporter so its HTTP + # traffic does not appear in the user's console output. + if not self._is_stats_exporter(): + policies.append(config.http_logging_policy or HttpLoggingPolicy(**kwargs)) + self.client: AzureMonitorClient = AzureMonitorClient( host=self._endpoint, connection_timeout=self._timeout, policies=policies, **kwargs ) From 50e793d3a8cb0ed5915f2718d8f88a200f750d65 Mon Sep 17 00:00:00 2001 From: Radhika Gupta Date: Fri, 27 Mar 2026 09:48:21 -0700 Subject: [PATCH 2/4] Update CHANGELOG --- sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index cab281b6706e..6ffe11a5c155 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -7,11 +7,11 @@ ### Breaking Changes ### Bugs Fixed -- Suppress internal sdkstats HTTP pipeline logs from appearing in user's traces +- Suppress internal sdkstats HTTP pipeline logs from appearing in user's logs + ([#45966](https://github.com/Azure/azure-sdk-for-python/pull/45966)) - Kubernetes pod name takes precedence when populating `cloud_RoleInstance` ([#45884](https://github.com/Azure/azure-sdk-for-python/pull/45884)) - ### Other Changes ## 1.0.0b49 (2026-03-19) From 969c330b53bd8290b10de930196fa4f2b4a3565d Mon Sep 17 00:00:00 2001 From: Radhika Gupta Date: Fri, 27 Mar 2026 10:50:47 -0700 Subject: [PATCH 3/4] Add test coverage --- .../tests/test_base_exporter.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py index 55e8ec5ad161..33d8634e04da 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py @@ -310,6 +310,45 @@ def test_constructor_disable_offline_storage_with_storage_directory(self, mock_g self.assertEqual(base._storage_directory, "test/path") mock_get_temp_dir.assert_not_called() + def test_normal_exporter_includes_http_logging_policy(self): + from azure.core.pipeline.policies import HttpLoggingPolicy + + captured_policies = [] + original_init = AzureMonitorClient.__init__ + + def capturing_init(self, *args, **kwargs): + captured_policies.extend(kwargs.get("policies", [])) + original_init(self, *args, **kwargs) + + with mock.patch.object(AzureMonitorClient, "__init__", capturing_init): + BaseExporter( + connection_string="InstrumentationKey=4321abcd-5678-4efa-8abc-1234567890ab", + ) + self.assertTrue( + any(isinstance(p, HttpLoggingPolicy) for p in captured_policies), + "HttpLoggingPolicy should be present in the pipeline for normal exporters", + ) + + def test_statsbeat_exporter_excludes_http_logging_policy(self): + from azure.core.pipeline.policies import HttpLoggingPolicy + + captured_policies = [] + original_init = AzureMonitorClient.__init__ + + def capturing_init(self, *args, **kwargs): + captured_policies.extend(kwargs.get("policies", [])) + original_init(self, *args, **kwargs) + + with mock.patch.object(AzureMonitorClient, "__init__", capturing_init): + AzureMonitorMetricExporter( + is_sdkstats=True, + disable_offline_storage=True, + ) + self.assertFalse( + any(isinstance(p, HttpLoggingPolicy) for p in captured_policies), + "HttpLoggingPolicy must not be present in the pipeline for statsbeat exporters", + ) + # ======================================================================== # STORAGE TESTS # ======================================================================== From 58045a2e4a63bc026dd94f8e2046afda92231d1d Mon Sep 17 00:00:00 2001 From: Radhika Gupta Date: Fri, 27 Mar 2026 11:43:46 -0700 Subject: [PATCH 4/4] Update comment --- .../azure/monitor/opentelemetry/exporter/export/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py index 62d5efae82c6..14354219d503 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py @@ -163,7 +163,7 @@ def __init__(self, **kwargs: Any) -> None: ] # Exclude HttpLoggingPolicy for the sdkstats exporter so its HTTP - # traffic does not appear in the user's console output. + # traffic does not appear in the user's logs. if not self._is_stats_exporter(): policies.append(config.http_logging_policy or HttpLoggingPolicy(**kwargs))