fix(proxy/utils.py): add prometheus failed db request tracking

This commit is contained in:
Krrish Dholakia 2024-04-18 16:30:29 -07:00
parent d61250109e
commit 919a2876f1
2 changed files with 16 additions and 2 deletions

View file

@ -4,6 +4,7 @@ from .types.services import ServiceTypes, ServiceLoggerPayload
from .integrations.prometheus_services import PrometheusServicesLogger from .integrations.prometheus_services import PrometheusServicesLogger
from .integrations.custom_logger import CustomLogger from .integrations.custom_logger import CustomLogger
from datetime import timedelta from datetime import timedelta
from typing import Union
class ServiceLogging(CustomLogger): class ServiceLogging(CustomLogger):
@ -59,7 +60,11 @@ class ServiceLogging(CustomLogger):
) )
async def async_service_failure_hook( 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 - For counting if the redis, postgres call is unsuccessful
@ -67,9 +72,15 @@ class ServiceLogging(CustomLogger):
if self.mock_testing: if self.mock_testing:
self.mock_testing_async_failure_hook += 1 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( payload = ServiceLoggerPayload(
is_error=True, is_error=True,
error=str(error), error=error_message,
service=service, service=service,
duration=duration, duration=duration,
call_type=call_type, call_type=call_type,

View file

@ -488,6 +488,9 @@ class ProxyLogging:
if hasattr(self, "service_logging_obj"): if hasattr(self, "service_logging_obj"):
self.service_logging_obj.async_service_failure_hook( self.service_logging_obj.async_service_failure_hook(
service=ServiceTypes.DB, service=ServiceTypes.DB,
duration=duration,
error=error_message,
call_type=call_type,
) )
if litellm.utils.capture_exception: if litellm.utils.capture_exception: