Repository navigation
feat: export request TTFB, stream duration, TTFT and token throughput - #24
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
The existing OTLP pipeline reports token usage and inference lifetime but cannot distinguish HTTP ingress latency, full response stream lifetime, first generated output, or per-request throughput. Add five gateway-specific histograms and numeric per-request log/span fields using the existing OTLP configuration.
codex_api.http.time_to_first_bytecodex_api.http.request.durationcodex_api.inference.time_to_first_tokencodex_api.inference.output_tokens_per_secondcodex_api.inference.durationHTTP request lifecycle
An outer middleware starts before authorization, request body reads/decompression, validation, concurrency waiting and upstream setup/retries. A response-body wrapper stops total duration at the final frame/EOF rather than when response headers return, preserving frames, trailers, size hints and backpressure. Normal exhaustion, body errors and early drops produce distinct
completed,body_errorandcancelledoutcomes. Fully consumed HTTP error responses retain their actual status and havecompletedbody outcome. Empty and HEAD responses complete at headers. HTTP 101 upgrades useupgradedand measure only the handshake, not socket lifetime.All router requests, including rejected requests and non-inference endpoints, generate separate
codex_api.http.requestlogs/server spans withttfb_ms,total_duration_ms, method, matched route, status and outcome. Cancellation before headers has no TTFB or status. HTTP request IDs are independent of inference usage IDs; supplied W3C parent trace context is honored. Histogram dimensions are limited to bounded method/route/status/outcome values, excluding raw paths and identifiers.TTFB means application response headers ready, not the first body chunk or actual network delivery. HTTP timers exclude connection acceptance, TLS and request header parsing before middleware dispatch. Stream duration ends at application-observed completion/drop; socket/proxy buffering and actual client receipt are outside this measurement.
Inference measurements
Responses HTTP/SSE, native aliases, compact inference and generating WebSocket turns produce usage logs with
inference_duration_ms, plusttft_msandtpswhen available. Existing full-guard-lifetime duration metrics remain unchanged. HTTP SSE timestamps are captured before internal channel delivery and freeze on the first terminal event. WebSocket response attribution uses explicit response IDs, bounded item-ID mappings and unambiguous lanes; duplicate terminals and ambiguous/unknown-item deltas do not produce duplicate or misassigned TTFT samples.TTFT measures gateway-observed first generated content, not server-internal prefill time. TPS includes initial wait and reported reasoning tokens; it is overall inference throughput, not decode-only speed, and never estimates tokens from text or chunks. Failed/incomplete/cancelled/missing-usage/zero-token/zero-duration responses omit TPS. Inference clocks exclude HTTP upload/validation and WebSocket handshake, which are separately covered by the HTTP request metrics. Standalone images/search, audio, Realtime and generic proxies receive HTTP lifecycle metrics but no synthetic TTFT/TPS. No prompts, generated content, tool arguments or credentials are exported, and identifiers remain outside metric dimensions.
Validation
cargo test --workspace --locked: 317 passed, 0 failed, 12 ignored. Optional real-account/client/source-audit cases were not run locally.cargo fmt --all -- --checkandgit diff --checkpass.