Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

prometheus emit llm provider on failure metric

Ishaan Jaffc402db905725
diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py
index 5ac8c80eb30..205e1f0c6b6 100644
--- a/litellm/integrations/prometheus.py
+++ b/litellm/integrations/prometheus.py
@@ -818,7 +818,7 @@ class PrometheusLogger(CustomLogger):
requested_model=request_data.get("model", ""),
status_code=str(getattr(original_exception, "status_code", None)),
exception_status=str(getattr(original_exception, "status_code", None)),
- exception_class=str(original_exception.__class__.__name__),
+ exception_class=self._get_exception_class_name(original_exception),
tags=_tags,
)
_labels = prometheus_label_factory(
@@ -917,7 +917,7 @@ class PrometheusLogger(CustomLogger):
api_base=api_base,
api_provider=llm_provider,
exception_status=str(getattr(exception, "status_code", None)),
- exception_class=exception.__class__.__name__,
+ exception_class=self._get_exception_class_name(exception),
requested_model=model_group,
hashed_api_key=standard_logging_payload["metadata"][
"user_api_key_hash"
@@ -1146,6 +1146,20 @@ class PrometheusLogger(CustomLogger):
)
return
+ @staticmethod
+ def _get_exception_class_name(exception: Exception) -> str:
+ exception_class_name = getattr(exception, "llm_provider") or ""
+
+ # pretty print the provider name on prometheus
+ # eg. `openai` -> `Openai.`
+ if len(exception_class_name) >= 1:
+ exception_class_name = (
+ exception_class_name[0].upper() + exception_class_name[1:] + "."
+ )
+
+ exception_class_name += exception.__class__.__name__
+ return exception_class_name
+
async def log_success_fallback_event(
self, original_model_group: str, kwargs: dict, original_exception: Exception
):
@@ -1181,7 +1195,7 @@ class PrometheusLogger(CustomLogger):
team=standard_metadata["user_api_key_team_id"],
team_alias=standard_metadata["user_api_key_team_alias"],
exception_status=str(getattr(original_exception, "status_code", None)),
- exception_class=str(original_exception.__class__.__name__),
+ exception_class=self._get_exception_class_name(original_exception),
tags=_tags,
)
_labels = prometheus_label_factory(
@@ -1225,7 +1239,7 @@ class PrometheusLogger(CustomLogger):
team=standard_metadata["user_api_key_team_id"],
team_alias=standard_metadata["user_api_key_team_alias"],
exception_status=str(getattr(original_exception, "status_code", None)),
- exception_class=str(original_exception.__class__.__name__),
+ exception_class=self._get_exception_class_name(original_exception),
tags=_tags,
)