feat: implement client-side telemetry pipeline with Web Worker batching and beacon delivery - #761
Merged
Chucks1093 merged 2 commits intoAug 24, 2026
Conversation
…ng and beacon delivery Closes accesslayerorg#756
Member
|
Moving the batching and compression into a Web Worker is the right call since it keeps the main thread completely free and the zero synchronous work guarantee on track() means telemetry will never block a user interaction. The DroppedEvents sentinel is also a smart design because it gives the backend visibility into data loss without silently swallowing events, which would make capacity planning much harder. |
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.
Closes #756
Summary
TelemetryEventunion (PageLoad,ApiCall,SigningStep,ComponentError,UserAction) plus aDroppedEventssentinel, all wrapped with a commonTelemetryEnvelope(sessionId,walletAddress,buildId,timestamp,sequence).TelemetryBatcher— the testable core that buffers events in memory, flushes every 5 seconds or at 50 events, retains failed batches and prepends them to the next flush (at-least-once delivery), caps retained events at 500 (inserting aDroppedEventssentinel when exceeded), and includeslastDeliveredSequenceandcurrentBatchStartSequencein every batch header for server-side gap detection.telemetry.worker.ts— a dedicated Web Worker that wraps the batcher, compresses payloads withCompressionStream(gzip) before sending viafetch POST /telemetry, and handlesFLUSH_AND_BEACONmessages by shipping the current batch vianavigator.sendBeaconfor guaranteed page-unload delivery.TelemetryClient— the main-thread singleton that spawns the worker, assignssessionIdand monotonically incrementingsequencenumbers, and registers avisibilitychangelistener that postsFLUSH_AND_BEACONwhen the page is hidden. Thetrack()method is a singlepostMessagecall with zero synchronous work.useTelemetry()React hook that lazily initialises the client on first mount and returns a stabletrackfunction.DroppedEventssentinel insertion, and a sub-0.1ms performance assertion fortrack().Test plan
useTelemetry().track()completes in under 0.1ms on the main threadsendBeaconwith the current batchDroppedEventssentinel appears when retained events exceed 500