fix(bugbot): preserve "BudgetExceededError" Prometheus label

Adding llm_provider to BudgetExceededError (so callbacks get provider
attribution from StandardLoggingPayload) made the provider-prefix step in
_get_exception_class_name silently flip the label from "BudgetExceededError"
to e.g. "Openai.BudgetExceededError", breaking dashboards keyed on the
historical value.

Short-circuit BudgetExceededError in _get_exception_class_name the same way
ProxyRateLimitError already is. Provider/category attribution still lands on
the new rate_limit_category / rate_limit_type labels.
This commit is contained in:
mateo-berri 2026-05-14 21:05:09 +00:00
parent 7747ad050f
commit 2621f368cd
No known key found for this signature in database
2 changed files with 44 additions and 0 deletions

View file

@ -2669,6 +2669,23 @@ class PrometheusLogger(CustomLogger):
):
return "HTTPException"
# Same back-compat reasoning for ``BudgetExceededError``: the unified
# rate-limit error work attached ``.llm_provider`` to budget errors
# too (so callbacks reading ``StandardLoggingPayload`` get provider
# attribution). Without this short-circuit, the provider prefix below
# would silently flip the label from "BudgetExceededError" to e.g.
# "Openai.BudgetExceededError" and break dashboards keyed on the
# original value.
try:
from litellm.exceptions import BudgetExceededError
except ImportError:
BudgetExceededError = None # type: ignore[assignment,misc]
if BudgetExceededError is not None and isinstance(
exception, BudgetExceededError
):
return "BudgetExceededError"
exception_class_name = ""
if hasattr(exception, "llm_provider"):
exception_class_name = getattr(exception, "llm_provider") or ""

View file

@ -1096,5 +1096,32 @@ def test_prometheus_exception_class_name_back_compat_for_proxy_rate_limit_error(
assert PrometheusLogger._get_exception_class_name(exc_no_model) == "HTTPException"
def test_prometheus_exception_class_name_back_compat_for_budget_exceeded_error():
"""
The unified rate-limit work also attached ``.llm_provider`` to
``BudgetExceededError`` so callbacks get provider attribution from
``StandardLoggingPayload``. Without a back-compat short-circuit the
provider-prefix step in ``_get_exception_class_name`` would silently
flip the label from ``"BudgetExceededError"`` to e.g.
``"Openai.BudgetExceededError"`` and break dashboards keyed on the
historical value. Pin the literal label here.
"""
from litellm.integrations.prometheus import PrometheusLogger
err = litellm.BudgetExceededError(
current_cost=1.0,
max_budget=0.5,
llm_provider="openai",
)
assert PrometheusLogger._get_exception_class_name(err) == "BudgetExceededError"
# Default (empty llm_provider) path — same literal label.
err_no_provider = litellm.BudgetExceededError(current_cost=1.0, max_budget=0.5)
assert (
PrometheusLogger._get_exception_class_name(err_no_provider)
== "BudgetExceededError"
)
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-vv", "-x"]))