fix(telemetry): serialize each event once at admission - #5422
youtsuhodev wants to merge 1 commit into
Conversation
emit() previously ran JSON.stringify then JSON.parse to deep-clone every event, and sendBatch() re-stringified the whole batch. Store the admission-time JSON string as the immutable snapshot and splice it into the batch envelope, dropping two serialization passes per intent from the hot path.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. Walkthrough
ChangesTelemetry serialization
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to The telemetry optimization preserves the existing event payload and delivery behavior, so it is mergeable with normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. JSON rests in the queue, Comment |
🤖 Claude Code ReviewVerdict: ✅ No issues found — this is a clean, correct performance-only refactor. Findings by severity: Critical: 0 · High: 0 · Medium: 0 · Low: 0 Summary: The change to I independently verified:
No high-signal bugs, logic errors, or CLAUDE.md violations were identified in this diff. 🤖 Generated with Claude Code |
Description:
Serialize each telemetry event exactly once, at admission, instead of three
times across the emit → flush path.
BufferedMatchTelemetryEmitter.emit()previously ranJSON.stringify(event)and then
JSON.parse(serialized)purely to deep-clone the event for itsadmission snapshot, and
sendBatch()later re-stringified every queued eventinside the batch envelope. For
intent_observed— emitted per accepted/rejectedintent, up to 10/s per client — this put three serialization passes on a hot
path.
Changes in
src/server/telemetry/BufferedMatchTelemetryEmitter.ts:QueueEntrynow stores the admission-time JSON string (serialized) insteadof the event object. That string is both the immutable snapshot and the exact
wire payload, so the
JSON.parseclone is gone.emit()computesbytesfrom that single string; the byte budget, oversizedevent, and circular-reference (
droppedSerialization) behavior are unchanged.sendBatch()splices the pre-serialized fragments into the envelope byconcatenation (same key order and values as the previous
JSON.stringifyofthe object), removing the second serialization of every event.
Net effect: two serialization passes removed per intent, no JS deep clone, and
the large
intentobject is no longer retained in the queue.Scope: performance-only, no wire-format or signature change. Verified the emitted
batch is byte-for-byte compatible with the previous envelope (HMAC signature is
computed over the body exactly as before).
Testing:
npx vitest tests/server/telemetry tests/server/MatchTelemetryIntegration.test.ts --run→ 37 passed.
oxlintandeslintclean on the changed file. No new tests wereadded: the existing suite already covers the affected paths (immutable admission
snapshot after caller mutation, exact serialized byte budget, unserializable/
circular event dropped without throwing, FIFO batch + exact HMAC).
No
src/corechanges.Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
lilian.looters