Repository navigation
feat(realtime): telemetry for the pub/sub event handler - #15111
ArnabChatterjee20k merged 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR instruments the realtime subsystem with OpenTelemetry metrics: event arrival, delivery latency, failure, drop and close counters plus an observable gauge reporting the handler's current processing stage and its age, wired into the realtime worker's metrics registry.
Reviewed commit: 86fdf3b |
🔵 Tier A · Mergeable after minor fixes
The pub/sub handler now records received, dropped, and failed event metrics, exposes its active processing stage, and reports arrival and delivery-delay failures. It also emits a span for each valid event with its project, event name, result, receiver count, and processing timestamps. Tests cover the metrics, malformed payload handling, idle stage reporting, and span attributes. Latest changes: The newest commits add per-event spans with project, event, result, receiver-count, and timing attributes, plus a recording exporter and span assertions in the handler tests.
Fix with agent prompt### Issue 1
src/Appwrite/Realtime/Event/Handler.php:118-119
**Avoid exporting an info span for every pub/sub event**
This now finishes an info span for every valid event, and the default exporter in `app/init/span.php` writes spans to stdout with no sampling when trace filters are unset. Since this handler processes the realtime firehose, that creates a log entry per event and can overwhelm log volume and add substantial per-event overhead; the prior failed-event-only span avoided this.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 5
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| $span->set('realtime.resolved_at', \microtime(true)); | ||
| $span->finish(error: $error); |
There was a problem hiding this comment.
Avoid exporting an info span for every pub/sub event
This now finishes an info span for every valid event, and the default exporter in app/init/span.php writes spans to stdout with no sampling when trace filters are unset. Since this handler processes the realtime firehose, that creates a log entry per event and can overwhelm log volume and add substantial per-event overhead; the prior failed-event-only span avoided this.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Realtime/Event/Handler.php
Line: 118-119
Comment:
**Avoid exporting an info span for every pub/sub event**
This now finishes an info span for every valid event, and the default exporter in `app/init/span.php` writes spans to stdout with no sampling when trace filters are unset. Since this handler processes the realtime firehose, that creates a log entry per event and can overwhelm log volume and add substantial per-event overhead; the prior failed-event-only span avoided this.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · performance · Reply if this doesn't apply.
53189bf
into
fix/realtime-permission-check-cap
Issue / Description
Closes #15107. Stacked on #15094.
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