-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Stop replay when event buffer exceeds max. size #8315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { REPLAY_MAX_EVENT_BUFFER_SIZE } from '../constants'; | ||
import type { AddEventResult, EventBuffer, EventBufferType, RecordingEvent } from '../types'; | ||
import { timestampToMs } from '../util/timestampToMs'; | ||
import { EventBufferSizeExceededError } from '.'; | ||
|
||
/** | ||
* A basic event buffer that does not do any compression. | ||
|
@@ -8,6 +10,7 @@ import { timestampToMs } from '../util/timestampToMs'; | |
export class EventBufferArray implements EventBuffer { | ||
/** All the events that are buffered to be sent. */ | ||
public events: RecordingEvent[]; | ||
private _totalSize = 0; | ||
|
||
public constructor() { | ||
this.events = []; | ||
|
@@ -30,6 +33,12 @@ export class EventBufferArray implements EventBuffer { | |
|
||
/** @inheritdoc */ | ||
public async addEvent(event: RecordingEvent): Promise<AddEventResult> { | ||
const eventSize = JSON.stringify(event).length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems expensive to be running on each event. This is running before we pass the event to the web worker? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in the non-worker based event buffer it adds overhead as we need to stringify as we go. In the buffer-based worker we already do that, so there it adds no overhead. If we want to keep track in any way, we will have to add overhead to the non-worker based buffer (currently, we only stringify on |
||
this._totalSize += eventSize; | ||
if (this._totalSize > REPLAY_MAX_EVENT_BUFFER_SIZE) { | ||
throw new EventBufferSizeExceededError(); | ||
} | ||
|
||
this.events.push(event); | ||
} | ||
|
||
|
@@ -40,14 +49,15 @@ export class EventBufferArray implements EventBuffer { | |
// events member so that we do not lose new events while uploading | ||
// attachment. | ||
const eventsRet = this.events; | ||
this.events = []; | ||
this.clear(); | ||
resolve(JSON.stringify(eventsRet)); | ||
}); | ||
} | ||
|
||
/** @inheritdoc */ | ||
public clear(): void { | ||
this.events = []; | ||
this._totalSize = 0; | ||
} | ||
|
||
/** @inheritdoc */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.