Add production startup and TTFT telemetry#22198
Open
mzeng-openai wants to merge 2 commits into
Open
Conversation
owenlin0
reviewed
May 11, 2026
| "thread_start_create_thread", | ||
| create_thread_started_at.elapsed(), | ||
| Some("ready"), | ||
| ); |
Collaborator
There was a problem hiding this comment.
why call it done here instead of at the bottom of the method?
| } | ||
|
|
||
| #[test] | ||
| fn otel_export_routing_policy_routes_startup_and_ttft_observability() { |
owenlin0
approved these changes
May 11, 2026
Collaborator
owenlin0
left a comment
There was a problem hiding this comment.
small comments but preapproving
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.
Why
While investigating
codex exec histartup latency, the useful questions were not "is startup slow?" but "which durable bucket is slow in production?"The path we observed has a few distinct stages:
thread/startcreates the sessionBefore this PR, production telemetry had some of the raw measurements already:
But there was no coherent production event stream for the startup breakdown itself, and TTFT was metric-only. That made it hard to answer the same latency questions from OpenTelemetry-backed logs without adding one-off local instrumentation.
What changed
Add durable production telemetry on the existing
SessionTelemetrypath:codex.startup_phaseOTel log/trace events pluscodex.startup.phase.duration_mscodex.turn_ttftOTel log/trace events while preserving the existing TTFT metricThe startup phase event is emitted for the coarse buckets we actually observed while running
exec hi:thread_start_create_threadstartup_prewarm_totalstartup_prewarm_create_turn_contextstartup_prewarm_build_toolsstartup_prewarm_build_promptstartup_prewarm_websocket_warmupstartup_prewarm_resolveThese phases are intentionally low-cardinality so they remain safe as production telemetry tags.
Why this shape
This keeps the instrumentation on the same production path as the rest of the session telemetry instead of adding a local debug-only trace mode. It also avoids changing startup behavior:
One boundary is intentional: very early process bootstrap that happens before a session exists is not included here, because this PR uses session-scoped production telemetry. The expensive buckets we were trying to understand after
thread/startare now covered durably.Verification
cargo test -p codex-otelcargo test -p codex-core turn_timingcargo test -p codex-core regular_turn_emits_turn_started_without_waiting_for_startup_prewarmcargo test -p codex-core interrupting_regular_turn_waiting_on_startup_prewarm_emits_turn_abortedcargo test -p codex-app-server thread_startjust fix -p codex-otel -p codex-core -p codex-app-serverI also ran
cargo test -p codex-core; it built successfully and then hit an existing unrelated stack overflow intools::handlers::multi_agents::tests::tool_handlers_cascade_close_and_resume_and_keep_explicitly_closed_subtrees_closed.