Skip to content

fix(otel): record observed first-chunk timing for pass-through streams - #45590

Open
hiteshPrabhu wants to merge 1 commit into
BerriAI:mainfrom
hiteshPrabhu:fix_passthrough_ttft_observation
Open

hiteshPrabhu wants to merge 1 commit into
BerriAI:mainfrom
hiteshPrabhu:fix_passthrough_ttft_observation

Conversation

@hiteshPrabhu

@hiteshPrabhu hiteshPrabhu commented Oct 9, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Pass-through streams omit OTel first-chunk timing
  • Premature success logging can seed a misleading timestamp

How it solves it:

  • Resolve streaming state from actual boolean fields
  • Stamp the first nonempty chunk once
  • Defer passthrough success logging until stream consumption

User Flow

Before: a streamed response succeeds without first-chunk timing

  1. Send POST http://localhost:4000/bedrock/model/example/converse-stream with a synthetic message
  2. Receive HTTP 200 and the streamed response
  3. Inspect telemetry: first-chunk timing is absent

After: telemetry measures when the first chunk arrives

  1. Send POST http://localhost:4000/bedrock/model/example/converse-stream with the same synthetic message
  2. Receive HTTP 200 and the unchanged streamed response
  3. Inspect telemetry: one TTFT measurement agrees with the span

Relevant issues

Fixes #45588

Related: #30384 concerns a different generic proxy streaming handler; #31385 and #32284 cover Messages/Responses timing

Pre-Submission checklist

  • Added meaningful first-chunk and callback-lifecycle regressions
  • Relevant local test files pass
  • Reported CI and patch coverage checks pass at the current head
  • Scope is limited to pass-through first-chunk timing
  • Greptile confidence is at least 4/5 before maintainer review

Tests

On this independent branch, tests/unit/integrations/otel/ plus tests/unit/passthrough/: 1,102 passed

The decorated async route regression uses real Logging, real OTel recording and an injected external HTTP transport. It failed before the dispatch correction and passes afterward. It checks unchanged bytes, no premature timestamp, once-only first-chunk observation and one terminal callback

Additional tests cover sync/async wrappers, send/asend, existing observations, empty/unconsumed streams, boolean precedence, missing/negative/non-finite timing, and metric/span parity. Independent local review findings were addressed

Combined-patch strict Ruff, type-discipline and test-quality delta gates passed. Expanded utility tests also exposed three retry failures reproducible on the unchanged baseline; they are not represented as passing

Screenshots / Proof of Fix

Native real-provider proof is pending. The evidence below uses a real local proxy, a scripted Bedrock HTTP upstream and a local OTLP receiver. No paid provider was called

Shared setup: the synthetic configuration in #45588. The upstream delays its first event-stream bytes by 150 ms, then completes about 650 ms later

curl -sS -N http://localhost:4000/bedrock/model/example/converse-stream \
  -H 'Content-Type: application/json' \
  -d '{"messages":[{"role":"user","content":[{"text":"synthetic test"}]}]}'

Before (63a4f3f)

  1. Send the synthetic request and inspect the OTLP receiver
  2. Observe HTTP 200 and unchanged bytes, but no TTFT metric or first-chunk span attribute

After (05b8c3c)

  1. Repeat the same request and inspect the OTLP receiver
  2. Observe HTTP 200, unchanged bytes, and one TTFT observation at 0.155568838 seconds, matching the span and preceding response completion

Type

Bug Fix

Caveats

Medium

  • Native real-provider proof remains pending
  • The CLA bot still reports an unsigned agreement
  • Existing synchronous OTel v2 export support is unchanged
  • This measures first nonempty chunk arrival, not semantic token parsing
  • Provider-label attribution is a separate fix, not included here

Final Attestation

  • Final upstream checks and real-provider proof are complete

@CLAassistant

CLAassistant commented Oct 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing hiteshPrabhu:fix_passthrough_ttft_observation (05b8c3c) with main (63a4f3f)

Open in CodSpeed

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hiteshPrabhu
hiteshPrabhu marked this pull request as ready for review October 12, 2026 04:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T04:48:19.767432Z 05b8c3c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05b8c3c70a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

await GLOBAL_LOGGING_WORKER.flush()
assert logging.model_call_details["stream"] is True
assert logging.completion_start_time is None
assert await anext(response) == first

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Inject a deterministic clock into timing tests

The first-chunk tests consume datetime.now() directly, so wall-clock jumps can change pass/fail outcomes; inject a deterministic clock for unit coverage

AGENTS.md reference: tests/unit/AGENTS.md:L3-L3

Useful? React with 👍 / 👎.



def _resolved_bool(value: object) -> bool | None:
"""``value`` as a real bool; never truthifies a string like "false"."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the redundant helper docstring

This helper docstring merely restates the return expression; remove it because comments are reserved for complex business logic, tooling directives, or TODOs

AGENTS.md reference: AGENTS.md:L1-L7

Useful? React with 👍 / 👎.

Comment on lines +187 to +189
chunk: Final = await self._iterator.asend(value)
_stamp_first_chunk_if_needed(self._litellm_logging_obj, chunk)
return chunk

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Collect chunks returned by send and asend

send(None) and asend(None) timestamp but never collect their chunks, so one-chunk streams export no TTFT; added tests check only internal state

AGENTS.md reference: AGENTS.md:L24-L24

Useful? React with 👍 / 👎.

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.

[Bug]: OTel v2 omits first-chunk timing on streaming pass-through requests

2 participants