Skip to content

Commit 0bfa9b7

Browse files
committed
Route failure path through shared bounded-tracking guard
The failure path in async_log_failure_event manually inlined the bounded tracking logic and bypassed the shared _track_bounded_prometheus_metric_series guard. When label filters strip end_user from litellm_llm_api_failed_requests_metric, the inlined logic still tracked the full 8-tuple, which would later fail to evict correctly. Route through _inc_labeled_counter so the failure path uses the same label filtering and bounded tracking as the success path.
1 parent 9d91af6 commit 0bfa9b7

1 file changed

Lines changed: 12 additions & 32 deletions

File tree

litellm/integrations/prometheus.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,40 +1621,20 @@ async def async_log_failure_event(self, kwargs, response_obj, start_time, end_ti
16211621
)
16221622

16231623
try:
1624-
_failed_request_label_values = (
1625-
_sanitize_prometheus_label_value(end_user_id),
1626-
_sanitize_prometheus_label_value(user_api_key),
1627-
_sanitize_prometheus_label_value(user_api_key_alias),
1628-
_sanitize_prometheus_label_value(model),
1629-
_sanitize_prometheus_label_value(user_api_team),
1630-
_sanitize_prometheus_label_value(user_api_team_alias),
1631-
_sanitize_prometheus_label_value(user_id),
1632-
_sanitize_prometheus_label_value(
1633-
standard_logging_payload.get("model_id", "")
1624+
self._inc_labeled_counter(
1625+
counter=self.litellm_llm_api_failed_requests_metric,
1626+
metric_name="litellm_llm_api_failed_requests_metric",
1627+
enum_values=UserAPIKeyLabelValues(
1628+
end_user=end_user_id,
1629+
hashed_api_key=user_api_key,
1630+
api_key_alias=user_api_key_alias,
1631+
model=model,
1632+
team=user_api_team,
1633+
team_alias=user_api_team_alias,
1634+
user=user_id,
1635+
model_id=standard_logging_payload.get("model_id", ""),
16341636
),
16351637
)
1636-
self.litellm_llm_api_failed_requests_metric.labels(
1637-
*_failed_request_label_values
1638-
).inc()
1639-
if end_user_id is not None:
1640-
self._bounded_prometheus_series_tracker.track_series(
1641-
metric=self.litellm_llm_api_failed_requests_metric,
1642-
metric_name="litellm_llm_api_failed_requests_metric",
1643-
label_values=_failed_request_label_values,
1644-
max_series=getattr(
1645-
litellm,
1646-
"prometheus_end_user_metrics_max_series_per_metric",
1647-
10000,
1648-
),
1649-
ttl_seconds=getattr(
1650-
litellm, "prometheus_end_user_metrics_ttl_seconds", 3600.0
1651-
),
1652-
cleanup_interval_seconds=getattr(
1653-
litellm,
1654-
"prometheus_end_user_metrics_cleanup_interval_seconds",
1655-
60.0,
1656-
),
1657-
)
16581638
self.set_llm_deployment_failure_metrics(kwargs)
16591639
await self._set_org_budget_metrics_after_api_request(
16601640
org_id=user_api_key_org_id,

0 commit comments

Comments
 (0)