feat(prometheus): add call_type label to request lifecycle metrics - #34717
Open
Bungic wants to merge 1 commit into
Open
feat(prometheus): add call_type label to request lifecycle metrics#34717Bungic wants to merge 1 commit into
Bungic wants to merge 1 commit into
Conversation
Contributor
Greptile SummaryAdds normalized
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/integrations/prometheus.py | Normalizes async call types and supplies the resulting label at success, proxy-failure, and deployment-failure population sites. |
| litellm/types/integrations/prometheus.py | Adds the call_type label and value field to the intended request lifecycle metric definitions while excluding deployment and quota gauges. |
| tests/test_litellm/integrations/test_prometheus_labels.py | Adds coverage for metric allow-lists, async normalization, enum coverage, gauge exclusions, and rendered Prometheus output. |
Reviews (2): Last reviewed commit: "feat(prometheus): add call_type label to..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Chat completions, embeddings, image generation and audio all land in the same litellm_requests_metric and litellm_spend_metric series today. Embedding traffic is usually orders of magnitude higher volume and orders of magnitude lower cost than chat, so mixing them makes both the request rate and the spend series hard to reason about. The value is already on standard_logging_payload as call_type, so this is label plumbing rather than new collection. Async and sync entry points report different call types for the same operation, acompletion against completion, and the proxy is async while the SDK usually is not. Emitting both spellings would split every proxy's chat traffic in two, so each async call type is collapsed onto its sync twin. The alias table is derived from CallTypes at import time and matches on member names rather than values: stripping a leading "a" from the value would turn add_message into dd_message and anthropic_messages into nthropic_messages, both of which are sync call types that legitimately start with one. 16 metrics gain the label. Remaining-quota gauges and the configured tpm/rpm limits deliberately do not, since headroom belongs to a deployment rather than to a call type and splitting it would emit several series each claiming to describe the same number. A test pins that exclusion. Same shape as BerriAI#32126, which added api_provider to the metrics emitted from call sites that already held the value.
Bungic
force-pushed
the
prometheus-call-type-label
branch
from
July 26, 2026 15:11
4d70641 to
041ce5f
Compare
Author
|
Re-requesting after a push. The only change since the last review is two type annotations in |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
litellm_requests_metricand onelitellm_spend_metricseriesHow it solves it:
call_typelabel to the 16 request lifecycle metricsacompletionandcompletiondo not become two seriesThe value is already on
standard_logging_payloadascall_type, so this is label plumbing rather than new collectionSame shape as #32126, which added
api_providerto the metrics that were emitted from call sites already holding the value. Part of #34704The async spelling
CallTypesnames every async variant after its sync one, and the proxy is async while the SDK usually is not. Left alone, one proxy's chat traffic would be labelledacompletionand an SDK user's would becompletion, which splits the same operation across two seriesThe alias table is derived from
CallTypesat import time, so a new call type is covered without editing the integration. It matches on member names rather than values on purpose: stripping a leadingafrom the value turnsadd_messageintodd_messageandanthropic_messagesintonthropic_messages, and both of those are sync call types that legitimately start with one. There is a test for eachRelevant issues
Part of #34704
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Two deployments on a local proxy, one chat and one embedding. The deployments use
mock_responseso the run costs nothing; the label is read offstandard_logging_payload, so the provider's answer has no bearing on itThree chat calls and two embedding calls, then scrape:
After, with the labels trimmed to the interesting ones:
Before, both rows collapse into series that differ only by model name, with nothing to group or filter on. Note the proxy served these asynchronously and the label still reads
completion, which is the normalisation doing its jobType
🆕 New Feature
Changes
litellm/types/integrations/prometheus.py:UserAPIKeyLabelNames.CALL_TYPE, acall_typefield onUserAPIKeyLabelValues, and the label added to 16 metric label listslitellm/integrations/prometheus.py:_build_async_call_type_aliases()builds the async to sync table fromCallTypesat import time,_normalize_call_type()applies it, and the value is populated at the three sites that already resolve the payload:async_log_success_event,set_llm_deployment_failure_metricsandasync_post_call_failure_hooktests/test_litellm/integrations/test_prometheus_labels.py: extended with allow-list assertions, the normalisation table, a check that every async member ofCallTypesis covered, and an end to end assertion that reads the label back off a rendered sampleRemaining quota gauges and the configured tpm/rpm limits deliberately do not get the label, since headroom belongs to a deployment rather than to a call type; splitting it would emit several series each claiming to describe the same number. There is a test pinning that
QA runbook
chat-demoand a few embeddings toembed-democurl -sL -H "Authorization: Bearer sk-1234" http://localhost:4000/metrics | grep "^litellm_requests_metric_total{"should show two series, onecall_type="completion"and onecall_type="embedding"Final Attestation