From 1f5c972985a788d37a441ee38fe475fe35f736ff Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 26 Nov 2024 19:35:19 -0800 Subject: [PATCH] add new dd type for auth errors --- litellm/integrations/datadog/datadog.py | 34 +++++++++++++++++++ ...odel_prices_and_context_window_backup.json | 2 +- .../integrations/datadog.py} | 10 +++++- 3 files changed, 44 insertions(+), 2 deletions(-) rename litellm/{integrations/datadog/types.py => types/integrations/datadog.py} (68%) diff --git a/litellm/integrations/datadog/datadog.py b/litellm/integrations/datadog/datadog.py index 527b6f87d..b7348f50e 100644 --- a/litellm/integrations/datadog/datadog.py +++ b/litellm/integrations/datadog/datadog.py @@ -32,6 +32,8 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) +from litellm.proxy._types import UserAPIKeyAuth +from litellm.types.integrations.datadog import * from litellm.types.services import ServiceLoggerPayload from litellm.types.utils import StandardLoggingPayload @@ -364,6 +366,38 @@ class DataDogLogger(CustomBatchLogger): """ return + async def async_post_call_failure_hook( + self, + request_data: dict, + original_exception: Exception, + user_api_key_dict: UserAPIKeyAuth, + ): + """ + Handles Proxy Errors (not-related to LLM API), ex: Authentication Errors + """ + import json + + _exception_payload = DatadogProxyFailureHookJsonMessage( + exception=str(original_exception), + error_class=str(original_exception.__class__.__name__), + status_code=getattr(original_exception, "status_code", None), + traceback=traceback.format_exc(), + user_api_key_dict=user_api_key_dict.model_dump(), + ) + + json_payload = json.dumps(_exception_payload) + verbose_logger.debug("Datadog: Logger - Logging payload = %s", json_payload) + dd_payload = DatadogPayload( + ddsource=os.getenv("DD_SOURCE", "litellm"), + ddtags="", + hostname="", + message=json_payload, + service="litellm-server", + status=DataDogStatus.ERROR, + ) + + self.log_queue.append(dd_payload) + def _create_v0_logging_payload( self, kwargs: Union[dict, Any], diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index a56472f7f..b0d0e7d37 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -2032,7 +2032,6 @@ "tool_use_system_prompt_tokens": 264, "supports_assistant_prefill": true, "supports_prompt_caching": true, - "supports_pdf_input": true, "supports_response_schema": true }, "claude-3-opus-20240229": { @@ -2098,6 +2097,7 @@ "supports_vision": true, "tool_use_system_prompt_tokens": 159, "supports_assistant_prefill": true, + "supports_pdf_input": true, "supports_prompt_caching": true, "supports_response_schema": true }, diff --git a/litellm/integrations/datadog/types.py b/litellm/types/integrations/datadog.py similarity index 68% rename from litellm/integrations/datadog/types.py rename to litellm/types/integrations/datadog.py index 87aa3ce17..79d4eded4 100644 --- a/litellm/integrations/datadog/types.py +++ b/litellm/types/integrations/datadog.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import TypedDict +from typing import Optional, TypedDict class DataDogStatus(str, Enum): @@ -19,3 +19,11 @@ class DatadogPayload(TypedDict, total=False): class DD_ERRORS(Enum): DATADOG_413_ERROR = "Datadog API Error - Payload too large (batch is above 5MB uncompressed). If you want this logged either disable request/response logging or set `DD_BATCH_SIZE=50`" + + +class DatadogProxyFailureHookJsonMessage(TypedDict, total=False): + exception: str + error_class: str + status_code: Optional[int] + traceback: str + user_api_key_dict: dict