diff --git a/litellm/_service_logger.py b/litellm/_service_logger.py index b2bd26c267..0c6996b102 100644 --- a/litellm/_service_logger.py +++ b/litellm/_service_logger.py @@ -4,6 +4,7 @@ from .types.services import ServiceTypes, ServiceLoggerPayload from .integrations.prometheus_services import PrometheusServicesLogger from .integrations.custom_logger import CustomLogger from datetime import timedelta +from typing import Union class ServiceLogging(CustomLogger): @@ -59,7 +60,11 @@ class ServiceLogging(CustomLogger): ) async def async_service_failure_hook( - self, service: ServiceTypes, duration: float, error: Exception, call_type: str + self, + service: ServiceTypes, + duration: float, + error: Union[str, Exception], + call_type: str, ): """ - For counting if the redis, postgres call is unsuccessful @@ -67,9 +72,15 @@ class ServiceLogging(CustomLogger): if self.mock_testing: self.mock_testing_async_failure_hook += 1 + error_message = "" + if isinstance(error, Exception): + error_message = str(error) + elif isinstance(error, str): + error_message = error + payload = ServiceLoggerPayload( is_error=True, - error=str(error), + error=error_message, service=service, duration=duration, call_type=call_type, diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index e45245909f..8572fd70c0 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -488,6 +488,9 @@ class ProxyLogging: if hasattr(self, "service_logging_obj"): self.service_logging_obj.async_service_failure_hook( service=ServiceTypes.DB, + duration=duration, + error=error_message, + call_type=call_type, ) if litellm.utils.capture_exception: