Skip to content

fix(otel): honor metric export interval - #38055

Draft
daleselaji-dev wants to merge 1 commit into
BerriAI:mainfrom
daleselaji-dev:codex/otel-metric-interval-38052
Draft

daleselaji-dev wants to merge 1 commit into
BerriAI:mainfrom
daleselaji-dev:codex/otel-metric-interval-38052

Conversation

@daleselaji-dev

Copy link
Copy Markdown
Contributor

Problem

LiteLLM's OpenTelemetry v2 metric reader hardcodes a 5-second export interval. This prevents deployments from using the standard OTEL_METRIC_EXPORT_INTERVAL environment variable and causes cumulative metric series to be re-exported more frequently than operators can control.

Root Cause

build_metric_reader passes export_interval_millis=5000 explicitly to PeriodicExportingMetricReader, overriding the OpenTelemetry SDK's environment-driven default.

Solution

Let the OpenTelemetry SDK construct the reader with its standard interval resolution, including OTEL_METRIC_EXPORT_INTERVAL.

Changes

  • Removed the hardcoded interval override from the OTel v2 metric reader.
  • Added a regression test proving the standard environment variable is honored.
  • Updated the function documentation to describe the SDK-controlled interval.

Testing

  • Baseline focused OTel metric-reader test: 1 passed.
  • Final focused OTel metric-reader tests: 2 passed.
  • Full test_otel_v2_components.py: 59 passed.
  • Ruff check passed for the changed source and test file.
  • Ruff format passed for the changed source file; the existing test file has unrelated repository formatting differences under the current Ruff version.
  • git diff --check passed.
  • Basedpyright was attempted; it remains blocked by two pre-existing Any diagnostics in the touched source at lines 229 and 251, outside this diff.
  • No live provider or collector credentials were required.

Compatibility/Risk

The SDK default remains the effective fallback when the environment variable is absent. Existing deployments that relied on the previous 5-second value retain that behavior through the OpenTelemetry SDK default; deployments that set the standard variable can now control the interval.

Notes for Reviewer

The change is limited to the OTel v2 metric-reader constructor. The regression uses the console exporter and a mocked environment variable, so it does not contact an external collector.

Linked Issue

Fixes #38052

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing daleselaji-dev:codex/otel-metric-interval-38052 (d0e802d) with litellm_internal_staging (d447be1)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (f005afa) during the generation of this report, so d447be1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:44
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTel v2: metric reader hardcodes a 5s export interval; with cumulative histograms (#35060) every series is re-shipped 12×/min regardless of traffic

3 participants