-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcreateReplayEnvelope.ts
31 lines (30 loc) · 1.13 KB
/
createReplayEnvelope.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader } from '@sentry/core';
import type { DsnComponents, ReplayEnvelope, ReplayEvent, ReplayRecordingData } from '@sentry/core';
/**
* Create a replay envelope ready to be sent.
* This includes both the replay event, as well as the recording data.
*/
export function createReplayEnvelope(
replayEvent: ReplayEvent,
recordingData: ReplayRecordingData,
dsn: DsnComponents,
tunnel?: string,
): ReplayEnvelope {
return createEnvelope<ReplayEnvelope>(
createEventEnvelopeHeaders(replayEvent, getSdkMetadataForEnvelopeHeader(replayEvent), tunnel, dsn),
[
[{ type: 'replay_event' }, replayEvent],
[
{
type: 'replay_recording',
// If string then we need to encode to UTF8, otherwise will have
// wrong size. TextEncoder has similar browser support to
// MutationObserver, although it does not accept IE11.
length:
typeof recordingData === 'string' ? new TextEncoder().encode(recordingData).length : recordingData.length,
},
recordingData,
],
],
);
}