Repository navigation
fix(otel): histogram bucket boundaries - #44619
ArjunXvarma wants to merge 12 commits into
Conversation
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
1a1d940 to
d67988b
Compare
|
|
Note on the failing This check fails on two environment variables:
No other checks are affected. |
The metric bucket constants were taken from the gen-ai-token-metrics.md and gen-ai-metrics.md files from the open telemetry semantic convetions for gen ai repository. The token cost constant was not considered because the gen ai semantic conventions do not define any boundaries for it
Add tests for GenAI histogram bucket boundaries - test_histograms_use_semconv_bucket_boundaries: each GenAI histogram exports the semconv boundaries from MetricBuckets, and records at least one data point so the check cannot pass vacuously. - test_operator_view_overrides_default_boundaries: the boundaries are passed as an advisory, so an operator-configured View still takes precedence. - test_distinct_latencies_land_in_distinct_buckets: a 0.3 s and a 4.9 s call land in different duration buckets; with the SDK's ms-sized defaults both fell into (0, 5]. - test_bucket_boundaries_are_positive_and_strictly_increasing: guards the constants against typos when they are updated to a new spec revision.
…n opentelemetry-api < 1.30.0
…ONV_HISTOGRAM_BUCKETS
…ONV_HISTOGRAM_BUCKETS
…a v1 config directly
846cbed to
f1899ff
Compare
|
The 4 CI failures are only the env-key docs check; the variable is documented in BerriAI/litellm-docs#2113, and CI will pass once it merges |
TLDR
Problem this solves:
How it solves it:
LITELLM_OTEL_SEMCONV_HISTOGRAM_BUCKETS, defaultfalseOff by default because changing bucket layouts breaks percentile continuity with data already stored. Happy to flip the default to
trueif maintainers prefer shipping the fix on by defaultUser Flow
Before: an operator charting LLM latency sees the same percentiles no matter how fast requests are
gen_ai.client.operation.durationAfter: the operator opts in and the same chart reflects real latency
LITELLM_OTEL_SEMCONV_HISTOGRAM_BUCKETS=trueand restart the proxy with the same exportergen_ai.client.operation.durationOperators who don't set the variable see no change after upgrading
Relevant issues
Fixes #44558
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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
Live proxy on localhost:4000 with the default OTel engine, real calls to Gemini (
gemini-3.5-flash-lite), and metrics printed by the OTel console exporter every 5 s. Each run sends the same four requests, asking for 5, 60, 250 and 500 words so latencies spread from about 1 s to 4 s, then reads everygen_ai.client.operation.durationdata point from the proxy logShared setup,
config.yaml:Start command (the flag line is added or removed per case):
Requests:
Reading the histogram after the next export:
Every request lands in its own data point because the default metric attributes include per-request metadata. That is existing behavior and unrelated to this PR
Before (d4619c4)
Flag on
LITELLM_OTEL_SEMCONV_HISTOGRAM_BUCKETS=true, which this commit does not read yetRequests taking 1.1 s and 3.4 s all land in the same (0, 5] bucket, so p50 and p95 can't tell them apart
After (df1fbe8)
Flag unset (default)
LITELLM_OTEL_SEMCONV_HISTOGRAM_BUCKETSSame boundaries and bucketing as Before, so upgrading without opting in changes nothing
Flag on
LITELLM_OTEL_SEMCONV_HISTOGRAM_BUCKETS=trueThe semconv boundaries apply, and the requests spread across (0.64, 1.28], (1.28, 2.56] and (2.56, 5.12], so percentiles now track real latency
Type
Bug Fix
Test
Caveats (if any)
Medium
test_env_keys.pyfails in CI until that PR mergesLow
gen_ai.usage.costkeeps the SDK defaults