[RUM-16912] Refactor transport layer for extensibility#140
Merged
cdn34dd merged 1 commit intoJun 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the batch transport layer to separate shared batching/file-rotation/upload plumbing from track-specific serialization and request construction, enabling future transport strategies (e.g., session replay) without modifying scheduling/rotation logic.
Changes:
- Made
BatchProducer/BatchConsumerabstract base classes with strategy hooks (writeData,buildRequest) and shared initialization/upload logic. - Added “standard” concrete implementations (
StandardBatchProducer/StandardBatchConsumer) preserving the existing NDJSON-on-disk + JSON-array POST behavior. - Updated
BatchManagerto construct producer/consumer via a factory and reorganized tests to cover base vs. standard behaviors.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/transport/batch/standard/StandardBatchProducer.ts | Implements standard NDJSON file writing + size-based rotation on top of abstract producer. |
| src/transport/batch/standard/StandardBatchProducer.spec.ts | Updates/extends producer tests for the new standard implementation and filename format. |
| src/transport/batch/standard/StandardBatchConsumer.ts | Implements standard request construction (JSON array + DD-API-KEY header). |
| src/transport/batch/standard/StandardBatchConsumer.spec.ts | Adds tests validating standard consumer request headers/body and file selection/order. |
| src/transport/batch/BatchProducer.ts | Converts producer into an abstract base with shared init/recovery and unique filename generation. |
| src/transport/batch/BatchManager.ts | Introduces factory-based producer/consumer creation; wires standard pair for now. |
| src/transport/batch/BatchManager.spec.ts | Updates manager tests to mock standard producer/consumer and validate wiring/scheduling. |
| src/transport/batch/BatchConsumer.ts | Converts consumer into an abstract base delegating request construction to buildRequest. |
| src/transport/batch/BatchConsumer.spec.ts | Refactors tests to use a minimal concrete subclass to exercise base upload/send/delete logic. |
| src/transport/batch/batchConfig.types.ts | Introduces a unified BatchConfig type used by BatchManager.create. |
bcaudan
approved these changes
Jun 22, 2026
dd5da55 to
cd306bf
Compare
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.
Motivation
The batch transport currently has a single concrete BatchProducer/BatchConsumer pair with one strategy hardcoded into it: serialize events as NDJSON to disk, then POST them as a JSON array with DD-API-KEY auth. That works fine for RUM and spans, but we're about to need other strategies — session replay being the next one, and its intake contract is quite different (multipart body, query-param auth, segments rather than line-delimited events).
As things stand there's nowhere clean to add that. You'd either fork the classes or bolt conditionals onto code that also handles file rotation, the write queue, and upload scheduling — none of which actually changes between strategies. This PR is the groundwork to avoid that: separate the shared plumbing from the per-track specifics so a new strategy can slot in without touching any of the scheduling/rotation logic.
Changes
Test instructions
Checklist