Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
### Breaking Changes

### Bugs Fixed
- 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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 logs.
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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ========================================================================
Expand Down
Loading