@sentry/replay 0.4.1 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ Sentry.init({
37
37
  integrations: [
38
38
  new SentryReplay({
39
39
  stickySession: true, // Default is false
40
- rrwebConfig: {
40
+ recordingConfig: {
41
41
  maskAllInputs: false, // Default is true
42
42
  },
43
43
  }),
@@ -1,2 +1,3 @@
1
1
  import type { Session } from '@/session/Session';
2
- export declare function captureReplay(session: Session): void;
2
+ import { InitialState } from '@/types';
3
+ export declare function captureReplay(session: Session, initialState: InitialState): void;
@@ -1,4 +1,4 @@
1
- import { RRWebEvent } from './types';
1
+ import { RecordingEvent } from './types';
2
2
  interface CreateEventBufferParams {
3
3
  useCompression: boolean;
4
4
  }
@@ -6,15 +6,15 @@ export declare function createEventBuffer({ useCompression }: CreateEventBufferP
6
6
  export interface IEventBuffer {
7
7
  get length(): number;
8
8
  destroy(): void;
9
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
9
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
10
10
  finish(): Promise<string | Uint8Array>;
11
11
  }
12
12
  declare class EventBufferArray implements IEventBuffer {
13
- events: RRWebEvent[];
13
+ events: RecordingEvent[];
14
14
  constructor();
15
15
  destroy(): void;
16
16
  get length(): number;
17
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
17
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
18
18
  finish(): Promise<string>;
19
19
  }
20
20
  export declare class EventBufferCompressionWorker implements IEventBuffer {
@@ -24,8 +24,8 @@ export declare class EventBufferCompressionWorker implements IEventBuffer {
24
24
  init(): void;
25
25
  destroy(): void;
26
26
  get length(): number;
27
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
28
- sendEventToWorker(event: RRWebEvent): void;
27
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
28
+ sendEventToWorker(event: RecordingEvent): void;
29
29
  finish(): Promise<Uint8Array>;
30
30
  }
31
31
  export {};
@@ -1,10 +1,10 @@
1
- import { DsnComponents, Integration, Breadcrumb } from '@sentry/types';
1
+ import { DsnComponents, Event, Integration, Breadcrumb } from '@sentry/types';
2
2
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
3
3
  import { IEventBuffer } from './eventBuffer';
4
- import type { RRWebOptions, ReplaySpan, ReplayRequest, InstrumentationType, SentryReplayPluginOptions, SentryReplayConfiguration } from './types';
4
+ import type { InstrumentationType, RecordingEvent, RecordingConfig, ReplaySpan, ReplayRequest, SentryReplayPluginOptions, SentryReplayConfiguration } from './types';
5
5
  import { Session } from './session/Session';
6
6
  /**
7
- * Returns true if we want to flush immediately, otherwise continue with normal batching
7
+ * Returns true to return control to calling function, otherwise continue with normal batching
8
8
  */
9
9
  declare type AddUpdateCallback = () => boolean | void;
10
10
  export declare class SentryReplay implements Integration {
@@ -32,15 +32,16 @@ export declare class SentryReplay implements Integration {
32
32
  /**
33
33
  * Options to pass to `rrweb.record()`
34
34
  */
35
- readonly rrwebRecordOptions: RRWebOptions;
35
+ readonly recordingOptions: RecordingConfig;
36
36
  readonly options: SentryReplayPluginOptions;
37
37
  /**
38
38
  * setTimeout id used for debouncing sending rrweb attachments
39
39
  */
40
40
  private timeout;
41
41
  /**
42
- * The timestamp of the first event since the last flush.
43
- * This is used to determine if the maximum allowed time has passed before we should flush events again.
42
+ * The timestamp of the first event since the last flush. This is used to
43
+ * determine if the maximum allowed time has passed before events should be
44
+ * flushed again.
44
45
  */
45
46
  private initialEventTimestampSinceFlush;
46
47
  private performanceObserver;
@@ -53,19 +54,25 @@ export declare class SentryReplay implements Integration {
53
54
  * immediately before sending recording)
54
55
  */
55
56
  private needsCaptureReplay;
57
+ private initialState;
56
58
  session: Session | undefined;
57
59
  static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
58
- constructor({ uploadMinDelay, uploadMaxDelay, stickySession, // TBD: Making this opt-in for now
59
- useCompression, rrwebConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...rrwebRecordOptions }, }?: SentryReplayConfiguration);
60
+ constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
61
+ useCompression, captureOnlyOnError, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
60
62
  setupOnce(): void;
63
+ /**
64
+ * Initializes the plugin.
65
+ *
66
+ * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
67
+ */
61
68
  setup(): void;
62
69
  /**
63
70
  * We want to batch uploads of replay events. Save events only if
64
- * `<uploadMinDelay>` milliseconds have elapsed since the last event
65
- * *OR* if `<uploadMaxDelay>` milliseconds have elapsed.
71
+ * `<flushMinDelay>` milliseconds have elapsed since the last event
72
+ * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
66
73
  *
67
- * Accepts a callback to perform side-effects and returns a boolean value if we
68
- * should flush events immediately
74
+ * Accepts a callback to perform side-effects and returns true to stop batch
75
+ * processing and hand back control to caller.
69
76
  */
70
77
  addUpdate(cb?: AddUpdateCallback): void;
71
78
  /**
@@ -80,8 +87,26 @@ export declare class SentryReplay implements Integration {
80
87
  loadSession({ expiry }: {
81
88
  expiry: number;
82
89
  }): void;
90
+ /**
91
+ * Adds listeners to record events for the replay
92
+ */
83
93
  addListeners(): void;
94
+ /**
95
+ * Cleans up listeners that were created in `addListeners`
96
+ */
84
97
  removeListeners(): void;
98
+ /**
99
+ * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
100
+ * events as a tag. Also handles the case where we only want to capture a reply
101
+ * when an error occurs.
102
+ **/
103
+ handleGlobalEvent: (event: Event) => Event;
104
+ /**
105
+ * Handler for recording events.
106
+ *
107
+ * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
108
+ */
109
+ handleRecordingEmit: (event: RecordingEvent, isCheckout?: boolean) => void;
85
110
  /**
86
111
  * Handle when visibility of the page content changes. Opening a new tab will
87
112
  * cause the state to change to hidden because of content of current page will
@@ -97,7 +122,16 @@ export declare class SentryReplay implements Integration {
97
122
  * Handle when page is focused
98
123
  */
99
124
  handleWindowFocus: () => void;
125
+ /**
126
+ * Handle when page is closed
127
+ */
100
128
  handleWindowUnload: () => void;
129
+ /**
130
+ * Handler for Sentry Core SDK events.
131
+ *
132
+ * Transforms core SDK events into replay events.
133
+ *
134
+ */
101
135
  handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
102
136
  /**
103
137
  * Keep a list of performance entries that will be sent with a replay
@@ -116,7 +150,13 @@ export declare class SentryReplay implements Integration {
116
150
  * create a new Replay event.
117
151
  */
118
152
  triggerFullSnapshot(): void;
153
+ /**
154
+ * Updates the session's last activity timestamp
155
+ */
119
156
  updateLastActivity(lastActivity?: number): void;
157
+ /**
158
+ * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
159
+ */
120
160
  createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
121
161
  /**
122
162
  * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
@@ -133,11 +173,17 @@ export declare class SentryReplay implements Integration {
133
173
  * Returns true if session is not expired, false otherwise.
134
174
  */
135
175
  checkAndHandleExpiredSession(expiry?: number): boolean;
136
- flushUpdate(lastActivity?: number): Promise<void>;
137
176
  /**
138
- * Determine if there is browser support for `navigator.sendBeacon`
177
+ * Only flush if `captureOnlyOnError` is false.
178
+ */
179
+ conditionalFlush(lastActivity?: number): Promise<void>;
180
+ /**
181
+ * Flushes replay event buffer to Sentry.
182
+ *
183
+ * Performance events are only added right before flushing - this is probably
184
+ * due to the buffered performance observer events.
139
185
  */
140
- hasSendBeacon(): boolean;
186
+ flushUpdate(lastActivity?: number): Promise<void>;
141
187
  /**
142
188
  * Send replay attachment using either `sendBeacon()` or `fetch()`
143
189
  */
@@ -33,6 +33,10 @@ export declare class Session {
33
33
  * Sequence ID specific to replay updates
34
34
  */
35
35
  private _sequenceId;
36
+ /**
37
+ * Previous session ID
38
+ */
39
+ private _previousSessionId;
36
40
  readonly options: Required<SessionOptions>;
37
41
  constructor(session?: Partial<SessionObject>, { stickySession }?: SessionOptions);
38
42
  get id(): string;
@@ -41,6 +45,8 @@ export declare class Session {
41
45
  set lastActivity(newDate: number);
42
46
  get sequenceId(): number;
43
47
  set sequenceId(id: number);
48
+ get previousSessionId(): string;
49
+ set previousSessionId(id: string);
44
50
  toJSON(): SessionObject;
45
51
  }
46
52
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { eventWithTime } from 'rrweb/typings/types';
2
2
  import { record } from 'rrweb';
3
- export declare type RRWebEvent = eventWithTime;
4
- export declare type RRWebOptions = Parameters<typeof record>[0];
3
+ export declare type RecordingEvent = eventWithTime;
4
+ export declare type RecordingConfig = Parameters<typeof record>[0];
5
5
  export interface ReplaySpan {
6
6
  description: string;
7
7
  op: string;
@@ -33,11 +33,15 @@ export interface SentryReplayPluginOptions {
33
33
  /**
34
34
  * The amount of time to wait before sending a replay
35
35
  */
36
- uploadMinDelay?: number;
36
+ flushMinDelay?: number;
37
37
  /**
38
38
  * The max amount of time to wait before sending a replay
39
39
  */
40
- uploadMaxDelay?: number;
40
+ flushMaxDelay?: number;
41
+ /**
42
+ * The amount of time to buffer the initial snapshot
43
+ */
44
+ initialFlushDelay?: number;
41
45
  /**
42
46
  * If false, will create a new session per pageload
43
47
  */
@@ -48,10 +52,21 @@ export interface SentryReplayPluginOptions {
48
52
  * (default is true)
49
53
  */
50
54
  useCompression?: boolean;
55
+ /**
56
+ * Only capture replays when an error happens
57
+ */
58
+ captureOnlyOnError?: boolean;
51
59
  }
52
60
  export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
53
61
  /**
54
- * Options for `rrweb.recordsetup
62
+ * Options for `rrweb.record()`
55
63
  */
56
- rrwebConfig?: RRWebOptions;
64
+ recordingConfig?: RecordingConfig;
65
+ }
66
+ /**
67
+ * Some initial state captured before creating a root replay event
68
+ */
69
+ export interface InitialState {
70
+ timestamp: number;
71
+ url: string;
57
72
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine if there is browser support for `navigator.sendBeacon`
3
+ */
4
+ export declare function supportsSendBeacon(): boolean;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="jest" />
2
- import { RRWebEvent } from '@/types';
2
+ import { RecordingEvent } from '@/types';
3
3
  declare type RecordAdditionalProperties = {
4
4
  takeFullSnapshot: jest.Mock;
5
5
  addCustomEvent: () => void;
6
6
  freezePage: () => void;
7
7
  mirror: unknown;
8
- _emitter: (event: RRWebEvent, ...args: any[]) => void;
8
+ _emitter: (event: RecordingEvent, ...args: any[]) => void;
9
9
  };
10
10
  export declare type RecordMock = jest.MockedFunction<typeof rrweb.record> & RecordAdditionalProperties;
11
11
  import * as rrweb from 'rrweb';
@@ -1,2 +1,3 @@
1
1
  import type { Session } from '@/session/Session';
2
- export declare function captureReplay(session: Session): void;
2
+ import { InitialState } from '@/types';
3
+ export declare function captureReplay(session: Session, initialState: InitialState): void;
@@ -1,4 +1,4 @@
1
- import { RRWebEvent } from './types';
1
+ import { RecordingEvent } from './types';
2
2
  interface CreateEventBufferParams {
3
3
  useCompression: boolean;
4
4
  }
@@ -6,15 +6,15 @@ export declare function createEventBuffer({ useCompression }: CreateEventBufferP
6
6
  export interface IEventBuffer {
7
7
  get length(): number;
8
8
  destroy(): void;
9
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
9
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
10
10
  finish(): Promise<string | Uint8Array>;
11
11
  }
12
12
  declare class EventBufferArray implements IEventBuffer {
13
- events: RRWebEvent[];
13
+ events: RecordingEvent[];
14
14
  constructor();
15
15
  destroy(): void;
16
16
  get length(): number;
17
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
17
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
18
18
  finish(): Promise<string>;
19
19
  }
20
20
  export declare class EventBufferCompressionWorker implements IEventBuffer {
@@ -24,8 +24,8 @@ export declare class EventBufferCompressionWorker implements IEventBuffer {
24
24
  init(): void;
25
25
  destroy(): void;
26
26
  get length(): number;
27
- addEvent(event: RRWebEvent, isCheckout?: boolean): void;
28
- sendEventToWorker(event: RRWebEvent): void;
27
+ addEvent(event: RecordingEvent, isCheckout?: boolean): void;
28
+ sendEventToWorker(event: RecordingEvent): void;
29
29
  finish(): Promise<Uint8Array>;
30
30
  }
31
31
  export {};
@@ -1,7 +1,7 @@
1
- import { DsnComponents, Integration, Breadcrumb } from '@sentry/types';
1
+ import { DsnComponents, Event, Integration, Breadcrumb } from '@sentry/types';
2
2
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
3
3
  import { IEventBuffer } from './eventBuffer';
4
- import type { RRWebOptions, ReplaySpan, ReplayRequest, InstrumentationType, SentryReplayPluginOptions, SentryReplayConfiguration } from './types';
4
+ import type { InstrumentationType, RecordingEvent, RecordingConfig, ReplaySpan, ReplayRequest, SentryReplayPluginOptions, SentryReplayConfiguration } from './types';
5
5
  import { Session } from './session/Session';
6
6
  /**
7
7
  * Returns true to return control to calling function, otherwise continue with normal batching
@@ -32,7 +32,7 @@ export declare class SentryReplay implements Integration {
32
32
  /**
33
33
  * Options to pass to `rrweb.record()`
34
34
  */
35
- readonly rrwebRecordOptions: RRWebOptions;
35
+ readonly recordingOptions: RecordingConfig;
36
36
  readonly options: SentryReplayPluginOptions;
37
37
  /**
38
38
  * setTimeout id used for debouncing sending rrweb attachments
@@ -54,11 +54,17 @@ export declare class SentryReplay implements Integration {
54
54
  * immediately before sending recording)
55
55
  */
56
56
  private needsCaptureReplay;
57
+ private initialState;
57
58
  session: Session | undefined;
58
59
  static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
59
60
  constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
60
- useCompression, rrwebConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...rrwebRecordOptions }, }?: SentryReplayConfiguration);
61
+ useCompression, captureOnlyOnError, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
61
62
  setupOnce(): void;
63
+ /**
64
+ * Initializes the plugin.
65
+ *
66
+ * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
67
+ */
62
68
  setup(): void;
63
69
  /**
64
70
  * We want to batch uploads of replay events. Save events only if
@@ -81,8 +87,26 @@ export declare class SentryReplay implements Integration {
81
87
  loadSession({ expiry }: {
82
88
  expiry: number;
83
89
  }): void;
90
+ /**
91
+ * Adds listeners to record events for the replay
92
+ */
84
93
  addListeners(): void;
94
+ /**
95
+ * Cleans up listeners that were created in `addListeners`
96
+ */
85
97
  removeListeners(): void;
98
+ /**
99
+ * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
100
+ * events as a tag. Also handles the case where we only want to capture a reply
101
+ * when an error occurs.
102
+ **/
103
+ handleGlobalEvent: (event: Event) => Event;
104
+ /**
105
+ * Handler for recording events.
106
+ *
107
+ * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
108
+ */
109
+ handleRecordingEmit: (event: RecordingEvent, isCheckout?: boolean) => void;
86
110
  /**
87
111
  * Handle when visibility of the page content changes. Opening a new tab will
88
112
  * cause the state to change to hidden because of content of current page will
@@ -98,7 +122,16 @@ export declare class SentryReplay implements Integration {
98
122
  * Handle when page is focused
99
123
  */
100
124
  handleWindowFocus: () => void;
125
+ /**
126
+ * Handle when page is closed
127
+ */
101
128
  handleWindowUnload: () => void;
129
+ /**
130
+ * Handler for Sentry Core SDK events.
131
+ *
132
+ * Transforms core SDK events into replay events.
133
+ *
134
+ */
102
135
  handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
103
136
  /**
104
137
  * Keep a list of performance entries that will be sent with a replay
@@ -117,7 +150,13 @@ export declare class SentryReplay implements Integration {
117
150
  * create a new Replay event.
118
151
  */
119
152
  triggerFullSnapshot(): void;
153
+ /**
154
+ * Updates the session's last activity timestamp
155
+ */
120
156
  updateLastActivity(lastActivity?: number): void;
157
+ /**
158
+ * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
159
+ */
121
160
  createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
122
161
  /**
123
162
  * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
@@ -134,11 +173,17 @@ export declare class SentryReplay implements Integration {
134
173
  * Returns true if session is not expired, false otherwise.
135
174
  */
136
175
  checkAndHandleExpiredSession(expiry?: number): boolean;
137
- flushUpdate(lastActivity?: number): Promise<void>;
138
176
  /**
139
- * Determine if there is browser support for `navigator.sendBeacon`
177
+ * Only flush if `captureOnlyOnError` is false.
178
+ */
179
+ conditionalFlush(lastActivity?: number): Promise<void>;
180
+ /**
181
+ * Flushes replay event buffer to Sentry.
182
+ *
183
+ * Performance events are only added right before flushing - this is probably
184
+ * due to the buffered performance observer events.
140
185
  */
141
- hasSendBeacon(): boolean;
186
+ flushUpdate(lastActivity?: number): Promise<void>;
142
187
  /**
143
188
  * Send replay attachment using either `sendBeacon()` or `fetch()`
144
189
  */
@@ -1,7 +1,7 @@
1
1
  import type { eventWithTime } from 'rrweb/typings/types';
2
2
  import { record } from 'rrweb';
3
- export declare type RRWebEvent = eventWithTime;
4
- export declare type RRWebOptions = Parameters<typeof record>[0];
3
+ export declare type RecordingEvent = eventWithTime;
4
+ export declare type RecordingConfig = Parameters<typeof record>[0];
5
5
  export interface ReplaySpan {
6
6
  description: string;
7
7
  op: string;
@@ -52,10 +52,21 @@ export interface SentryReplayPluginOptions {
52
52
  * (default is true)
53
53
  */
54
54
  useCompression?: boolean;
55
+ /**
56
+ * Only capture replays when an error happens
57
+ */
58
+ captureOnlyOnError?: boolean;
55
59
  }
56
60
  export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
57
61
  /**
58
- * Options for `rrweb.recordsetup
62
+ * Options for `rrweb.record()`
59
63
  */
60
- rrwebConfig?: RRWebOptions;
64
+ recordingConfig?: RecordingConfig;
65
+ }
66
+ /**
67
+ * Some initial state captured before creating a root replay event
68
+ */
69
+ export interface InitialState {
70
+ timestamp: number;
71
+ url: string;
61
72
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine if there is browser support for `navigator.sendBeacon`
3
+ */
4
+ export declare function supportsSendBeacon(): boolean;