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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(prometheus.py): fix metrics
Krrish Dholakiab05742e8144f
diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.pyindex 7da154d31e5..aa06ec99eb7 100644--- a/litellm/integrations/prometheus.py+++ b/litellm/integrations/prometheus.py@@ -215,40 +215,25 @@ class PrometheusLogger(CustomLogger):self.litellm_remaining_requests_metric = self._gauge_factory("litellm_remaining_requests","LLM Deployment Analytics - remaining requests for model, returned from LLM API Provider",- labelnames=[- "model_group",- "api_provider",- "api_base",- "litellm_model_name",- "hashed_api_key",- "api_key_alias",- ],+ labelnames=self.get_labels_for_metric(+ "litellm_remaining_requests_metric"+ ),)self.litellm_remaining_tokens_metric = self._gauge_factory("litellm_remaining_tokens","remaining tokens for model, returned from LLM API Provider",- labelnames=[- "model_group",- "api_provider",- "api_base",- "litellm_model_name",- "hashed_api_key",- "api_key_alias",- ],+ labelnames=self.get_labels_for_metric(+ "litellm_remaining_tokens_metric"+ ),)self.litellm_overhead_latency_metric = self._histogram_factory("litellm_overhead_latency_metric","Latency overhead (milliseconds) added by LiteLLM processing",- labelnames=[- "model_group",- "api_provider",- "api_base",- "litellm_model_name",- "hashed_api_key",- "api_key_alias",- ],+ labelnames=self.get_labels_for_metric(+ "litellm_overhead_latency_metric"+ ),buckets=LATENCY_BUCKETS,)# llm api provider budget metrics@@ -1160,6 +1145,7 @@ class PrometheusLogger(CustomLogger):enum_values: UserAPIKeyLabelValues,output_tokens: float = 1.0,):+try:verbose_logger.debug("setting remaining tokens requests metric")standard_logging_payload: Optional[StandardLoggingPayload] = (@@ -1292,7 +1278,7 @@ class PrometheusLogger(CustomLogger):).observe(latency_per_token)except Exception as e:- verbose_logger.error(+ verbose_logger.exception("Prometheus Error: set_llm_deployment_success_metrics. Exception occured - {}".format(str(e))diff --git a/litellm/types/integrations/prometheus.py b/litellm/types/integrations/prometheus.pyindex 358ff3d50bd..cdcc8807617 100644--- a/litellm/types/integrations/prometheus.py+++ b/litellm/types/integrations/prometheus.py@@ -71,6 +71,7 @@ class UserAPIKeyLabelNames(Enum):STATUS_CODE = "status_code"FALLBACK_MODEL = "fallback_model"ROUTE = "route"+ MODEL_GROUP = "model_group"DEFINED_PROMETHEUS_METRICS = Literal[@@ -161,7 +162,7 @@ class PrometheusMetricLabels:]litellm_overhead_latency_metric = [- UserAPIKeyLabelNames.REQUESTED_MODEL.value,+ UserAPIKeyLabelNames.MODEL_GROUP.value,UserAPIKeyLabelNames.API_PROVIDER.value,UserAPIKeyLabelNames.API_BASE.value,UserAPIKeyLabelNames.v2_LITELLM_MODEL_NAME.value,@@ -170,7 +171,7 @@ class PrometheusMetricLabels:]litellm_remaining_requests_metric = [- UserAPIKeyLabelNames.REQUESTED_MODEL.value,+ UserAPIKeyLabelNames.MODEL_GROUP.value,UserAPIKeyLabelNames.API_PROVIDER.value,UserAPIKeyLabelNames.API_BASE.value,UserAPIKeyLabelNames.v2_LITELLM_MODEL_NAME.value,@@ -179,7 +180,7 @@ class PrometheusMetricLabels:]litellm_remaining_tokens_metric = [- UserAPIKeyLabelNames.REQUESTED_MODEL.value,+ UserAPIKeyLabelNames.MODEL_GROUP.value,UserAPIKeyLabelNames.API_PROVIDER.value,UserAPIKeyLabelNames.API_BASE.value,UserAPIKeyLabelNames.v2_LITELLM_MODEL_NAME.value,