@sentry/replay 0.4.5 → 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,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;
@@ -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;