From 75dacd88592eac08d78d6c58a5ffd3b5363fdcc9 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 26 Nov 2024 19:39:36 -0800 Subject: [PATCH] use async_log_proxy_authentication_errors --- litellm/proxy/auth/user_api_key_auth.py | 12 +++++++----- litellm/proxy/utils.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index d19215245..32f0c95db 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -1197,13 +1197,15 @@ async def user_api_key_auth( # noqa: PLR0915 extra={"requester_ip": requester_ip}, ) - # Log this exception to OTEL - if open_telemetry_logger is not None: - await open_telemetry_logger.async_post_call_failure_hook( # type: ignore + # Log this exception to OTEL, Datadog etc + asyncio.create_task( + proxy_logging_obj.async_log_proxy_authentication_errors( original_exception=e, - request_data={}, - user_api_key_dict=UserAPIKeyAuth(parent_otel_span=parent_otel_span), + request=request, + parent_otel_span=parent_otel_span, + api_key=api_key, ) + ) if isinstance(e, litellm.BudgetExceededError): raise ProxyException( diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index a155b23cc..46d554190 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -899,7 +899,7 @@ class ProxyLogging: - `post_call_failure_hook` calls `litellm_logging_obj.async_failure_handler`. This led to the Exception being logged twice What does this handler do? - - Logs Authentication Errors (like invalid API Key passed) to CustomLogger compatible classes + - Logs Authentication Errors (like invalid API Key passed) to CustomLogger compatible classes (OTEL, Datadog etc) - calls CustomLogger.async_post_call_failure_hook """