@sentry/replay 0.6.10 → 0.6.11

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.
Files changed (76) hide show
  1. package/README.md +10 -7
  2. package/dist/index.es.js +99 -47
  3. package/dist/index.js +98 -46
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/src/index.d.ts +8 -4
  6. package/dist/types/src/session/Session.d.ts +4 -6
  7. package/dist/types/src/session/constants.d.ts +5 -0
  8. package/dist/types/src/session/createSession.d.ts +2 -13
  9. package/dist/types/src/session/fetchSession.d.ts +2 -1
  10. package/dist/types/src/session/getSession.d.ts +3 -11
  11. package/dist/types/src/types.d.ts +39 -13
  12. package/dist/types/src/util/isSampled.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/dist/config/types/jest.config.d.ts +0 -3
  15. package/dist/config/types/jest.setup.d.ts +0 -32
  16. package/dist/config/types/src/blockAllMedia.test.d.ts +0 -1
  17. package/dist/config/types/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
  18. package/dist/config/types/src/coreHandlers/getSpanHandler.d.ts +0 -5
  19. package/dist/config/types/src/coreHandlers/handleDom.d.ts +0 -1
  20. package/dist/config/types/src/coreHandlers/handleFetch.d.ts +0 -19
  21. package/dist/config/types/src/coreHandlers/handleFetch.test.d.ts +0 -1
  22. package/dist/config/types/src/coreHandlers/handleHistory.d.ts +0 -7
  23. package/dist/config/types/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  24. package/dist/config/types/src/coreHandlers/handleScope.d.ts +0 -2
  25. package/dist/config/types/src/coreHandlers/handleScope.test.d.ts +0 -1
  26. package/dist/config/types/src/coreHandlers/handleXhr.d.ts +0 -21
  27. package/dist/config/types/src/createPerformanceEntry.d.ts +0 -43
  28. package/dist/config/types/src/createPerformanceEntry.test.d.ts +0 -1
  29. package/dist/config/types/src/eventBuffer.d.ts +0 -45
  30. package/dist/config/types/src/eventBuffer.test.d.ts +0 -1
  31. package/dist/config/types/src/flags.d.ts +0 -2
  32. package/dist/config/types/src/flush.test.d.ts +0 -1
  33. package/dist/config/types/src/index-captureOnlyOnError.test.d.ts +0 -1
  34. package/dist/config/types/src/index-noSticky.test.d.ts +0 -1
  35. package/dist/config/types/src/index-sampling.test.d.ts +0 -1
  36. package/dist/config/types/src/index.d.ts +0 -289
  37. package/dist/config/types/src/index.test.d.ts +0 -1
  38. package/dist/config/types/src/multiple-instances.test.d.ts +0 -1
  39. package/dist/config/types/src/session/Session.d.ts +0 -63
  40. package/dist/config/types/src/session/Session.test.d.ts +0 -1
  41. package/dist/config/types/src/session/constants.d.ts +0 -6
  42. package/dist/config/types/src/session/createSession.d.ts +0 -19
  43. package/dist/config/types/src/session/createSession.test.d.ts +0 -1
  44. package/dist/config/types/src/session/deleteSession.d.ts +0 -4
  45. package/dist/config/types/src/session/deleteSession.test.d.ts +0 -1
  46. package/dist/config/types/src/session/fetchSession.d.ts +0 -5
  47. package/dist/config/types/src/session/fetchSession.test.d.ts +0 -1
  48. package/dist/config/types/src/session/getSession.d.ts +0 -28
  49. package/dist/config/types/src/session/getSession.test.d.ts +0 -1
  50. package/dist/config/types/src/session/index.d.ts +0 -1
  51. package/dist/config/types/src/session/saveSession.d.ts +0 -2
  52. package/dist/config/types/src/session/saveSession.test.d.ts +0 -1
  53. package/dist/config/types/src/stop.test.d.ts +0 -1
  54. package/dist/config/types/src/types.d.ts +0 -105
  55. package/dist/config/types/src/util/addInternalBreadcrumb.d.ts +0 -5
  56. package/dist/config/types/src/util/captureInternalException.d.ts +0 -4
  57. package/dist/config/types/src/util/createBreadcrumb.d.ts +0 -4
  58. package/dist/config/types/src/util/createPayload.d.ts +0 -5
  59. package/dist/config/types/src/util/dedupePerformanceEntries.d.ts +0 -10
  60. package/dist/config/types/src/util/dedupePerformanceEntries.test.d.ts +0 -1
  61. package/dist/config/types/src/util/isExpired.d.ts +0 -5
  62. package/dist/config/types/src/util/isExpired.test.d.ts +0 -1
  63. package/dist/config/types/src/util/isIngestHost.d.ts +0 -4
  64. package/dist/config/types/src/util/isInternal.d.ts +0 -5
  65. package/dist/config/types/src/util/isSampled.d.ts +0 -7
  66. package/dist/config/types/src/util/isSampled.test.d.ts +0 -1
  67. package/dist/config/types/src/util/isSessionExpired.d.ts +0 -5
  68. package/dist/config/types/src/util/isSessionExpired.test.d.ts +0 -1
  69. package/dist/config/types/src/util/logger.d.ts +0 -12
  70. package/dist/config/types/src/util/supportsSendBeacon.d.ts +0 -4
  71. package/dist/config/types/test/fixtures/performanceEntry/lcp.d.ts +0 -1
  72. package/dist/config/types/test/fixtures/performanceEntry/navigation.d.ts +0 -1
  73. package/dist/config/types/test/fixtures/performanceEntry/resource.d.ts +0 -1
  74. package/dist/config/types/test/index.d.ts +0 -3
  75. package/dist/config/types/test/mocks/mockRrweb.d.ts +0 -15
  76. package/dist/config/types/test/mocks/mockSdk.d.ts +0 -10
@@ -40,12 +40,16 @@ export declare class Replay implements Integration {
40
40
  */
41
41
  private isEnabled;
42
42
  /**
43
- *
44
43
  * Paused is a state where:
45
44
  * - DOM Recording is not listening at all
46
45
  * - Nothing will be added to event buffer (e.g. core SDK events)
47
46
  */
48
47
  private isPaused;
48
+ /**
49
+ * Integration will wait until an error occurs before creating and sending a
50
+ * replay.
51
+ */
52
+ private waitForError;
49
53
  /**
50
54
  * Have we attached listeners to the core SDK?
51
55
  * Note we have to track this as there is no way to remove instrumentation handlers.
@@ -61,7 +65,7 @@ export declare class Replay implements Integration {
61
65
  private initialState;
62
66
  private context;
63
67
  session: Session | undefined;
64
- constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, useCompression, captureOnlyOnError, replaysSamplingRate, maskAllText, maskAllInputs, blockAllMedia, blockClass, ignoreClass, maskTextClass, blockSelector, ...recordingOptions }?: ReplayConfiguration);
68
+ constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, useCompression, sessionSampleRate, errorSampleRate, maskAllText, maskAllInputs, blockAllMedia, blockClass, ignoreClass, maskTextClass, blockSelector, replaysSamplingRate, captureOnlyOnError, ...recordingOptions }?: ReplayConfiguration);
65
69
  /**
66
70
  * Because we create a transaction in `setupOnce`, we can potentially create a
67
71
  * transaction before some native SDK integrations have run and applied their
@@ -234,7 +238,7 @@ export declare class Replay implements Integration {
234
238
  expiry?: number;
235
239
  }): boolean | undefined;
236
240
  /**
237
- * Only flush if `captureOnlyOnError` is false.
241
+ * Only flush if `this.waitForError` is false.
238
242
  */
239
243
  conditionalFlush(): void;
240
244
  /**
@@ -270,7 +274,7 @@ export declare class Replay implements Integration {
270
274
  * from calling both `flush` and `debouncedFlush`. Otherwise, there could be
271
275
  * cases of mulitple flushes happening closely together.
272
276
  */
273
- flushImmediate(): void;
277
+ flushImmediate(): any;
274
278
  /**
275
279
  * Send replay attachment using `fetch()`
276
280
  */
@@ -1,3 +1,5 @@
1
+ import { SampleRates, SessionOptions } from '../types';
2
+ declare type StickyOption = Required<Pick<SessionOptions, 'stickySession'>>;
1
3
  interface SessionObject {
2
4
  id: string;
3
5
  /**
@@ -17,10 +19,6 @@ interface SessionObject {
17
19
  */
18
20
  sampled: boolean;
19
21
  }
20
- interface SessionOptions {
21
- stickySession?: boolean;
22
- samplingRate?: number;
23
- }
24
22
  export declare class Session {
25
23
  /**
26
24
  * Session ID
@@ -46,8 +44,8 @@ export declare class Session {
46
44
  * Is the Session sampled?
47
45
  */
48
46
  private _sampled;
49
- readonly options: Required<Pick<SessionOptions, 'stickySession'>>;
50
- constructor(session?: Partial<SessionObject>, { stickySession, samplingRate }?: SessionOptions);
47
+ readonly options: StickyOption;
48
+ constructor(session: Partial<SessionObject> | undefined, { stickySession, sessionSampleRate, errorSampleRate, }: StickyOption & SampleRates);
51
49
  get id(): string;
52
50
  get started(): number;
53
51
  get lastActivity(): number;
@@ -4,3 +4,8 @@ export declare const RECORDING_EVENT_NAME = "replay_recording";
4
4
  export declare const SESSION_IDLE_DURATION = 300000;
5
5
  export declare const VISIBILITY_CHANGE_TIMEOUT = 300000;
6
6
  export declare const MAX_SESSION_LIFE = 1800000;
7
+ /**
8
+ * Defaults for sampling rates
9
+ */
10
+ export declare const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
11
+ export declare const DEFAULT_ERROR_SAMPLE_RATE = 1;
@@ -1,19 +1,8 @@
1
+ import { SessionOptions } from '../types';
1
2
  import { Session } from './Session';
2
- interface CreateSessionParams {
3
- /**
4
- * Should save to sessionStorage?
5
- */
6
- stickySession: boolean;
7
- /**
8
- * The sampling rate of the Session. See integration configuration comments
9
- * for `replaysSamplingRate`.
10
- */
11
- samplingRate?: number;
12
- }
13
3
  /**
14
4
  * Create a new session, which in its current implementation is a Sentry event
15
5
  * that all replays will be saved to as attachments. Currently, we only expect
16
6
  * one of these Sentry events per "replay session".
17
7
  */
18
- export declare function createSession({ stickySession, samplingRate, }: CreateSessionParams): Session;
19
- export {};
8
+ export declare function createSession({ sessionSampleRate, errorSampleRate, stickySession, }: SessionOptions): Session;
@@ -1,5 +1,6 @@
1
+ import { SampleRates } from '../types';
1
2
  import { Session } from './Session';
2
3
  /**
3
4
  * Fetches a session from storage
4
5
  */
5
- export declare function fetchSession(): Session | null;
6
+ export declare function fetchSession({ sessionSampleRate, errorSampleRate, }: SampleRates): Session | null;
@@ -1,27 +1,19 @@
1
+ import { SessionOptions } from '../types';
1
2
  import { Session } from './Session';
2
- interface GetSessionParams {
3
+ interface GetSessionParams extends SessionOptions {
3
4
  /**
4
5
  * The length of time (in ms) which we will consider the session to be expired.
5
6
  */
6
7
  expiry: number;
7
- /**
8
- * Should save session to sessionStorage?
9
- */
10
- stickySession: boolean;
11
8
  /**
12
9
  * The current session (e.g. if stickySession is off)
13
10
  */
14
11
  currentSession?: Session;
15
- /**
16
- * The sampling rate of the Session. See integration configuration comments
17
- * for `replaysSamplingRate`.
18
- */
19
- samplingRate?: number;
20
12
  }
21
13
  /**
22
14
  * Get or create a session
23
15
  */
24
- export declare function getSession({ expiry, currentSession, stickySession, samplingRate, }: GetSessionParams): {
16
+ export declare function getSession({ expiry, currentSession, stickySession, sessionSampleRate, errorSampleRate, }: GetSessionParams): {
25
17
  type: string;
26
18
  session: Session;
27
19
  };
@@ -33,47 +33,72 @@ export interface WorkerResponse {
33
33
  success: boolean;
34
34
  response: string | Uint8Array;
35
35
  }
36
- export interface ReplayPluginOptions {
36
+ export interface SampleRates {
37
+ /**
38
+ * The sample rate for session-long replays. 1.0 will record all sessions and
39
+ * 0 will record none.
40
+ */
41
+ sessionSampleRate: number;
42
+ /**
43
+ * The sample rate for sessions that has had an error occur. This is
44
+ * independent of `sessionSampleRate`.
45
+ */
46
+ errorSampleRate: number;
47
+ }
48
+ /**
49
+ * Session options that are configurable by the integration configuration
50
+ */
51
+ export interface SessionOptions extends SampleRates {
52
+ /**
53
+ * If false, will create a new session per pageload. Otherwise, saves session
54
+ * to Session Storage.
55
+ */
56
+ stickySession: boolean;
57
+ }
58
+ export interface ReplayPluginOptions extends SessionOptions {
37
59
  /**
38
60
  * The amount of time to wait before sending a replay
39
61
  */
40
- flushMinDelay?: number;
62
+ flushMinDelay: number;
41
63
  /**
42
64
  * The max amount of time to wait before sending a replay
43
65
  */
44
- flushMaxDelay?: number;
66
+ flushMaxDelay: number;
45
67
  /**
46
68
  * The amount of time to buffer the initial snapshot
47
69
  */
48
- initialFlushDelay?: number;
49
- /**
50
- * If false, will create a new session per pageload
51
- */
52
- stickySession?: boolean;
70
+ initialFlushDelay: number;
53
71
  /**
54
72
  * Attempt to use compression when web workers are available
55
73
  *
56
74
  * (default is true)
57
75
  */
58
- useCompression?: boolean;
76
+ useCompression: boolean;
59
77
  /**
60
78
  * Only capture replays when an error happens
79
+ *
80
+ * @deprecated
81
+ * @see errorSampleRate
61
82
  */
62
83
  captureOnlyOnError?: boolean;
63
84
  /**
64
- * The sampling rate for replays. 1.0 will record all replays, 0 will record none.
85
+ * The sample rate for replays. 1.0 will record all replays, 0 will record none.
86
+ *
87
+ * @deprecated
88
+ * @see sessionSampleRate
65
89
  */
66
90
  replaysSamplingRate?: number;
67
91
  /**
68
92
  * Mask all text in recordings. All text will be replaced with asterisks by default.
69
93
  */
70
- maskAllText?: boolean;
94
+ maskAllText: boolean;
71
95
  /**
72
96
  * Block all media (e.g. images, svg, video) in recordings.
73
97
  */
74
- blockAllMedia?: boolean;
98
+ blockAllMedia: boolean;
75
99
  }
76
- export interface ReplayConfiguration extends ReplayPluginOptions, RecordingOptions {
100
+ declare type OptionalReplayPluginOptions = Partial<ReplayPluginOptions>;
101
+ export interface ReplayConfiguration extends OptionalReplayPluginOptions, RecordingOptions {
77
102
  }
78
103
  /**
79
104
  * Some initial state captured before creating a root replay event
@@ -103,3 +128,4 @@ export interface ReplayEventContext {
103
128
  */
104
129
  earliestEvent: number | null;
105
130
  }
131
+ export {};
@@ -4,4 +4,4 @@
4
4
  * 1.0 = 100% sampling
5
5
  * 0.0 = 0% sampling
6
6
  */
7
- export declare function isSampled(sampleRate: number): boolean;
7
+ export declare function isSampled(sampleRate?: number): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/replay",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "User replays for Sentry",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -1,3 +0,0 @@
1
- import type { Config } from '@jest/types';
2
- declare const _default: () => Promise<Config.InitialOptions>;
3
- export default _default;
@@ -1,32 +0,0 @@
1
- import { Session } from './src/session/Session';
2
- declare type SentReplayExpected = {
3
- envelopeHeader?: {
4
- event_id: string;
5
- sent_at: string;
6
- sdk: {
7
- name: string;
8
- version?: string;
9
- };
10
- };
11
- replayEventHeader?: {
12
- type: 'replay_event';
13
- };
14
- replayEventPayload?: Record<string, any>;
15
- recordingHeader?: {
16
- type: 'replay_recording';
17
- length: number;
18
- };
19
- recordingPayloadHeader?: Record<string, any>;
20
- events?: string | Uint8Array;
21
- };
22
- declare module 'expect' {
23
- interface AsymmetricMatchers {
24
- toHaveSentReplay(expected?: SentReplayExpected): void;
25
- toHaveSameSession(expected: undefined | Session): void;
26
- }
27
- interface Matchers<R> {
28
- toHaveSentReplay(expected?: SentReplayExpected): R;
29
- toHaveSameSession(expected: undefined | Session): R;
30
- }
31
- }
32
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { InstrumentationTypeBreadcrumb } from '../types';
2
- import { handleScope } from './handleScope';
3
- export declare function getBreadcrumbHandler(type: InstrumentationTypeBreadcrumb): typeof handleScope;
@@ -1,5 +0,0 @@
1
- import { InstrumentationTypeSpan } from '../types';
2
- import { handleFetch } from './handleFetch';
3
- import { handleHistory } from './handleHistory';
4
- import { handleXhr } from './handleXhr';
5
- export declare function getSpanHandler(type: InstrumentationTypeSpan): typeof handleFetch | typeof handleXhr | typeof handleHistory;
@@ -1 +0,0 @@
1
- export declare function handleDom(handlerData: any): import("@sentry/types").Breadcrumb | null;
@@ -1,19 +0,0 @@
1
- import { ReplayPerformanceEntry } from '../createPerformanceEntry';
2
- interface FetchHandlerData {
3
- args: Parameters<typeof fetch>;
4
- fetchData: {
5
- method: string;
6
- url: string;
7
- };
8
- response: {
9
- type: string;
10
- url: string;
11
- redirected: boolean;
12
- status: number;
13
- ok: boolean;
14
- };
15
- startTimestamp: number;
16
- endTimestamp?: number;
17
- }
18
- export declare function handleFetch(handlerData: FetchHandlerData): null | ReplayPerformanceEntry;
19
- export {};
@@ -1,7 +0,0 @@
1
- import { ReplayPerformanceEntry } from '../createPerformanceEntry';
2
- interface HistoryHandlerData {
3
- from: string;
4
- to: string;
5
- }
6
- export declare function handleHistory(handlerData: HistoryHandlerData): ReplayPerformanceEntry;
7
- export {};
@@ -1,2 +0,0 @@
1
- import { Breadcrumb, Scope } from '@sentry/types';
2
- export declare function handleScope(scope: Scope): Breadcrumb | null;
@@ -1,21 +0,0 @@
1
- import { ReplayPerformanceEntry } from '../createPerformanceEntry';
2
- declare type XHRSendInput = null | Blob | BufferSource | FormData | URLSearchParams | string;
3
- interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
4
- [key: string]: unknown;
5
- __sentry_xhr__?: {
6
- method?: string;
7
- url?: string;
8
- status_code?: number;
9
- body?: XHRSendInput;
10
- startTimestamp?: number;
11
- };
12
- __sentry_own_request__?: boolean;
13
- }
14
- interface XhrHandlerData {
15
- args: [method: string, url: string];
16
- xhr: SentryWrappedXMLHttpRequest;
17
- startTimestamp: number;
18
- endTimestamp?: number;
19
- }
20
- export declare function handleXhr(handlerData: XhrHandlerData): ReplayPerformanceEntry | null;
21
- export {};
@@ -1,43 +0,0 @@
1
- import { AllPerformanceEntry } from './types';
2
- export interface ReplayPerformanceEntry {
3
- /**
4
- * One of these types https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType
5
- */
6
- type: string;
7
- /**
8
- * A more specific description of the performance entry
9
- */
10
- name: string;
11
- /**
12
- * The start timestamp in seconds
13
- */
14
- start: number;
15
- /**
16
- * The end timestamp in seconds
17
- */
18
- end: number;
19
- /**
20
- * Additional unstructured data to be included
21
- */
22
- data?: Record<string, unknown>;
23
- }
24
- interface MemoryInfo {
25
- jsHeapSizeLimit: number;
26
- totalJSHeapSize: number;
27
- usedJSHeapSize: number;
28
- }
29
- export declare function createPerformanceEntries(entries: AllPerformanceEntry[]): ReplayPerformanceEntry[];
30
- export declare function createMemoryEntry(memoryEntry: MemoryInfo): {
31
- type: string;
32
- name: string;
33
- start: number;
34
- end: number;
35
- data: {
36
- memory: {
37
- jsHeapSizeLimit: number;
38
- totalJSHeapSize: number;
39
- usedJSHeapSize: number;
40
- };
41
- };
42
- };
43
- export {};
@@ -1,45 +0,0 @@
1
- import { RecordingEvent, WorkerRequest, WorkerResponse } from './types';
2
- interface CreateEventBufferParams {
3
- useCompression: boolean;
4
- }
5
- export declare function createEventBuffer({ useCompression }: CreateEventBufferParams): EventBufferCompressionWorker | EventBufferArray;
6
- export interface IEventBuffer {
7
- get length(): number;
8
- destroy(): void;
9
- addEvent(event: RecordingEvent, isCheckout?: boolean): void;
10
- finish(): Promise<string | Uint8Array>;
11
- }
12
- declare class EventBufferArray implements IEventBuffer {
13
- events: RecordingEvent[];
14
- constructor();
15
- destroy(): void;
16
- get length(): number;
17
- addEvent(event: RecordingEvent, isCheckout?: boolean): void;
18
- finish(): Promise<string>;
19
- }
20
- export declare class EventBufferCompressionWorker implements IEventBuffer {
21
- private worker;
22
- private eventBufferItemLength;
23
- private _id;
24
- constructor(worker: Worker);
25
- /**
26
- * Read-only incrementing counter
27
- */
28
- get id(): number;
29
- /**
30
- * Post message to worker and wait for response before resolving promise.
31
- */
32
- postMessage({ id, method, args, }: WorkerRequest): Promise<WorkerResponse['response']>;
33
- init(): void;
34
- destroy(): void;
35
- /**
36
- * Note that this may not reflect what is actually in the event buffer. This
37
- * is only a local count of the buffer size since `addEvent` is async.
38
- */
39
- get length(): number;
40
- addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<string | Uint8Array>;
41
- sendEventToWorker: (event: RecordingEvent) => Promise<string | Uint8Array>;
42
- finishRequest: (id: number) => Promise<Uint8Array>;
43
- finish(): Promise<Uint8Array>;
44
- }
45
- export {};
@@ -1 +0,0 @@
1
- import 'jsdom-worker';
@@ -1,2 +0,0 @@
1
- /** Flag that is true for debug builds, false otherwise. */
2
- export declare const IS_DEBUG_BUILD: boolean;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};