Skip to content

Commit 6cfd730

Browse files
authored
feat(core): Add replay_event type for events (#6481)
1 parent 72d77d8 commit 6cfd730

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

packages/core/src/envelope.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ export function createEventEnvelope(
6363
tunnel?: string,
6464
): EventEnvelope {
6565
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
66-
const eventType = event.type || 'event';
66+
67+
/*
68+
Note: Due to TS, event.type may be `replay_event`, theoretically.
69+
In practice, we never call `createEventEnvelope` with `replay_event` type,
70+
and we'd have to adjut a looot of types to make this work properly.
71+
We want to avoid casting this around, as that could lead to bugs (e.g. when we add another type)
72+
So the safe choice is to really guard against the replay_event type here.
73+
*/
74+
const eventType = event.type && event.type !== 'replay_event' ? event.type : 'event';
6775

6876
enhanceEventWithSdkInfo(event, metadata && metadata.sdk);
6977

packages/core/src/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class Hub implements HubInterface {
233233
*/
234234
public captureEvent(event: Event, hint?: EventHint): string {
235235
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
236-
if (event.type !== 'transaction') {
236+
if (!event.type) {
237237
this._lastEventId = eventId;
238238
}
239239

packages/hub/test/hub.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
/* eslint-disable deprecation/deprecation */
33

4-
import { Client, Event } from '@sentry/types';
4+
import { Client, Event, EventType } from '@sentry/types';
55

66
import { getCurrentHub, Hub, Scope } from '../src';
77

@@ -358,10 +358,11 @@ describe('Hub', () => {
358358
expect(args[1].event_id).toEqual(hub.lastEventId());
359359
});
360360

361-
test('transactions do not set lastEventId', () => {
361+
const eventTypesToIgnoreLastEventId: EventType[] = ['transaction', 'replay_event'];
362+
it.each(eventTypesToIgnoreLastEventId)('eventType %s does not set lastEventId', eventType => {
362363
const event: Event = {
363364
extra: { b: 3 },
364-
type: 'transaction',
365+
type: eventType,
365366
};
366367
const testClient = makeClient();
367368
const hub = new Hub(testClient);

packages/replay/src/coreHandlers/handleGlobalEvent.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import { isRrwebError } from '../util/isRrwebError';
1212
export function handleGlobalEventListener(replay: ReplayContainer): (event: Event) => Event | null {
1313
return (event: Event) => {
1414
// Do not apply replayId to the root event
15-
if (
16-
// @ts-ignore new event type
17-
event.type === REPLAY_EVENT_NAME
18-
) {
15+
if (event.type === REPLAY_EVENT_NAME) {
1916
// Replays have separate set of breadcrumbs, do not include breadcrumbs
2017
// from core SDK
2118
delete event.breadcrumbs;
@@ -31,7 +28,7 @@ export function handleGlobalEventListener(replay: ReplayContainer): (event: Even
3128

3229
// Only tag transactions with replayId if not waiting for an error
3330
// @ts-ignore private
34-
if (event.type !== 'transaction' || replay.recordingMode === 'session') {
31+
if (!event.type || replay.recordingMode === 'session') {
3532
event.tags = { ...event.tags, replayId: replay.session?.id };
3633
}
3734

packages/types/src/datacategory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export type DataCategory =
1010
| 'error'
1111
// Transaction type event
1212
| 'transaction'
13+
// Replay type event
14+
| 'replay_event'
1315
// Events with `event_type` csp, hpkp, expectct, expectstaple
1416
| 'security'
1517
// Attachment bytes stored (unused for rate limiting

packages/types/src/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface Event {
6363
* Note that `ErrorEvent`s do not have a type (hence its undefined),
6464
* while all other events are required to have one.
6565
*/
66-
export type EventType = 'transaction' | 'profile' | undefined;
66+
export type EventType = 'transaction' | 'profile' | 'replay_event' | undefined;
6767

6868
export interface ErrorEvent extends Event {
6969
type: undefined;

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type {
2525
UserFeedbackItem,
2626
} from './envelope';
2727
export type { ExtendedError } from './error';
28-
export type { Event, EventHint, ErrorEvent, TransactionEvent } from './event';
28+
export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent } from './event';
2929
export type { EventProcessor } from './eventprocessor';
3030
export type { Exception } from './exception';
3131
export type { Extra, Extras } from './extra';

0 commit comments

Comments
 (0)