Repository navigation
feat(realtime): telemetry for the pub/sub event handler - #15113
ArnabChatterjee20k merged 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (2) — 🟢 2 low
This PR instruments the realtime event handler with observability: a stage-duration observable gauge, three counters (received, dropped, failed), and per-event spans in
Reviewed commit: a054079 |
🟢 Tier S · Ready to mergeThis change adds per-worker realtime event counters and a stage-duration gauge, records failures from the arrival and delivery-delay paths, and adds event spans. It also adds unit coverage for event counts, dropped payloads, span attributes, and the idle gauge state.
📂 Walkthrough · 5
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed |
bdcbb44
into
fix/realtime-permission-ingest-fail-closed
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
Adds per-event telemetry to the realtime firehose worker: stage gauge, received/dropped/failed counters, and per-event spans, plus unit-test fakes.
Key findings
- 🟡 Span every realtime event, reversing prior firehose exclusion — Handler.php:74
| $span = Span::init('realtime.event'); | ||
| $span | ||
| ->set('project.id', $event['project'] ?? '') | ||
| ->set('realtime.event.name', $event['data']['events'][0] ?? '') | ||
| ->set('realtime.arrived_at', $arrivedAt); |
There was a problem hiding this comment.
🟡 performance · medium
Span every realtime event, reversing prior firehose exclusion
handle() now creates and finishes a realtime.event span for every decoded event (src/Appwrite/Realtime/Event/Handler.php:74), while the code it replaces stated spans were kept to failed events only so the firehose stayed out of logs and telemetry. At realtime throughput this exports one span per event, multiplying collector load, and the coverage is inconsistent: the invalid_payload early return drops the event with only a counter and no span. Confirm the always-on policy explicitly, or restore failure-only span emission.
📋 Prompt for AI Agents
In src/Appwrite/Realtime/Event/Handler.php around lines 68-115, the realtime.event span is now initialised for every event and finished with realtime.result/resolved_at attributes, but the replaced code commented that only failed events got a span to keep the firehose out of logs. Either restructure so the span is created and finished only when the catch block runs, preserving the counters (eventsReceived, eventsDropped, eventsFailed) unchanged, or — if per-event spans are intended — also create and finish a span on the invalid_payload early-return path (lines 68-72) so every terminal outcome is observable in traces.
There was a problem hiding this comment.
Valid, fixed in 2c82ac1 on #15086's branch.
The span is no longer exported for every event. app/realtime.php now finishes realtime.event only when:
- the event failed (the error is attached),
- it took 1s or longer, or
- its project matches
_APP_TRACE_PROJECT_ID, so one project can be traced on demand.
Every other event's span is dropped without being exported. The counters (realtime.server.events.received, events.dropped{reason}, events.failed{stage}) still cover the whole firehose, so nothing is lost for alerting.
There was a problem hiding this comment.
The current diff (Handler.php) still shows the span created and finished for every valid decoded event — the selective export logic described (1s threshold, project-ID filter, failure-only) is not visible in any of the diffs provided. The fix may have landed in commit 2c82ac1 on a separate branch, but that code is not in the evidence available here. Based solely on what is shown, the original issue — a span emitted for every event — remains present in this diff.
There was a problem hiding this comment.
This PR was merged at a054079665, before the fix, so its diff will always show the old code. The fix is 2c82ac1816, pushed afterwards to the branch this PR merged into (#15086):
Handler::handle()no longer callsSpan::init()orSpan::finish(); it returns the outcome: https://github.com/appwrite/appwrite/blob/2c82ac1816/src/Appwrite/Realtime/Event/Handler.php#L62-L120- the subscribe closure in
app/realtime.phpowns the span and finishes it only for failed, slow (1s or more) or traced events: https://github.com/appwrite/appwrite/blob/2c82ac1816/app/realtime.php#L650-L670
Hansi already confirmed the same fix on #15086: #15086 (comment)
There was a problem hiding this comment.
The diffs provided in this review thread — both Handler.php and app/realtime.php — still show the span created and finished for every valid decoded event, with no selective export logic (failure-only, 1s threshold, or project-ID filter) visible. The fix described (commit 2c82ac1, where Handler::handle() no longer owns the span and the subscribe closure in app/realtime.php applies conditional export) is not present in any of the evidence shown here. Since this is the final verification tier and the fix is not visible in the supplied diffs, I cannot resolve the finding based on the available evidence alone.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Issue / Description
Closes #15107. Stacked on #15086.
The realtime pub/sub handler has almost no telemetry of its own. If it keeps reading events from Redis but stops delivering them, the only sign is that
realtime.server.arrival_delayandrealtime.server.message.sentgo flat, and nothing says why. Two places also throw failures away silently: the arrival-delay and delivery-delaycatch (\Throwable) {}blocks.Solution
New instruments, created through the telemetry adapter the same way the MQTT broker's are (
mqtt.messages.droppedwith areason,mqtt.messages.failed, …):realtime.server.events.receivedrealtime.server.events.droppedreasonno_subscriber: nobody on this worker matched;invalid_payload: not a JSON eventrealtime.server.events.failedstagearrival,delivery_delay, or whatever stephandle()was in when it threwrealtime.server.event.stagestage+workerIddecode,arrival,permissions,deliver,close,tail), 0 when idleHow to read them when delivery stops:
events.receivedflat: nothing is reaching the handler.event.stageclimbing: the handler is blocked, and thestagelabel names the step.events.failedrising: events throw. Thestagelabel shows where; this used to be silent for arrival and delivery delay.events.receivedrising,events.dropped{reason=no_subscriber}equal to it: events are handled but match nobody on the worker.The two silent
catchblocks still don't stop delivery. They now count the failure.A payload that isn't a JSON object is now counted and dropped up front, instead of failing further down with a
TypeError.Tests
tests/unit/Realtime/Event/HandlerTest.php, with a namedRecordingAdapterand the telemetryTestadapter:stage=idleafter an event.realtime.eventspan per event, with project id, event name, resultno_subscriber, 0 receivers andresolved_at≥arrived_at; no span for a payload that isn't an event.php -l, Pint and Rector on all changed files. I couldn't run PHPUnit locally (no Swoole), so CI's unit job is the first run.🤖 Generated with Claude Code