feat(prometheus): configure deployment caller identity - #38221
Conversation
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThe PR adds configurable alias, email, or combined caller identity labels for nine Prometheus deployment and latency metric families while retaining alias-only behavior by default.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/types/integrations/prometheus.py | Defines caller-identity modes, validation, and mode-dependent label-schema resolution for the targeted metrics. |
| litellm/integrations/prometheus.py | Validates configuration during logger initialization and propagates fallback email identity into deployment-failure metric labels. |
| litellm/proxy/proxy_server.py | Applies and validates the caller-identity setting before callback construction. |
| litellm/init.py | Adds the public setting with the backward-compatible api_key_alias default. |
| tests/test_litellm/integrations/test_prometheus_caller_identity.py | Covers all identity modes, real registry samples, failure fallback precedence, exclusions, validation, and callback initialization order. |
Reviews (6): Last reviewed commit: "fix(prometheus): validate caller identit..." | Re-trigger Greptile
|
@greptileai review latest head |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a3ce23e. Configure here.
|
@mphilippnv |
|
Good catch. The original seven were deliberate only in that they matched the families observed and listed in #38159; there was no semantic reason to exclude these two. Both are emitted from I added @greptileai review latest head |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9b331ae. Configure here.
|
@greptileai review latest head |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cc89ded. Configure here.
c9b9d81 to
1e3ab6a
Compare
|
@greptileai review latest head |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1e3ab6a. Configure here.
…ster Fail config load on an invalid prometheus_deployment_and_latency_caller_identity value (including null) and on include_labels entries the selected mode removes from a target metric, instead of booting green with an empty /metrics. Validate the mode at the top of PrometheusLogger.__init__ so an invalid value raises before any collector lands in the process-global registry, keeping retries free of duplicated-timeseries errors. Label-validation errors now name the mode setting alongside the rejected label.
1e3ab6a to
cdaaf40
Compare
|
@greptileai review latest head |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cdaaf40. Configure here.
|
Hi @mphilippnv, I hit one failure mode while live-testing this PR and pushed a small fix to your branch in cdaaf40. Hope that’s okay. Happy to move it to a follow-up if you prefer. A bad value for the new setting (user-email, YAML on/null) could let the proxy boot successfully while silently disabling all Prometheus metrics. The same happened when user_email mode conflicted with an existing include_labels: [api_key_alias]. The commit makes these fail fast instead:
Valid configs are unchanged. I verified all three modes on a live proxy with a real key/email/provider, plus the failure cases above. |
e52f055
into
BerriAI:litellm_internal_staging
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a proxy operator cannot build an email-scoped deployment dashboard
prometheus_deployment_and_latency_caller_identity: user_emailand restart the proxyPOST https://litellm.example.com/v1/chat/completionswith a virtual key linked to an emailGET https://litellm.example.com/metricsand the nine deployment/latency families still exposeapi_key_alias, notuser_emailAfter: the same configuration exposes the resolved email on those families
prometheus_deployment_and_latency_caller_identity: user_emailand restart the proxyPOST https://litellm.example.com/v1/chat/completionswith a virtual key linked to an emailGET https://litellm.example.com/metricsand the nine deployment/latency families exposeuser_email, including early failure countersRelevant issues
Closes #38159
Companion documentation: BerriAI/litellm-docs#1012
Linear ticket
Pre-Submission checklist
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Shared setup: each case ran in a clean Python process with the public setting set to
user_email, a realPrometheusLogger, one emitted request outcome, and a scrape ofprometheus_client.REGISTRY. No mocks or network providers were used.Before (bb27bfd)
Successful request
origin/litellm_internal_staginglitellm_deployment_total_requests_total{...,api_key_alias="dashboard-user",...} 1.0;user_emailis absentDeployment failure using UserAPIKeyAuth fallback
UserAPIKeyAuth.user_email, then scrape the registrylitellm_deployment_failure_responses_total{...,api_key_alias="dashboard-user",...} 1.0;user_emailis absentAfter (9b331ae)
Successful request
litellm_deployment_total_requests_total{...,user_email="alice@example.com",...} 1.0;api_key_aliasis absentDeployment failure using UserAPIKeyAuth fallback
litellm_deployment_failure_responses_total{...,user_email="fallback@example.com",...} 1.0;api_key_aliasis absentType
🆕 New Feature
✅ Test
Caveats (if any)
Final Attestation
Note
Medium Risk
Changing Prometheus label names on core deployment/latency metrics can break dashboards and recording rules; default
api_key_aliaspreserves behavior, butuser_email/bothexpose PII and require process restart.Overview
Adds
prometheus_deployment_and_latency_caller_identity(api_key_aliasdefault,user_email, orboth) so nine deployment/latency Prometheus families can label callers by API key alias, user email, or both instead of always usingapi_key_alias.Label schemas are resolved in
PrometheusMetricLabels.get_labelswithout mutating class-level lists; invalid modes fail atPrometheusLoggerinit and when the proxy loadslitellm_settings(before Prometheus callbacks).user_emailmode rejectsprometheus_metrics_configthat stillinclude_labelsapi_key_aliason those metrics.PrometheusLoggernow resolvesuser_emailfrom standard logging metadata, litellm params, orUserAPIKeyAuth, including deployment failure paths. Comprehensive tests cover schema modes, boot order, and scraped samples.Reviewed by Cursor Bugbot for commit cdaaf40. Bugbot is set up for automated code reviews on this repo. Configure here.