mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
feat(prometheus): add api_provider label to spend metric (#25693)
* feat(prometheus): add api_provider label to spend metric Add `api_provider` to `litellm_spend_metric` labels so users can build Grafana dashboards that break down spend by cloud provider (e.g. bedrock, anthropic, openai, azure, vertex_ai). The `api_provider` label already exists in UserAPIKeyLabelValues and is populated from `standard_logging_payload["custom_llm_provider"]`, but was not included in the spend metric's label list. * add api_provider to requests metric + add test Address review feedback: - Add api_provider to litellm_requests_metric too (same call-site as spend metric, keeps label sets in sync) - Add test_api_provider_in_spend_and_requests_metrics following the existing pattern in test_prometheus_labels.py
This commit is contained in:
parent
9a8daab454
commit
97092ab4c0
2 changed files with 17 additions and 0 deletions
|
|
@ -396,6 +396,7 @@ class PrometheusMetricLabels:
|
|||
UserAPIKeyLabelNames.CLIENT_IP.value,
|
||||
UserAPIKeyLabelNames.USER_AGENT.value,
|
||||
UserAPIKeyLabelNames.MODEL_ID.value,
|
||||
UserAPIKeyLabelNames.API_PROVIDER.value,
|
||||
]
|
||||
|
||||
litellm_spend_metric = [
|
||||
|
|
@ -410,6 +411,7 @@ class PrometheusMetricLabels:
|
|||
UserAPIKeyLabelNames.CLIENT_IP.value,
|
||||
UserAPIKeyLabelNames.USER_AGENT.value,
|
||||
UserAPIKeyLabelNames.MODEL_ID.value,
|
||||
UserAPIKeyLabelNames.API_PROVIDER.value,
|
||||
]
|
||||
|
||||
litellm_input_tokens_metric = [
|
||||
|
|
|
|||
|
|
@ -69,6 +69,21 @@ def test_model_id_in_required_metrics():
|
|||
print(f"✅ {metric_name} contains model_id label")
|
||||
|
||||
|
||||
def test_api_provider_in_spend_and_requests_metrics():
|
||||
"""
|
||||
Test that api_provider label is present in spend and requests metrics
|
||||
so users can build spend-by-provider and request-count-by-provider dashboards.
|
||||
"""
|
||||
api_provider_label = UserAPIKeyLabelNames.API_PROVIDER.value
|
||||
|
||||
for metric_name in ["litellm_spend_metric", "litellm_requests_metric"]:
|
||||
labels = PrometheusMetricLabels.get_labels(metric_name)
|
||||
assert (
|
||||
api_provider_label in labels
|
||||
), f"Metric {metric_name} should contain api_provider label"
|
||||
print(f"✅ {metric_name} contains api_provider label")
|
||||
|
||||
|
||||
def test_user_email_label_exists():
|
||||
"""Test that the USER_EMAIL label is properly defined"""
|
||||
assert UserAPIKeyLabelNames.USER_EMAIL.value == "user_email"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue