feat - log exceptions to OTEL

This commit is contained in:
Ishaan Jaff 2024-06-10 12:34:18 -07:00
parent d5a1cc282e
commit a27f7e2817
2 changed files with 11 additions and 2 deletions

View file

@ -160,6 +160,7 @@ from litellm.proxy.auth.auth_checks import (
get_user_object, get_user_object,
allowed_routes_check, allowed_routes_check,
get_actual_routes, get_actual_routes,
log_to_opentelemetry,
) )
from litellm.llms.custom_httpx.httpx_handler import HTTPHandler from litellm.llms.custom_httpx.httpx_handler import HTTPHandler
from litellm.exceptions import RejectedRequestError from litellm.exceptions import RejectedRequestError
@ -1506,7 +1507,7 @@ async def user_api_key_auth(
) )
if valid_token is None: if valid_token is None:
# No token was found when looking up in the DB # No token was found when looking up in the DB
raise Exception("Invalid token passed") raise Exception("Invalid proxy server token passed")
if valid_token_dict is not None: if valid_token_dict is not None:
if user_id_information is not None and _is_user_proxy_admin( if user_id_information is not None and _is_user_proxy_admin(
user_id_information user_id_information
@ -1539,6 +1540,14 @@ async def user_api_key_auth(
str(e) str(e)
) )
) )
# Log this exception to OTEL
if open_telemetry_logger is not None:
await open_telemetry_logger.async_post_call_failure_hook(
original_exception=e,
user_api_key_dict=UserAPIKeyAuth(parent_otel_span=parent_otel_span),
)
verbose_proxy_logger.debug(traceback.format_exc()) verbose_proxy_logger.debug(traceback.format_exc())
if isinstance(e, litellm.BudgetExceededError): if isinstance(e, litellm.BudgetExceededError):
raise ProxyException( raise ProxyException(

View file

@ -272,7 +272,7 @@ def test_call_with_invalid_key(prisma_client):
except Exception as e: except Exception as e:
print("Got Exception", e) print("Got Exception", e)
print(e.message) print(e.message)
assert "Authentication Error, Invalid token passed" in e.message assert "Authentication Error, Invalid proxy server token passed" in e.message
pass pass