@sentry/replay 0.2.0-9 → 0.4.1

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 (82) hide show
  1. package/README.md +2 -3
  2. package/dist/{jest.config.d.ts → config/dist/jest.config.d.ts} +0 -0
  3. package/dist/config/dist/jest.setup.d.ts +10 -0
  4. package/dist/config/dist/src/api/captureReplay.d.ts +2 -0
  5. package/dist/config/dist/src/api/captureReplayUpdate.d.ts +2 -0
  6. package/dist/config/dist/src/coreHandlers/handleDom.d.ts +1 -0
  7. package/dist/config/dist/src/coreHandlers/handleFetch.d.ts +2 -0
  8. package/dist/{src/session/createSession.test.d.ts → config/dist/src/coreHandlers/handleFetch.test.d.ts} +0 -0
  9. package/dist/{src/session/fetchSession.test.d.ts → config/dist/src/coreHandlers/handleScope-unit.test.d.ts} +0 -0
  10. package/dist/config/dist/src/coreHandlers/handleScope.d.ts +2 -0
  11. package/dist/{src/session/getSession.test.d.ts → config/dist/src/coreHandlers/handleScope.test.d.ts} +0 -0
  12. package/dist/config/dist/src/coreHandlers/handleXhr.d.ts +2 -0
  13. package/dist/config/dist/src/coreHandlers/index.d.ts +4 -0
  14. package/dist/{src → config/dist/src}/createPerformanceEntry.d.ts +20 -1
  15. package/dist/{src/session/saveSession.test.d.ts → config/dist/src/createPerformanceEntry.test.d.ts} +0 -0
  16. package/dist/config/dist/src/eventBuffer.d.ts +31 -0
  17. package/dist/{src/session/updateSessionActivity.test.d.ts → config/dist/src/eventBuffer.test.d.ts} +0 -0
  18. package/dist/{src → config/dist/src}/flags.d.ts +0 -0
  19. package/dist/{src/util/isExpired.test.d.ts → config/dist/src/index-captureOnlyOnError.test.d.ts} +0 -0
  20. package/dist/{src/util/isSessionExpired.test.d.ts → config/dist/src/index-noSticky.test.d.ts} +0 -0
  21. package/dist/config/dist/src/index.d.ts +151 -0
  22. package/dist/{tests/index.spec.d.ts → config/dist/src/index.test.d.ts} +0 -0
  23. package/dist/config/dist/src/session/Session.d.ts +46 -0
  24. package/dist/config/dist/src/session/Session.test.d.ts +1 -0
  25. package/dist/config/dist/src/session/constants.d.ts +5 -0
  26. package/dist/{src → config/dist/src}/session/createSession.d.ts +2 -2
  27. package/dist/config/dist/src/session/createSession.test.d.ts +1 -0
  28. package/dist/config/dist/src/session/fetchSession.d.ts +5 -0
  29. package/dist/config/dist/src/session/fetchSession.test.d.ts +1 -0
  30. package/dist/{src → config/dist/src}/session/getSession.d.ts +9 -1
  31. package/dist/config/dist/src/session/getSession.test.d.ts +1 -0
  32. package/dist/{src → config/dist/src}/session/index.d.ts +0 -1
  33. package/dist/config/dist/src/session/saveSession.d.ts +2 -0
  34. package/dist/config/dist/src/session/saveSession.test.d.ts +1 -0
  35. package/dist/config/dist/src/types.d.ts +57 -0
  36. package/dist/config/dist/src/util/createBreadcrumb.d.ts +4 -0
  37. package/dist/config/dist/src/util/createPayload.d.ts +5 -0
  38. package/dist/{src → config/dist/src}/util/isExpired.d.ts +0 -0
  39. package/dist/config/dist/src/util/isExpired.test.d.ts +1 -0
  40. package/dist/config/dist/src/util/isIngestHost.d.ts +4 -0
  41. package/dist/config/dist/src/util/isSessionExpired.d.ts +5 -0
  42. package/dist/config/dist/src/util/isSessionExpired.test.d.ts +1 -0
  43. package/dist/config/dist/src/util/logger.d.ts +12 -0
  44. package/dist/config/dist/test/index.d.ts +3 -0
  45. package/dist/config/dist/test/mocks/mockRrweb.d.ts +15 -0
  46. package/dist/config/dist/test/mocks/mockSdk.d.ts +11 -0
  47. package/dist/dist/api/captureReplay.d.ts +2 -0
  48. package/dist/dist/coreHandlers/handleDom.d.ts +1 -0
  49. package/dist/dist/coreHandlers/handleFetch.d.ts +2 -0
  50. package/dist/dist/coreHandlers/handleScope.d.ts +2 -0
  51. package/dist/dist/coreHandlers/handleXhr.d.ts +2 -0
  52. package/dist/dist/coreHandlers/index.d.ts +4 -0
  53. package/dist/dist/createPerformanceEntry.d.ts +42 -0
  54. package/dist/dist/eventBuffer.d.ts +31 -0
  55. package/dist/dist/flags.d.ts +2 -0
  56. package/dist/dist/index.d.ts +152 -0
  57. package/dist/dist/session/Session.d.ts +52 -0
  58. package/dist/dist/session/constants.d.ts +5 -0
  59. package/dist/dist/session/createSession.d.ts +14 -0
  60. package/dist/dist/session/fetchSession.d.ts +5 -0
  61. package/dist/dist/session/getSession.d.ts +23 -0
  62. package/dist/dist/session/index.d.ts +1 -0
  63. package/dist/dist/session/saveSession.d.ts +2 -0
  64. package/dist/dist/types.d.ts +61 -0
  65. package/dist/dist/util/createBreadcrumb.d.ts +4 -0
  66. package/dist/dist/util/isExpired.d.ts +5 -0
  67. package/dist/dist/util/isIngestHost.d.ts +4 -0
  68. package/dist/dist/util/isSessionExpired.d.ts +5 -0
  69. package/dist/dist/util/logger.d.ts +12 -0
  70. package/dist/index.es.js +732 -227
  71. package/dist/index.js +731 -246
  72. package/dist/index.js.map +1 -1
  73. package/package.json +25 -20
  74. package/dist/rollup.config.d.ts +0 -3
  75. package/dist/src/index.d.ts +0 -120
  76. package/dist/src/session/constants.d.ts +0 -1
  77. package/dist/src/session/fetchSession.d.ts +0 -2
  78. package/dist/src/session/saveSession.d.ts +0 -2
  79. package/dist/src/session/types.d.ts +0 -7
  80. package/dist/src/session/updateSessionActivity.d.ts +0 -3
  81. package/dist/src/util/isSessionExpired.d.ts +0 -5
  82. package/dist/src/util/logger.d.ts +0 -6
@@ -0,0 +1,31 @@
1
+ import { RRWebEvent } 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: RRWebEvent, isCheckout?: boolean): void;
10
+ finish(): Promise<string | Uint8Array>;
11
+ }
12
+ declare class EventBufferArray implements IEventBuffer {
13
+ events: RRWebEvent[];
14
+ constructor();
15
+ destroy(): void;
16
+ get length(): number;
17
+ addEvent(event: RRWebEvent, isCheckout?: boolean): void;
18
+ finish(): Promise<string>;
19
+ }
20
+ export declare class EventBufferCompressionWorker implements IEventBuffer {
21
+ private worker;
22
+ private eventBufferItemLength;
23
+ constructor(worker: Worker);
24
+ init(): void;
25
+ destroy(): void;
26
+ get length(): number;
27
+ addEvent(event: RRWebEvent, isCheckout?: boolean): void;
28
+ sendEventToWorker(event: RRWebEvent): void;
29
+ finish(): Promise<Uint8Array>;
30
+ }
31
+ export {};
@@ -0,0 +1,2 @@
1
+ /** Flag that is true for debug builds, false otherwise. */
2
+ export declare const IS_DEBUG_BUILD: boolean;
@@ -0,0 +1,152 @@
1
+ import { DsnComponents, Integration, Breadcrumb } from '@sentry/types';
2
+ import { ReplayPerformanceEntry } from './createPerformanceEntry';
3
+ import { IEventBuffer } from './eventBuffer';
4
+ import type { RRWebOptions, ReplaySpan, ReplayRequest, InstrumentationType, SentryReplayPluginOptions, SentryReplayConfiguration } from './types';
5
+ import { Session } from './session/Session';
6
+ /**
7
+ * Returns true to return control to calling function, otherwise continue with normal batching
8
+ */
9
+ declare type AddUpdateCallback = () => boolean | void;
10
+ export declare class SentryReplay implements Integration {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static id: string;
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ name: string;
19
+ eventBuffer: IEventBuffer;
20
+ /**
21
+ * Buffer of breadcrumbs to be uploaded
22
+ */
23
+ breadcrumbs: Breadcrumb[];
24
+ /**
25
+ * Buffer of replay spans to be uploaded
26
+ */
27
+ replaySpans: ReplaySpan[];
28
+ /**
29
+ * List of PerformanceEntry from PerformanceObserver
30
+ */
31
+ performanceEvents: PerformanceEntry[];
32
+ /**
33
+ * Options to pass to `rrweb.record()`
34
+ */
35
+ readonly rrwebRecordOptions: RRWebOptions;
36
+ readonly options: SentryReplayPluginOptions;
37
+ /**
38
+ * setTimeout id used for debouncing sending rrweb attachments
39
+ */
40
+ private timeout;
41
+ /**
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.
45
+ */
46
+ private initialEventTimestampSinceFlush;
47
+ private performanceObserver;
48
+ private retryCount;
49
+ private retryInterval;
50
+ /**
51
+ * Flag to make sure we only create a replay event when
52
+ * necessary (i.e. we only want to have a single replay
53
+ * event per session and it should only be created
54
+ * immediately before sending recording)
55
+ */
56
+ private needsCaptureReplay;
57
+ session: Session | undefined;
58
+ static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
59
+ constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
60
+ useCompression, rrwebConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...rrwebRecordOptions }, }?: SentryReplayConfiguration);
61
+ setupOnce(): void;
62
+ setup(): void;
63
+ /**
64
+ * We want to batch uploads of replay events. Save events only if
65
+ * `<flushMinDelay>` milliseconds have elapsed since the last event
66
+ * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
67
+ *
68
+ * Accepts a callback to perform side-effects and returns true to stop batch
69
+ * processing and hand back control to caller.
70
+ */
71
+ addUpdate(cb?: AddUpdateCallback): void;
72
+ /**
73
+ * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
74
+ */
75
+ destroy(): void;
76
+ clearSession(): void;
77
+ /**
78
+ * Loads a session from storage, or creates a new one if it does not exist or
79
+ * is expired.
80
+ */
81
+ loadSession({ expiry }: {
82
+ expiry: number;
83
+ }): void;
84
+ addListeners(): void;
85
+ removeListeners(): void;
86
+ /**
87
+ * Handle when visibility of the page content changes. Opening a new tab will
88
+ * cause the state to change to hidden because of content of current page will
89
+ * be hidden. Likewise, moving a different window to cover the contents of the
90
+ * page will also trigger a change to a hidden state.
91
+ */
92
+ handleVisibilityChange: () => void;
93
+ /**
94
+ * Handle when page is blurred
95
+ */
96
+ handleWindowBlur: () => void;
97
+ /**
98
+ * Handle when page is focused
99
+ */
100
+ handleWindowFocus: () => void;
101
+ handleWindowUnload: () => void;
102
+ handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
103
+ /**
104
+ * Keep a list of performance entries that will be sent with a replay
105
+ */
106
+ handlePerformanceObserver: (list: PerformanceObserverEntryList) => void;
107
+ /**
108
+ * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
109
+ */
110
+ doChangeToBackgroundTasks(breadcrumb?: Breadcrumb): void;
111
+ /**
112
+ * Tasks to run when we consider a page to be visible (via focus and/or visibility)
113
+ */
114
+ doChangeToForegroundTasks(breadcrumb?: Breadcrumb): void;
115
+ /**
116
+ * Trigger rrweb to take a full snapshot which will cause this plugin to
117
+ * create a new Replay event.
118
+ */
119
+ triggerFullSnapshot(): void;
120
+ updateLastActivity(lastActivity?: number): void;
121
+ createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
122
+ /**
123
+ * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
124
+ */
125
+ createPerformanceSpans(entries: ReplayPerformanceEntry[]): void;
126
+ /**
127
+ * Observed performance events are added to `this.performanceEvents`. These
128
+ * are included in the replay event before it is finished and sent to Sentry.
129
+ */
130
+ addPerformanceEntries(): void;
131
+ /**
132
+ *
133
+ *
134
+ * Returns true if session is not expired, false otherwise.
135
+ */
136
+ checkAndHandleExpiredSession(expiry?: number): boolean;
137
+ flushUpdate(lastActivity?: number): Promise<void>;
138
+ /**
139
+ * Determine if there is browser support for `navigator.sendBeacon`
140
+ */
141
+ hasSendBeacon(): boolean;
142
+ /**
143
+ * Send replay attachment using either `sendBeacon()` or `fetch()`
144
+ */
145
+ sendReplayRequest({ endpoint, events }: ReplayRequest): Promise<void>;
146
+ resetRetries(): void;
147
+ /**
148
+ * Finalize and send the current replay event to Sentry
149
+ */
150
+ sendReplay(eventId: string, events: Uint8Array | string): Promise<boolean>;
151
+ }
152
+ export {};
@@ -0,0 +1,52 @@
1
+ interface SessionObject {
2
+ id: string;
3
+ /**
4
+ * Start time of current session
5
+ */
6
+ started: number;
7
+ /**
8
+ * Last known activity of the session
9
+ */
10
+ lastActivity: number;
11
+ /**
12
+ * Sequence ID specific to replay updates
13
+ */
14
+ sequenceId: number;
15
+ }
16
+ interface SessionOptions {
17
+ stickySession?: boolean;
18
+ }
19
+ export declare class Session {
20
+ /**
21
+ * Session ID
22
+ */
23
+ private _id;
24
+ /**
25
+ * Start time of current session
26
+ */
27
+ private _started;
28
+ /**
29
+ * Last known activity of the session
30
+ */
31
+ private _lastActivity;
32
+ /**
33
+ * Sequence ID specific to replay updates
34
+ */
35
+ private _sequenceId;
36
+ /**
37
+ * Previous session ID
38
+ */
39
+ private _previousSessionId;
40
+ readonly options: Required<SessionOptions>;
41
+ constructor(session?: Partial<SessionObject>, { stickySession }?: SessionOptions);
42
+ get id(): string;
43
+ get started(): number;
44
+ get lastActivity(): number;
45
+ set lastActivity(newDate: number);
46
+ get sequenceId(): number;
47
+ set sequenceId(id: number);
48
+ get previousSessionId(): string;
49
+ set previousSessionId(id: string);
50
+ toJSON(): SessionObject;
51
+ }
52
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare const REPLAY_SESSION_KEY = "sentryReplaySession";
2
+ export declare const ROOT_REPLAY_NAME = "sentry-replay";
3
+ export declare const REPLAY_EVENT_NAME = "sentry-replay-event";
4
+ export declare const SESSION_IDLE_DURATION = 900000;
5
+ export declare const VISIBILITY_CHANGE_TIMEOUT = 900000;
@@ -0,0 +1,14 @@
1
+ import { Session } from './Session';
2
+ interface CreateSessionParams {
3
+ /**
4
+ * Should save to sessionStorage?
5
+ */
6
+ stickySession: boolean;
7
+ }
8
+ /**
9
+ * Create a new session, which in its current implementation is a Sentry event
10
+ * that all replays will be saved to as attachments. Currently, we only expect
11
+ * one of these Sentry events per "replay session".
12
+ */
13
+ export declare function createSession({ stickySession, }: CreateSessionParams): Session;
14
+ export {};
@@ -0,0 +1,5 @@
1
+ import { Session } from './Session';
2
+ /**
3
+ * Fetches a session from storage
4
+ */
5
+ export declare function fetchSession(): Session | null;
@@ -0,0 +1,23 @@
1
+ import { Session } from './Session';
2
+ interface GetSessionParams {
3
+ /**
4
+ * The length of time (in ms) which we will consider the session to be expired.
5
+ */
6
+ expiry: number;
7
+ /**
8
+ * Should save session to sessionStorage?
9
+ */
10
+ stickySession: boolean;
11
+ /**
12
+ * The current session (e.g. if stickySession is off)
13
+ */
14
+ currentSession?: Session;
15
+ }
16
+ /**
17
+ * Get or create a session
18
+ */
19
+ export declare function getSession({ expiry, currentSession, stickySession, }: GetSessionParams): {
20
+ type: string;
21
+ session: Session;
22
+ };
23
+ export {};
@@ -0,0 +1 @@
1
+ export * from './createSession';
@@ -0,0 +1,2 @@
1
+ import { Session } from './Session';
2
+ export declare function saveSession(session: Session): void;
@@ -0,0 +1,61 @@
1
+ import type { eventWithTime } from 'rrweb/typings/types';
2
+ import { record } from 'rrweb';
3
+ export declare type RRWebEvent = eventWithTime;
4
+ export declare type RRWebOptions = Parameters<typeof record>[0];
5
+ export interface ReplaySpan {
6
+ description: string;
7
+ op: string;
8
+ startTimestamp: number;
9
+ endTimestamp: number;
10
+ data?: Record<string, unknown>;
11
+ }
12
+ export interface ReplayRequest {
13
+ endpoint: string;
14
+ events: Uint8Array | string;
15
+ }
16
+ export declare type InstrumentationType = 'scope' | 'dom' | 'fetch' | 'xhr';
17
+ /**
18
+ * The request payload to worker
19
+ */
20
+ export interface WorkerRequest {
21
+ method: string;
22
+ args: any[];
23
+ }
24
+ /**
25
+ * The response from the worker
26
+ */
27
+ export interface WorkerResponse {
28
+ method: string;
29
+ success: boolean;
30
+ response: string | Uint8Array;
31
+ }
32
+ export interface SentryReplayPluginOptions {
33
+ /**
34
+ * The amount of time to wait before sending a replay
35
+ */
36
+ flushMinDelay?: number;
37
+ /**
38
+ * The max amount of time to wait before sending a replay
39
+ */
40
+ flushMaxDelay?: number;
41
+ /**
42
+ * The amount of time to buffer the initial snapshot
43
+ */
44
+ initialFlushDelay?: number;
45
+ /**
46
+ * If false, will create a new session per pageload
47
+ */
48
+ stickySession?: boolean;
49
+ /**
50
+ * Attempt to use compression when web workers are available
51
+ *
52
+ * (default is true)
53
+ */
54
+ useCompression?: boolean;
55
+ }
56
+ export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
57
+ /**
58
+ * Options for `rrweb.recordsetup
59
+ */
60
+ rrwebConfig?: RRWebOptions;
61
+ }
@@ -0,0 +1,4 @@
1
+ import type { Breadcrumb } from '@sentry/types';
2
+ declare type RequiredProperties = 'category' | 'message';
3
+ export default function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
4
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Given an initial timestamp and an expiry duration, checks to see if current
3
+ * time should be considered as expired.
4
+ */
5
+ export declare function isExpired(initialTime: number, expiry: number, targetTime?: number): boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Checks is `targetHost` is a Sentry ingestion host
3
+ */
4
+ export declare function isIngestHost(targetHost: string): boolean;
@@ -0,0 +1,5 @@
1
+ import { Session } from '@/session/Session';
2
+ /**
3
+ * Checks to see if session is expired
4
+ */
5
+ export declare function isSessionExpired(session: Session, expiry: number, targetTime?: number): boolean;
@@ -0,0 +1,12 @@
1
+ declare const logger: {
2
+ error: (...args: any[]) => any;
3
+ warn: (...args: any[]) => any;
4
+ log: (...args: any[]) => any;
5
+ disable(): void;
6
+ enable(): void;
7
+ debug: (...args: unknown[]) => void;
8
+ info: (...args: unknown[]) => void;
9
+ assert: (...args: unknown[]) => void;
10
+ trace: (...args: unknown[]) => void;
11
+ };
12
+ export { logger };