1- import type { ReplayRecordingData } from '@sentry/types' ;
1+ import type { ReplayRecordingData , ReplayRecordingMode } from '@sentry/types' ;
22import { logger } from '@sentry/utils' ;
33
44import type { AddEventResult , EventBuffer , RecordingEvent } from '../types' ;
55import { EventBufferArray } from './EventBufferArray' ;
66import { EventBufferCompressionWorker } from './EventBufferCompressionWorker' ;
7+ import { EventBufferPartitionedCompressionWorker } from './EventBufferPartitionedCompressionWorker' ;
78
89/**
910 * This proxy will try to use the compression worker, and fall back to use the simple buffer if an error occurs there.
@@ -12,15 +13,22 @@ import { EventBufferCompressionWorker } from './EventBufferCompressionWorker';
1213 */
1314export class EventBufferProxy implements EventBuffer {
1415 private _fallback : EventBufferArray ;
15- private _compression : EventBufferCompressionWorker ;
16+ private _compression : EventBufferCompressionWorker | EventBufferPartitionedCompressionWorker ;
1617 private _used : EventBuffer ;
1718 private _ensureWorkerIsLoadedPromise : Promise < void > ;
1819
19- public constructor ( worker : Worker ) {
20+ public constructor ( worker : Worker , recordingMode : ReplayRecordingMode ) {
2021 this . _fallback = new EventBufferArray ( ) ;
21- this . _compression = new EventBufferCompressionWorker ( worker ) ;
22- this . _used = this . _fallback ;
2322
23+ // In error mode, we use the partitioned compression worker, which does not use compression streaming
24+ // Instead, all events are sent at finish-time, as we need to continuously modify the queued events
25+ // In session mode, we use a streaming compression implementation, which is more performant
26+ this . _compression =
27+ recordingMode === 'error'
28+ ? new EventBufferPartitionedCompressionWorker ( worker )
29+ : new EventBufferCompressionWorker ( worker ) ;
30+
31+ this . _used = this . _fallback ;
2432 this . _ensureWorkerIsLoadedPromise = this . _ensureWorkerIsLoaded ( ) ;
2533 }
2634
@@ -52,11 +60,21 @@ export class EventBufferProxy implements EventBuffer {
5260 return this . _used . finish ( ) ;
5361 }
5462
63+ /** @inheritdoc */
64+ public clear ( keepLastCheckout ?: boolean ) : Promise < void > {
65+ return this . _used . clear ( keepLastCheckout ) ;
66+ }
67+
5568 /** Ensure the worker has loaded. */
5669 public ensureWorkerIsLoaded ( ) : Promise < void > {
5770 return this . _ensureWorkerIsLoadedPromise ;
5871 }
5972
73+ /** @inheritdoc */
74+ public getEarliestTimestamp ( ) : number | null {
75+ return this . _used . getEarliestTimestamp ( ) ;
76+ }
77+
6078 /** Actually check if the worker has been loaded. */
6179 private async _ensureWorkerIsLoaded ( ) : Promise < void > {
6280 try {
0 commit comments