mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
track error info in metadata
This commit is contained in:
parent
d0d9236947
commit
fa9f3ae4e7
5 changed files with 31 additions and 0 deletions
|
|
@ -3114,10 +3114,27 @@ class StandardLoggingPayloadSetup:
|
|||
str(original_exception.__class__.__name__) if original_exception else ""
|
||||
)
|
||||
_llm_provider_in_exception = getattr(original_exception, "llm_provider", "")
|
||||
|
||||
# Get traceback information (first 100 lines)
|
||||
traceback_info = ""
|
||||
if original_exception:
|
||||
tb = getattr(original_exception, "__traceback__", None)
|
||||
if tb:
|
||||
import traceback
|
||||
|
||||
tb_lines = traceback.format_tb(tb)
|
||||
traceback_info = "".join(tb_lines[:100]) # Limit to first 100 lines
|
||||
|
||||
# Get additional error details
|
||||
error_message = str(original_exception)
|
||||
|
||||
return StandardLoggingPayloadErrorInformation(
|
||||
error_code=error_status,
|
||||
error_class=error_class,
|
||||
llm_provider=_llm_provider_in_exception,
|
||||
traceback=traceback_info,
|
||||
status_code=getattr(original_exception, "status_code", None),
|
||||
error_message=error_message if original_exception else "",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ from litellm.types.utils import (
|
|||
ModelResponse,
|
||||
ProviderField,
|
||||
StandardCallbackDynamicParams,
|
||||
StandardLoggingPayloadErrorInformation,
|
||||
StandardLoggingPayloadStatus,
|
||||
StandardPassThroughResponseObject,
|
||||
TextCompletionResponse,
|
||||
|
|
@ -1856,6 +1857,7 @@ class SpendLogsMetadata(TypedDict):
|
|||
requester_ip_address: Optional[str]
|
||||
applied_guardrails: Optional[List[str]]
|
||||
status: StandardLoggingPayloadStatus
|
||||
error_information: Optional[StandardLoggingPayloadErrorInformation]
|
||||
|
||||
|
||||
class SpendLogsPayload(TypedDict):
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ from litellm.litellm_core_utils.core_helpers import (
|
|||
_get_parent_otel_span_from_kwargs,
|
||||
get_litellm_metadata_from_kwargs,
|
||||
)
|
||||
from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup
|
||||
from litellm.proxy._types import UserAPIKeyAuth
|
||||
from litellm.proxy.auth.auth_checks import log_db_metrics
|
||||
from litellm.types.utils import (
|
||||
StandardLoggingPayload,
|
||||
StandardLoggingPayloadErrorInformation,
|
||||
StandardLoggingUserAPIKeyMetadata,
|
||||
)
|
||||
from litellm.utils import get_end_user_id_for_cost_tracking
|
||||
|
|
@ -48,6 +50,12 @@ class _ProxyDBLogger(CustomLogger):
|
|||
)
|
||||
_metadata["user_api_key"] = user_api_key_dict.api_key
|
||||
_metadata["status"] = "failure"
|
||||
_metadata["error_information"] = (
|
||||
StandardLoggingPayloadSetup.get_error_information(
|
||||
original_exception=original_exception,
|
||||
)
|
||||
)
|
||||
|
||||
existing_metadata: dict = request_data.get("metadata", None) or {}
|
||||
existing_metadata.update(_metadata)
|
||||
existing_metadata["proxy_server_request"] = (
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ def _get_spend_logs_metadata(
|
|||
additional_usage_values=None,
|
||||
applied_guardrails=None,
|
||||
status=None or "success",
|
||||
error_information=None,
|
||||
)
|
||||
verbose_proxy_logger.debug(
|
||||
"getting payload for SpendLogs, available keys in metadata: "
|
||||
|
|
|
|||
|
|
@ -1606,6 +1606,9 @@ class StandardLoggingPayloadErrorInformation(TypedDict, total=False):
|
|||
error_code: Optional[str]
|
||||
error_class: Optional[str]
|
||||
llm_provider: Optional[str]
|
||||
traceback: Optional[str]
|
||||
status_code: Optional[int]
|
||||
error_message: Optional[str]
|
||||
|
||||
|
||||
class StandardLoggingGuardrailInformation(TypedDict, total=False):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue