@@ -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:
443461def _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