From 3aad034a8b0c52275944ab3ab0276059170716b2 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 30 Apr 2024 13:28:26 -0700 Subject: [PATCH] feat log request kwargs in error logs --- litellm/proxy/_types.py | 2 +- litellm/proxy/proxy_server.py | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 75dfdb4c4db..2b3a72250f1 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -917,7 +917,7 @@ class LiteLLM_ErrorLogs(LiteLLMBase): api_base: Optional[str] = "" model_group: Optional[str] = "" model_id: Optional[str] = "" - request_kwargs: Optional[Json] = {} + request_kwargs: Optional[dict] = {} exception_type: Optional[str] = "" status_code: Optional[str] = "" exception_string: Optional[str] = "" diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index f9e7756bde6..530438b94a8 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1230,39 +1230,39 @@ async def _PROXY_failure_handler( ) _exception = kwargs.get("exception") - traceback = kwargs.get("traceback") _exception_type = _exception.__class__.__name__ _model = kwargs.get("model", None) - _status_code = _exception.status_code + _optional_params = kwargs.get("optional_params", {}) + _optional_params = copy.deepcopy(_optional_params) + + for k, v in _optional_params.items(): + v = str(v) + v = v[:100] + + _status_code = "500" + try: + _status_code = str(_exception.status_code) + except: + # Don't let this fail logging the exception to the dB + pass _litellm_params = kwargs.get("litellm_params", {}) or {} _metadata = _litellm_params.get("metadata", {}) or {} _model_id = _metadata.get("model_info", {}).get("id", "") _model_group = _metadata.get("model_group", "") - api_base = litellm.get_api_base(model=_model, optional_params=_litellm_params) + _exception_string = str(_exception)[:500] - verbose_proxy_logger.debug( - "\nexception_type", - _exception_type, - "\nrequest_model", - _model, - "\nmodel_id", - _model_id, - "\nexception", - _exception, - "\ntraceback", - traceback, - ) error_log = LiteLLM_ErrorLogs( request_id=str(uuid.uuid4()), model_group=_model_group, model_id=_model_id, + request_kwargs=_optional_params, api_base=api_base, exception_type=_exception_type, status_code=_status_code, - exception_string=str(_exception), + exception_string=_exception_string, ) # helper function to convert to dict on pydantic v2 & v1