Repository navigation
feat(diagnostics): measure gateway RPC latency phases - #138015
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Integrate main's preparation leases and start handler timing only after lazy preparation, final authorization fences, and the synchronous ownership handoff. Bind diagnostics in the existing request trace scope and remove obsolete early parent binding. Validated with 257 focused tests, 11 static checks, and independent P2 review with complete lifecycle source context. Current-main qualification against ed6e3aa preserves the touched preimages and reviewed owner contracts; behavior proof remains paired with 3ed226a.
|
Codex review: blocked before merge. Reviewed September 4, 2026, 8:54 AM ET / 12:54 UTC. ClawSweeper reviewWhat this changesThe PR records bounded Gateway WebSocket RPC timing phases and exports them through the OpenTelemetry and Prometheus diagnostics plugins. Merge readiness⛔ Blocked before merge - 1 item remains Keep open. This current maintainer-owned feature is not on current main; its dispatcher-to-exporter boundary is coherent and no actionable correctness defect was found in this review. Priority: P3 Review scores
Verification
How this fits togetherAuthenticated Gateway WebSocket requests enter the dispatcher, which handles admission, queueing, handler invocation, and responses. The PR records timing facts there and sends them through the existing diagnostic event bus to optional exporters. flowchart LR
A[WebSocket request] --> B[Authenticated dispatcher]
B --> C[Admission and queue]
C --> D[Gateway handler]
D --> E[Response sender]
B --> F[Diagnostic event bus]
F --> G[OpenTelemetry exporter]
F --> H[Prometheus exporter]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +340, Tests +1399, Docs +95. Total +1834 across 28 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded dispatcher-owned event producer and existing-bus exporters once normal exact-head checks complete, preserving the documented method-cardinality and trace-parent rules. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds diagnostic visibility rather than repairing a reported malfunction; its focused tests exercise the new request-to-exporter path. Is this the best way to solve the issue? Yes. Recording facts at the authenticated dispatcher and handler boundary, then reusing the existing diagnostics bus, avoids a parallel collector or protocol surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 390bef2077ea. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review The integration at 5bffdb4 follows the current request-entry owner: lazy handler-family preparation counts as admission, and handler timing begins after final authorization and lease handoff. The updated PR body records the failing prior-source reproductions, 257 passing integration tests, affected static checks, and independent review. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The phase ownership is well defined: admission ends at actual handler invocation, queue wait is a subset, handler time excludes lazy preparation, and first-response measures sender acceptance rather than client receipt. Method bucketing plus phase/outcome-only error labels is also the right cardinality discipline for Prometheus. I like that uninterested diagnostics consumers avoid observer/clock work entirely; keep the dropped-series and async-queue caveats prominent because they directly affect percentile interpretation.
|
Merged via squash.
|
* feat(diagnostics): measure gateway RPC latency phases * fix(diagnostics): keep gateway RPC event type internal
What Problem This Solves
Gateway response logs combine admission, queueing and handler work, while existing diagnostics exporters have no per-RPC timing producer. A slow request or early acknowledgment therefore cannot show whether time was spent waiting to start, executing its handler, or sending its first response.
Why This Change Was Made
Record these facts at the authenticated request dispatcher and concrete handler boundary, then reuse the existing diagnostic bus and OpenTelemetry/Prometheus exporters. First accepted send, handler settlement, dispatch rejection/cancellation and unavailable/suppressed delivery remain distinct. Supplied trace parents, including early denials, and explicit parent absence survive asynchronous execution without inheriting unrelated ambient traces.
The producer follows the request-entry lifetime introduced by #136998. Lazy router and handler-family preparation count as admission. Handler timing starts only after preparation, final authorization fences and synchronous lease handoff; a failed loader creates no handler sample. Shutdown still joins preparation and its error response, while executing handlers retain their existing owners. Main's request trace scope makes the earlier prebinding path unnecessary.
Production grows by 340 lines: Gateway producer +152, event/trace contracts +32, OTel export and signal gating +103, Prometheus export +45, and existing listener-interest consumers +8. This adds the missing producer and exporter capability; it introduces no active-span registry, collector, configuration key, dependency, persistent store, schema or protocol field. Test/support growth is +1,399 lines, including shared real-SDK fixtures and test relocation; docs +95.
User Impact
Existing exporter enablement exposes request counts and admission, start-queue, first-response and handler durations. Canonical core methods retain their names; other methods use fixed buckets. Outcomes aggregate by phase/outcome rather than multiplying method labels. Payloads, identities and raw errors are excluded. Enablement and metric semantics are documented in Prometheus diagnostics and OpenTelemetry export.
These are elapsed timings, not CPU profiles or proof of client receipt. Early acknowledgments and detached responses do not imply completed agent work. The existing 2,048 aggregate-sample Prometheus cap and async-event queue remain unchanged; drop counters must be checked before interpreting coverage. Existing samples continue updating when the cap fills. Inactive or uninterested consumers create no observer, clock read or registry lookup. Existing OTel
metrics:falseis honored even with a preloaded global SDK; traces-only and logs-only modes retain their contracts.Evidence
Validation is cumulative; the counts below overlap and do not claim one final whole-repository wrapper passed:
3ed226a746a8efd223a35a81790014c41ff044a3: 23 diagnostics cases, the real authenticated WebSocket/protected Prometheus/local OTLP case, and 233 adjacent lifecycle/router tests. Coverage includes preparation and credential-barrier shutdown, handler-initiated close, authorization, reconnect/cancellation, late responses, parent isolation and lazy handler families.5bffdb4cc5ea0de32eab7b61485f724cec34fc14.ed6e3aabf0ef6cd58a8ee9d9282a6dc6c06cc918. The 28-file candidate source manifest and paired proof remain pinned; later SDK budgets and separate test-acquisition helper changes are outside this paired execution proof. Source qualification is not a substitute for exact-head CI.Current-head validation and dependency review
Head
c8a1a33ea3c0911c9b004eb4a7f539134b4a37d8mechanically integrates main95815d895c153773f30f26a7bd2b53b7b7819b7fwith the same 28-file feature patch. Fresh final-tree proof passed 60 tests across six files, including the real authenticated WebSocket-to-Prometheus/OTLP flow and current request-entry/router contexts, plus the previously failing QA docs-reference case. Independent P2 found no actionable findings. Exact-head CI 33874530334 passed, includingopenclaw/ci-gate. The cumulative proof above remains preserved.The latest review's dependency-inspection gap is resolved by directly inspecting the frozen
@opentelemetry/api1.9.1 source/types and@opentelemetry/sdk-trace2.10.0 implementation:ROOT_CONTEXTis an empty context;startSpantakes its parent from the third context argument, and the SDK uses active context only when that argument is omitted. The RPC exporter supplies its validated explicit parent orROOT_CONTEXT. Existing parent-isolation tests and the fresh WebSocket/OTLP proof cover both paths. No source or dependency change was needed for that review-environment limitation.