Skip to content

Commit dff1a44

Browse files
committed
ref: Rename events to recordingData for replays
1 parent e87a5c1 commit dff1a44

File tree

12 files changed

+47
-51
lines changed

12 files changed

+47
-51
lines changed

packages/replay/jest.setup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22
import { getCurrentHub } from '@sentry/core';
3-
import type { ReplayRecordingData,Transport } from '@sentry/types';
3+
import type { ReplayRecordingData, Transport } from '@sentry/types';
44

55
import type { ReplayContainer, Session } from './src/types';
66

@@ -34,7 +34,7 @@ type SentReplayExpected = {
3434
replayEventPayload?: ReplayEventPayload;
3535
recordingHeader?: RecordingHeader;
3636
recordingPayloadHeader?: RecordingPayloadHeader;
37-
events?: ReplayRecordingData;
37+
recordingData?: ReplayRecordingData;
3838
};
3939

4040
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
@@ -79,7 +79,7 @@ function checkCallForSentReplay(
7979
const [[replayEventHeader, replayEventPayload], [recordingHeader, recordingPayload] = []] = envelopeItems;
8080

8181
// @ts-ignore recordingPayload is always a string in our tests
82-
const [recordingPayloadHeader, events] = recordingPayload?.split('\n') || [];
82+
const [recordingPayloadHeader, recordingData] = recordingPayload?.split('\n') || [];
8383

8484
const actualObj: Required<SentReplayExpected> = {
8585
// @ts-ignore Custom envelope
@@ -91,7 +91,7 @@ function checkCallForSentReplay(
9191
// @ts-ignore Custom envelope
9292
recordingHeader: recordingHeader,
9393
recordingPayloadHeader: recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
94-
events,
94+
recordingData,
9595
};
9696

9797
const isObjectContaining = expected && 'sample' in expected && 'inverse' in expected;

packages/replay/src/replay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export class ReplayContainer implements ReplayContainerInterface {
818818

819819
await sendReplay({
820820
replayId,
821-
events: recordingData,
821+
recordingData,
822822
segmentId,
823823
includeReplayStartTimestamp: segmentId === 0,
824824
eventContext,

packages/replay/src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import type { eventWithTime, recordOptions } from './types/rrweb';
55
export type RecordingEvent = eventWithTime;
66
export type RecordingOptions = recordOptions;
77

8-
export type RecordedEvents = Uint8Array | string;
9-
108
export type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;
119

1210
export interface SendReplayData {
13-
events: RecordedEvents;
11+
recordingData: ReplayRecordingData;
1412
replayId: string;
1513
segmentId: number;
1614
includeReplayStartTimestamp: boolean;

packages/replay/src/util/createRecordingData.ts renamed to packages/replay/src/util/prepareRecordingData.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import type { ReplayRecordingData } from '@sentry/types';
22

3-
import type { RecordedEvents } from '../types';
4-
53
/**
6-
* Create the recording data ready to be sent.
4+
* Prepare the recording data ready to be sent.
75
*/
8-
export function createRecordingData({
9-
events,
6+
export function prepareRecordingData({
7+
recordingData,
108
headers,
119
}: {
12-
events: RecordedEvents;
10+
recordingData: ReplayRecordingData;
1311
headers: Record<string, unknown>;
1412
}): ReplayRecordingData {
1513
let payloadWithSequence;
@@ -18,16 +16,16 @@ export function createRecordingData({
1816
const replayHeaders = `${JSON.stringify(headers)}
1917
`;
2018

21-
if (typeof events === 'string') {
22-
payloadWithSequence = `${replayHeaders}${events}`;
19+
if (typeof recordingData === 'string') {
20+
payloadWithSequence = `${replayHeaders}${recordingData}`;
2321
} else {
2422
const enc = new TextEncoder();
2523
// XXX: newline is needed to separate sequence id from events
2624
const sequence = enc.encode(replayHeaders);
2725
// Merge the two Uint8Arrays
28-
payloadWithSequence = new Uint8Array(sequence.length + events.length);
26+
payloadWithSequence = new Uint8Array(sequence.length + recordingData.length);
2927
payloadWithSequence.set(sequence);
30-
payloadWithSequence.set(events, sequence.length);
28+
payloadWithSequence.set(recordingData, sequence.length);
3129
}
3230

3331
return payloadWithSequence;

packages/replay/src/util/sendReplay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export async function sendReplay(
1414
interval: RETRY_BASE_INTERVAL,
1515
},
1616
): Promise<unknown> {
17-
const { events, options } = replayData;
17+
const { recordingData, options } = replayData;
1818

1919
// short circuit if there's no events to upload (this shouldn't happen as _runFlush makes this check)
20-
if (!events.length) {
20+
if (!recordingData.length) {
2121
return;
2222
}
2323

packages/replay/src/util/sendReplayRequest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { logger } from '@sentry/utils';
44

55
import { REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from '../constants';
66
import type { SendReplayData } from '../types';
7-
import { createRecordingData } from './createRecordingData';
87
import { createReplayEnvelope } from './createReplayEnvelope';
8+
import { prepareRecordingData } from './prepareRecordingData';
99
import { prepareReplayEvent } from './prepareReplayEvent';
1010

1111
/**
1212
* Send replay attachment using `fetch()`
1313
*/
1414
export async function sendReplayRequest({
15-
events,
15+
recordingData,
1616
replayId,
1717
segmentId: segment_id,
1818
includeReplayStartTimestamp,
@@ -21,8 +21,8 @@ export async function sendReplayRequest({
2121
session,
2222
options,
2323
}: SendReplayData): Promise<void | TransportMakeRequestResponse> {
24-
const recordingData = createRecordingData({
25-
events,
24+
const preparedRecordingData = prepareRecordingData({
25+
recordingData,
2626
headers: {
2727
segment_id,
2828
},
@@ -104,7 +104,7 @@ export async function sendReplayRequest({
104104
}
105105
*/
106106

107-
const envelope = createReplayEnvelope(replayEvent, recordingData, dsn, client.getOptions().tunnel);
107+
const envelope = createReplayEnvelope(replayEvent, preparedRecordingData, dsn, client.getOptions().tunnel);
108108

109109
try {
110110
return await transport.send(envelope);

packages/replay/test/integration/errorSampleRate.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Integration | errorSampleRate', () => {
6868
sessionSampleRate: 0,
6969
}),
7070
}),
71-
events: JSON.stringify([
71+
recordingData: JSON.stringify([
7272
{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 },
7373
TEST_EVENT,
7474
{
@@ -98,15 +98,15 @@ describe('Integration | errorSampleRate', () => {
9898
sessionSampleRate: 0,
9999
}),
100100
}),
101-
events: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP + 5020, type: 2 }]),
101+
recordingData: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP + 5020, type: 2 }]),
102102
});
103103

104104
jest.advanceTimersByTime(DEFAULT_FLUSH_MIN_DELAY);
105105

106106
// New checkout when we call `startRecording` again after uploading segment
107107
// after an error occurs
108108
expect(replay).toHaveLastSentReplay({
109-
events: JSON.stringify([
109+
recordingData: JSON.stringify([
110110
{
111111
data: { isCheckout: true },
112112
timestamp: BASE_TIMESTAMP + DEFAULT_FLUSH_MIN_DELAY + 20,
@@ -124,7 +124,7 @@ describe('Integration | errorSampleRate', () => {
124124
await new Promise(process.nextTick);
125125

126126
expect(replay).toHaveLastSentReplay({
127-
events: JSON.stringify([
127+
recordingData: JSON.stringify([
128128
{
129129
type: 5,
130130
timestamp: BASE_TIMESTAMP + 10000 + 40,
@@ -304,7 +304,7 @@ describe('Integration | errorSampleRate', () => {
304304
await new Promise(process.nextTick);
305305

306306
expect(replay).toHaveSentReplay({
307-
events: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 }, TEST_EVENT]),
307+
recordingData: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 }, TEST_EVENT]),
308308
replayEventPayload: expect.objectContaining({
309309
replay_start_timestamp: BASE_TIMESTAMP / 1000,
310310
// the exception happens roughly 10 seconds after BASE_TIMESTAMP
@@ -360,7 +360,7 @@ describe('Integration | errorSampleRate', () => {
360360
// Make sure the old performance event is thrown out
361361
replay_start_timestamp: (BASE_TIMESTAMP + ELAPSED + 20) / 1000,
362362
}),
363-
events: JSON.stringify([
363+
recordingData: JSON.stringify([
364364
{
365365
data: { isCheckout: true },
366366
timestamp: BASE_TIMESTAMP + ELAPSED + 20,
@@ -406,12 +406,12 @@ it('sends a replay after loading the session multiple times', async () => {
406406
await new Promise(process.nextTick);
407407

408408
expect(replay).toHaveSentReplay({
409-
events: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 }, TEST_EVENT]),
409+
recordingData: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 }, TEST_EVENT]),
410410
});
411411

412412
// Latest checkout when we call `startRecording` again after uploading segment
413413
// after an error occurs (e.g. when we switch to session replay recording)
414414
expect(replay).toHaveLastSentReplay({
415-
events: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP + 5020, type: 2 }]),
415+
recordingData: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP + 5020, type: 2 }]),
416416
});
417417
});

packages/replay/test/integration/events.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('Integration | events', () => {
176176
// Make sure the old performance event is thrown out
177177
replay_start_timestamp: BASE_TIMESTAMP / 1000,
178178
}),
179-
events: JSON.stringify([
179+
recordingData: JSON.stringify([
180180
TEST_EVENT,
181181
{
182182
type: 5,

packages/replay/test/integration/flush.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Integration | flush', () => {
177177
// sendReplay is called with replayId, events, segment
178178

179179
expect(mockSendReplay).toHaveBeenLastCalledWith({
180-
events: expect.any(String),
180+
recordingData: expect.any(String),
181181
replayId: expect.any(String),
182182
includeReplayStartTimestamp: true,
183183
segmentId: 0,
@@ -227,7 +227,7 @@ describe('Integration | flush', () => {
227227
expect(mockFlush).toHaveBeenCalledTimes(5);
228228
expect(mockRunFlush).toHaveBeenCalledTimes(2);
229229
expect(mockSendReplay).toHaveBeenLastCalledWith({
230-
events: expect.any(String),
230+
recordingData: expect.any(String),
231231
replayId: expect.any(String),
232232
includeReplayStartTimestamp: false,
233233
segmentId: 1,

packages/replay/test/integration/sendReplayEvent.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('Integration | sendReplayEvent', () => {
9696

9797
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
9898

99-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
99+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
100100

101101
// Session's last activity is not updated because we do not consider
102102
// visibilitystate as user being active
@@ -136,7 +136,7 @@ describe('Integration | sendReplayEvent', () => {
136136

137137
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
138138

139-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
139+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
140140

141141
// No user activity to trigger an update
142142
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);
@@ -160,7 +160,7 @@ describe('Integration | sendReplayEvent', () => {
160160
await new Promise(process.nextTick);
161161

162162
expect(replay).toHaveLastSentReplay({
163-
events: JSON.stringify([...Array(5)].map(() => TEST_EVENT)),
163+
recordingData: JSON.stringify([...Array(5)].map(() => TEST_EVENT)),
164164
});
165165

166166
// There should also not be another attempt at an upload 5 seconds after the last replay event
@@ -177,7 +177,7 @@ describe('Integration | sendReplayEvent', () => {
177177
mockTransportSend.mockClear();
178178
mockRecord._emitter(TEST_EVENT);
179179
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY);
180-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
180+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
181181
});
182182

183183
it('uploads a replay event when WINDOW is blurred', async () => {
@@ -211,7 +211,7 @@ describe('Integration | sendReplayEvent', () => {
211211
await new Promise(process.nextTick);
212212
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
213213
expect(replay).toHaveLastSentReplay({
214-
events: JSON.stringify([TEST_EVENT, hiddenBreadcrumb]),
214+
recordingData: JSON.stringify([TEST_EVENT, hiddenBreadcrumb]),
215215
});
216216
// Session's last activity should not be updated
217217
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);
@@ -238,7 +238,7 @@ describe('Integration | sendReplayEvent', () => {
238238
await new Promise(process.nextTick);
239239

240240
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
241-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
241+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
242242

243243
// Session's last activity is not updated because we do not consider
244244
// visibilitystate as user being active
@@ -256,7 +256,7 @@ describe('Integration | sendReplayEvent', () => {
256256

257257
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
258258
expect(mockTransportSend).toHaveBeenCalledTimes(1);
259-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
259+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
260260

261261
// No user activity to trigger an update
262262
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);
@@ -280,7 +280,7 @@ describe('Integration | sendReplayEvent', () => {
280280
await new Promise(process.nextTick);
281281

282282
expect(replay).toHaveLastSentReplay({
283-
events: JSON.stringify([...Array(5)].map(() => TEST_EVENT)),
283+
recordingData: JSON.stringify([...Array(5)].map(() => TEST_EVENT)),
284284
});
285285

286286
// There should also not be another attempt at an upload 5 seconds after the last replay event
@@ -298,7 +298,7 @@ describe('Integration | sendReplayEvent', () => {
298298
mockTransportSend.mockClear();
299299
mockRecord._emitter(TEST_EVENT);
300300
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY);
301-
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
301+
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) });
302302
});
303303

304304
it('uploads a dom breadcrumb 5 seconds after listener receives an event', async () => {
@@ -311,7 +311,7 @@ describe('Integration | sendReplayEvent', () => {
311311
await advanceTimers(ELAPSED);
312312

313313
expect(replay).toHaveLastSentReplay({
314-
events: JSON.stringify([
314+
recordingData: JSON.stringify([
315315
{
316316
type: 5,
317317
timestamp: BASE_TIMESTAMP,
@@ -369,7 +369,7 @@ describe('Integration | sendReplayEvent', () => {
369369
urls: ['http://localhost/'],
370370
}),
371371
recordingPayloadHeader: { segment_id: 0 },
372-
events: JSON.stringify([TEST_EVENT]),
372+
recordingData: JSON.stringify([TEST_EVENT]),
373373
});
374374

375375
mockTransportSend.mockClear();

packages/replay/test/integration/session.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Integration | session', () => {
149149
const breadcrumbTimestamp = newTimestamp + 20; // I don't know where this 20ms comes from
150150

151151
expect(replay).toHaveLastSentReplay({
152-
events: JSON.stringify([
152+
recordingData: JSON.stringify([
153153
{ data: { isCheckout: true }, timestamp: newTimestamp, type: 2 },
154154
{
155155
type: 5,
@@ -309,7 +309,7 @@ describe('Integration | session', () => {
309309

310310
expect(replay).toHaveLastSentReplay({
311311
recordingPayloadHeader: { segment_id: 0 },
312-
events: JSON.stringify([
312+
recordingData: JSON.stringify([
313313
{ data: { isCheckout: true }, timestamp: newTimestamp, type: 2 },
314314
{
315315
type: 5,
@@ -420,7 +420,7 @@ describe('Integration | session', () => {
420420

421421
expect(replay).toHaveLastSentReplay({
422422
recordingPayloadHeader: { segment_id: 0 },
423-
events: JSON.stringify([
423+
recordingData: JSON.stringify([
424424
{ data: { isCheckout: true }, timestamp: newTimestamp, type: 2 },
425425
{
426426
type: 5,

packages/replay/test/integration/stop.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Integration | stop', () => {
110110
jest.runAllTimers();
111111
await new Promise(process.nextTick);
112112
expect(replay).toHaveLastSentReplay({
113-
events: JSON.stringify([
113+
recordingData: JSON.stringify([
114114
// This event happens when we call `replay.start`
115115
{
116116
data: { isCheckout: true },

0 commit comments

Comments
 (0)