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]

Merge pull request #25256 from BerriAI/litellm_ishaan_april6

ishaan-berri1c128a86b811
diff --cc litellm/integrations/prometheus.py
index 613c354e42b,d5fde2a4864..1d92a9da073
--- a/litellm/integrations/prometheus.py
+++ b/litellm/integrations/prometheus.py
@@@ -1781,25 -1771,27 +1785,27 @@@ class PrometheusLogger(CustomLogger)
client_ip=_metadata.get("requester_ip_address"),
user_agent=_metadata.get("user_agent"),
model_id=model_id,
- stream=str(request_data.get("stream"))
- if litellm.prometheus_emit_stream_label
- else None,
+ stream=(
+ str(request_data.get("stream"))
+ if litellm.prometheus_emit_stream_label
+ else None
+ ),
)
- _labels = prometheus_label_factory(
- supported_enum_labels=self.get_labels_for_metric(
- metric_name="litellm_proxy_failed_requests_metric"
- ),
- enum_values=enum_values,
+ _label_ctx = PrometheusLabelFactoryContext(enum_values)
+ PrometheusLogger._inc_labeled_counter(
+ self,
+ self.litellm_proxy_failed_requests_metric,
+ "litellm_proxy_failed_requests_metric",
+ enum_values,
+ label_context=_label_ctx,
)
- self.litellm_proxy_failed_requests_metric.labels(**_labels).inc()
-
- _labels = prometheus_label_factory(
- supported_enum_labels=self.get_labels_for_metric(
- metric_name="litellm_proxy_total_requests_metric"
- ),
- enum_values=enum_values,
+ PrometheusLogger._inc_labeled_counter(
+ self,
+ self.litellm_proxy_total_requests_metric,
+ "litellm_proxy_total_requests_metric",
+ enum_values,
+ label_context=_label_ctx,
)
- self.litellm_proxy_total_requests_metric.labels(**_labels).inc()
except Exception as e:
verbose_logger.exception(
@@@ -3419,11 -3409,12 +3425,11 @@@
It emits the current remaining budget metrics for all Keys and Teams.
"""
from litellm.constants import PROMETHEUS_BUDGET_METRICS_REFRESH_INTERVAL_MINUTES
- from litellm.integrations.custom_logger import CustomLogger
- prometheus_loggers: List[
- CustomLogger
- ] = litellm.logging_callback_manager.get_custom_loggers_for_type(
- callback_type=PrometheusLogger
+ prometheus_loggers: List[CustomLogger] = (
+ litellm.logging_callback_manager.get_custom_loggers_for_type(
+ callback_type=PrometheusLogger
+ )
)
# we need to get the initialized prometheus logger instance(s) and call logger.initialize_remaining_budget_metrics() on them
verbose_logger.debug("found %s prometheus loggers", len(prometheus_loggers))