Skip to content

Commit a345409

Browse files
committed
ref(types): Upstream replay envelope types
1 parent 369760b commit a345409

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

packages/replay/src/util/createReplayEnvelope.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import { Envelope, ReplayEvent, ReplayRecordingData } from '@sentry/types';
1+
import { ReplayEnvelope, ReplayEvent, ReplayRecordingData } from '@sentry/types';
22
import { createEnvelope } from '@sentry/utils';
33

44
import { REPLAY_SDK_INFO } from '../constants';
55

66
export function createReplayEnvelope(
77
replayId: string,
88
replayEvent: ReplayEvent,
9-
payloadWithSequence: ReplayRecordingData,
10-
): Envelope {
11-
return createEnvelope(
9+
recordingData: ReplayRecordingData,
10+
): ReplayEnvelope {
11+
return createEnvelope<ReplayEnvelope>(
1212
{
1313
event_id: replayId,
1414
sent_at: new Date().toISOString(),
1515
sdk: REPLAY_SDK_INFO,
1616
},
1717
[
18-
// @ts-ignore New types
1918
[{ type: 'replay_event' }, replayEvent],
2019
[
2120
{
22-
// @ts-ignore setting envelope
2321
type: 'replay_recording',
24-
length: payloadWithSequence.length,
22+
length: recordingData.length,
2523
},
26-
// @ts-ignore: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
27-
payloadWithSequence,
24+
recordingData,
2825
],
2926
],
3027
);

packages/types/src/datacategory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ export type DataCategory =
1919
// SDK internal event, like client_reports
2020
| 'internal'
2121
// Profile event type
22-
| 'profile';
22+
| 'profile'
23+
// Replay event types
24+
| 'replay_event'
25+
| 'replay_recording';

packages/types/src/envelope.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ClientReport } from './clientreport';
22
import { DsnComponents } from './dsn';
33
import { Event } from './event';
4+
import { ReplayEvent, ReplayRecordingData } from './replay';
45
import { SdkInfo } from './sdkinfo';
56
import { Session, SessionAggregates } from './session';
67
import { Transaction } from './transaction';
@@ -27,7 +28,9 @@ export type EnvelopeItemType =
2728
| 'transaction'
2829
| 'attachment'
2930
| 'event'
30-
| 'profile';
31+
| 'profile'
32+
| 'replay_event'
33+
| 'replay_recording';
3134

3235
export type BaseEnvelopeHeaders = {
3336
[key: string]: unknown;
@@ -62,6 +65,8 @@ type UserFeedbackItemHeaders = { type: 'user_report' };
6265
type SessionItemHeaders = { type: 'session' };
6366
type SessionAggregatesItemHeaders = { type: 'sessions' };
6467
type ClientReportItemHeaders = { type: 'client_report' };
68+
type ReplayEventItemHeaders = { type: 'replay_event' };
69+
type ReplayRecordingItemHeaders = { type: 'replay_recording'; length: number };
6570

6671
export type EventItem = BaseEnvelopeItem<EventItemHeaders, Event>;
6772
export type AttachmentItem = BaseEnvelopeItem<AttachmentItemHeaders, string | Uint8Array>;
@@ -70,14 +75,18 @@ export type SessionItem =
7075
| BaseEnvelopeItem<SessionItemHeaders, Session>
7176
| BaseEnvelopeItem<SessionAggregatesItemHeaders, SessionAggregates>;
7277
export type ClientReportItem = BaseEnvelopeItem<ClientReportItemHeaders, ClientReport>;
78+
type ReplayEventItem = BaseEnvelopeItem<ReplayEventItemHeaders, ReplayEvent>;
79+
type ReplayRecordingItem = BaseEnvelopeItem<ReplayRecordingItemHeaders, ReplayRecordingData>;
7380

7481
export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: DynamicSamplingContext };
7582
type SessionEnvelopeHeaders = { sent_at: string };
7683
type ClientReportEnvelopeHeaders = BaseEnvelopeHeaders;
84+
type ReplayEnvelopeHeaders = BaseEnvelopeHeaders;
7785

7886
export type EventEnvelope = BaseEnvelope<EventEnvelopeHeaders, EventItem | AttachmentItem | UserFeedbackItem>;
7987
export type SessionEnvelope = BaseEnvelope<SessionEnvelopeHeaders, SessionItem>;
8088
export type ClientReportEnvelope = BaseEnvelope<ClientReportEnvelopeHeaders, ClientReportItem>;
89+
export type ReplayEnvelope = [ReplayEnvelopeHeaders, [ReplayEventItem, ReplayRecordingItem]];
8190

82-
export type Envelope = EventEnvelope | SessionEnvelope | ClientReportEnvelope;
91+
export type Envelope = EventEnvelope | SessionEnvelope | ClientReportEnvelope | ReplayEnvelope;
8392
export type EnvelopeItem = Envelope[1][number];

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type {
1919
EventEnvelope,
2020
EventEnvelopeHeaders,
2121
EventItem,
22+
ReplayEnvelope,
2223
SessionEnvelope,
2324
SessionItem,
2425
UserFeedbackItem,

packages/utils/src/envelope.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ const ITEM_TYPE_TO_DATA_CATEGORY_MAP: Record<EnvelopeItemType, DataCategory> = {
134134
client_report: 'internal',
135135
user_report: 'default',
136136
profile: 'profile',
137+
replay_event: 'replay_event',
138+
replay_recording: 'replay_recording',
137139
};
138140

139141
/**

0 commit comments

Comments
 (0)