Skip to content

Commit 59296b5

Browse files
authored
Log error for 401/403 to assist with customer troubleshooting (#41767)
1 parent 60dd9fb commit 59296b5

File tree

2 files changed

+22
-1
lines changed
  • sdk/monitor/azure-monitor-opentelemetry-exporter

2 files changed

+22
-1
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
### Other Changes
1515

16+
- Add logging errors for `401: Unauthorized` and `403: Forbidden` to assist in customer troubleshooting
17+
([#41767](https://github.com/Azure/azure-sdk-for-python/pull/41767))
18+
1619
## 1.0.0b38 (2025-06-17)
1720

1821
### Features Added

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ def _transmit(self, envelopes: List[TelemetryItem]) -> ExportResult:
247247
if self._should_collect_stats():
248248
_update_requests_map(_REQ_RETRY_NAME[1], value=response_error.status_code)
249249
result = ExportResult.FAILED_RETRYABLE
250+
# Log error for 401: Unauthorized, 403: Forbidden to assist with customer troubleshooting
251+
if not self._is_stats_exporter():
252+
if response_error.status_code == 401:
253+
logger.error(
254+
"Retryable server side error: %s. " \
255+
"Your Application Insights resource may be configured to use entra ID authentication. " \
256+
"Please make sure your application is configured to use the correct token credential.",
257+
response_error.message,
258+
)
259+
elif response_error.status_code == 403:
260+
logger.error(
261+
"Retryable server side error: %s. " \
262+
"Your application may be configured with a token credential " \
263+
"but your Application Insights resource may be configured incorrectly. Please make sure " \
264+
"your Application Insights resource has enabled entra Id authentication and " \
265+
"has the correct `Monitoring Metrics Publisher` role assigned.",
266+
response_error.message,
267+
)
250268
elif _is_throttle_code(response_error.status_code):
251269
if self._should_collect_stats():
252270
_update_requests_map(_REQ_THROTTLE_NAME[1], value=response_error.status_code)
@@ -443,9 +461,9 @@ def _format_storage_telemetry_item(item: TelemetryItem) -> TelemetryItem:
443461
def _get_authentication_credential(**kwargs: Any) -> Optional[ManagedIdentityCredential]:
444462
if "credential" in kwargs:
445463
return kwargs.get("credential")
464+
auth_string = os.getenv(_APPLICATIONINSIGHTS_AUTHENTICATION_STRING, "")
446465
try:
447466
if _APPLICATIONINSIGHTS_AUTHENTICATION_STRING in os.environ:
448-
auth_string = os.getenv(_APPLICATIONINSIGHTS_AUTHENTICATION_STRING, "")
449467
kv_pairs = auth_string.split(";")
450468
auth_string_d = dict(s.split("=") for s in kv_pairs)
451469
auth_string_d = {key.lower(): value for key, value in auth_string_d.items()}

0 commit comments

Comments
 (0)