@sentry/replay 0.5.3 → 0.5.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.
Files changed (85) hide show
  1. package/dist/index.es.js +123 -66
  2. package/dist/index.js +122 -65
  3. package/dist/index.js.map +1 -1
  4. package/dist/{config/types/jest.config.d.ts → jest.config.d.ts} +0 -0
  5. package/dist/{config/types/jest.setup.d.ts → jest.setup.d.ts} +1 -1
  6. package/dist/{config/types/src → src}/api/captureReplay.d.ts +0 -0
  7. package/dist/{config/types/src → src}/api/captureReplayUpdate.d.ts +0 -0
  8. package/dist/{config/types/src → src}/coreHandlers/getBreadcrumbHandler.d.ts +0 -0
  9. package/dist/{config/types/src → src}/coreHandlers/getSpanHandler.d.ts +0 -0
  10. package/dist/{config/types/src → src}/coreHandlers/handleDom.d.ts +0 -0
  11. package/dist/{config/types/src → src}/coreHandlers/handleFetch.d.ts +1 -1
  12. package/dist/{config/types/src → src}/coreHandlers/handleFetch.test.d.ts +0 -0
  13. package/dist/{config/types/src → src}/coreHandlers/handleHistory.d.ts +0 -0
  14. package/dist/{config/types/src → src}/coreHandlers/handleScope-unit.test.d.ts +0 -0
  15. package/dist/{config/types/src → src}/coreHandlers/handleScope.d.ts +0 -0
  16. package/dist/{config/types/src → src}/coreHandlers/handleScope.test.d.ts +0 -0
  17. package/dist/{config/types/src → src}/coreHandlers/handleXhr.d.ts +2 -2
  18. package/dist/{config/types/src → src}/createPerformanceEntry.d.ts +0 -0
  19. package/dist/{config/types/src → src}/createPerformanceEntry.test.d.ts +0 -0
  20. package/dist/{config/types/src → src}/eventBuffer.d.ts +0 -0
  21. package/dist/{config/types/src → src}/eventBuffer.test.d.ts +0 -0
  22. package/dist/{config/types/src → src}/flags.d.ts +0 -0
  23. package/dist/{config/types/src → src}/index-captureOnlyOnError.test.d.ts +0 -0
  24. package/dist/{config/types/src → src}/index-noSticky.test.d.ts +0 -0
  25. package/dist/{config/types/src → src}/index-sampling.test.d.ts +0 -0
  26. package/dist/{config/types/src → src}/index.d.ts +5 -1
  27. package/dist/{config/types/src → src}/index.test.d.ts +0 -0
  28. package/dist/{types/src → src}/session/Session.d.ts +2 -2
  29. package/dist/{config/types/src → src}/session/Session.test.d.ts +0 -0
  30. package/dist/{config/types/src → src}/session/constants.d.ts +0 -0
  31. package/dist/{config/types/src → src}/session/createSession.d.ts +0 -0
  32. package/dist/{config/types/src → src}/session/createSession.test.d.ts +0 -0
  33. package/dist/{config/types/src → src}/session/fetchSession.d.ts +0 -0
  34. package/dist/{config/types/src → src}/session/fetchSession.test.d.ts +0 -0
  35. package/dist/{config/types/src → src}/session/getSession.d.ts +0 -0
  36. package/dist/{config/types/src → src}/session/getSession.test.d.ts +0 -0
  37. package/dist/{config/types/src → src}/session/index.d.ts +0 -0
  38. package/dist/{config/types/src → src}/session/saveSession.d.ts +0 -0
  39. package/dist/{config/types/src → src}/session/saveSession.test.d.ts +0 -0
  40. package/dist/{config/types/src → src}/types.d.ts +4 -0
  41. package/dist/{config/types/src → src}/util/createBreadcrumb.d.ts +0 -0
  42. package/dist/{config/types/src → src}/util/createPayload.d.ts +0 -0
  43. package/dist/{types/src → src}/util/isExpired.d.ts +1 -1
  44. package/dist/{config/types/src → src}/util/isExpired.test.d.ts +0 -0
  45. package/dist/{config/types/src → src}/util/isIngestHost.d.ts +0 -0
  46. package/dist/{config/types/src → src}/util/isSampled.d.ts +0 -0
  47. package/dist/{config/types/src → src}/util/isSampled.test.d.ts +0 -0
  48. package/dist/{config/types/src → src}/util/isSessionExpired.d.ts +0 -0
  49. package/dist/{config/types/src → src}/util/isSessionExpired.test.d.ts +0 -0
  50. package/dist/{config/types/src → src}/util/logger.d.ts +0 -0
  51. package/dist/{config/types/test → test}/index.d.ts +0 -0
  52. package/dist/{config/types/test → test}/mocks/mockRrweb.d.ts +0 -0
  53. package/dist/{config/types/test → test}/mocks/mockSdk.d.ts +0 -0
  54. package/package.json +1 -1
  55. package/dist/config/types/src/session/Session.d.ts +0 -63
  56. package/dist/config/types/src/util/getAdditionalRequestData.d.ts +0 -2
  57. package/dist/config/types/src/util/isExpired.d.ts +0 -5
  58. package/dist/config/types/src/util/supportsSendBeacon.d.ts +0 -4
  59. package/dist/types/src/api/captureReplay.d.ts +0 -10
  60. package/dist/types/src/api/captureReplayUpdate.d.ts +0 -12
  61. package/dist/types/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
  62. package/dist/types/src/coreHandlers/getSpanHandler.d.ts +0 -5
  63. package/dist/types/src/coreHandlers/handleDom.d.ts +0 -1
  64. package/dist/types/src/coreHandlers/handleFetch.d.ts +0 -19
  65. package/dist/types/src/coreHandlers/handleHistory.d.ts +0 -7
  66. package/dist/types/src/coreHandlers/handleScope.d.ts +0 -2
  67. package/dist/types/src/coreHandlers/handleXhr.d.ts +0 -21
  68. package/dist/types/src/createPerformanceEntry.d.ts +0 -42
  69. package/dist/types/src/eventBuffer.d.ts +0 -45
  70. package/dist/types/src/flags.d.ts +0 -2
  71. package/dist/types/src/index.d.ts +0 -230
  72. package/dist/types/src/session/constants.d.ts +0 -5
  73. package/dist/types/src/session/createSession.d.ts +0 -19
  74. package/dist/types/src/session/fetchSession.d.ts +0 -5
  75. package/dist/types/src/session/getSession.d.ts +0 -28
  76. package/dist/types/src/session/index.d.ts +0 -1
  77. package/dist/types/src/session/saveSession.d.ts +0 -2
  78. package/dist/types/src/types.d.ts +0 -91
  79. package/dist/types/src/util/createBreadcrumb.d.ts +0 -4
  80. package/dist/types/src/util/createPayload.d.ts +0 -5
  81. package/dist/types/src/util/isIngestHost.d.ts +0 -4
  82. package/dist/types/src/util/isSampled.d.ts +0 -7
  83. package/dist/types/src/util/isSessionExpired.d.ts +0 -5
  84. package/dist/types/src/util/logger.d.ts +0 -12
  85. package/dist/types/src/util/supportsSendBeacon.d.ts +0 -4
@@ -1,230 +0,0 @@
1
- import { Breadcrumb, Event, Integration } from '@sentry/types';
2
- import { CaptureReplayParams } from './api/captureReplay';
3
- import { CaptureReplayUpdateParams } from './api/captureReplayUpdate';
4
- import { Session } from './session/Session';
5
- import { ReplayPerformanceEntry } from './createPerformanceEntry';
6
- import { IEventBuffer } from './eventBuffer';
7
- import type { InstrumentationTypeBreadcrumb, InstrumentationTypeSpan, RecordedEvents, RecordingConfig, RecordingEvent, ReplayRequest, SentryReplayConfiguration, SentryReplayPluginOptions } from './types';
8
- /**
9
- * Returns true to return control to calling function, otherwise continue with normal batching
10
- */
11
- declare type AddUpdateCallback = () => boolean | void;
12
- export declare class SentryReplay implements Integration {
13
- /**
14
- * @inheritDoc
15
- */
16
- static id: string;
17
- /**
18
- * @inheritDoc
19
- */
20
- name: string;
21
- eventBuffer: IEventBuffer;
22
- /**
23
- * Buffer of breadcrumbs to be uploaded
24
- */
25
- breadcrumbs: Breadcrumb[];
26
- /**
27
- * List of PerformanceEntry from PerformanceObserver
28
- */
29
- performanceEvents: PerformanceEntry[];
30
- /**
31
- * Options to pass to `rrweb.record()`
32
- */
33
- readonly recordingOptions: RecordingConfig;
34
- readonly options: SentryReplayPluginOptions;
35
- /**
36
- * setTimeout id used for debouncing sending rrweb attachments
37
- */
38
- private timeout;
39
- /**
40
- * The timestamp of the first event since the last flush. This is used to
41
- * determine if the maximum allowed time has passed before events should be
42
- * flushed again.
43
- */
44
- private initialEventTimestampSinceFlush;
45
- private performanceObserver;
46
- private retryCount;
47
- private retryInterval;
48
- /**
49
- * Flag to make sure we only create a replay event when
50
- * necessary (i.e. we only want to have a single replay
51
- * event per session and it should only be created
52
- * immediately before sending recording)
53
- */
54
- private needsCaptureReplay;
55
- /**
56
- * Captured state when integration is first initialized
57
- */
58
- private initialState;
59
- private context;
60
- session: Session | undefined;
61
- constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
62
- useCompression, captureOnlyOnError, replaysSamplingRate, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
63
- /**
64
- * Because we create a transaction in `setupOnce`, we can potentially create a
65
- * transaction before some native SDK integrations have run and applied their
66
- * own global event processor. An example is:
67
- * https://github.com/getsentry/sentry-javascript/blob/b47ceafbdac7f8b99093ce6023726ad4687edc48/packages/browser/src/integrations/useragent.ts
68
- *
69
- * So we call `this.setup` in next event loop as a workaround to wait for
70
- * other global event processors to finish
71
- */
72
- setupOnce(): void;
73
- /**
74
- * Initializes the plugin.
75
- *
76
- * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
77
- */
78
- setup(): void;
79
- /**
80
- * We want to batch uploads of replay events. Save events only if
81
- * `<flushMinDelay>` milliseconds have elapsed since the last event
82
- * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
83
- *
84
- * Accepts a callback to perform side-effects and returns true to stop batch
85
- * processing and hand back control to caller.
86
- */
87
- addUpdate(cb?: AddUpdateCallback): void;
88
- /**
89
- * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
90
- */
91
- destroy(): void;
92
- clearSession(): void;
93
- /**
94
- * Loads a session from storage, or creates a new one if it does not exist or
95
- * is expired.
96
- */
97
- loadSession({ expiry }: {
98
- expiry: number;
99
- }): void;
100
- /**
101
- * Capture some initial state that can change throughout the lifespan of the
102
- * replay. This is required because otherwise they would be captured at the
103
- * first flush.
104
- */
105
- setInitialState(): void;
106
- /**
107
- * Adds listeners to record events for the replay
108
- */
109
- addListeners(): void;
110
- /**
111
- * Cleans up listeners that were created in `addListeners`
112
- */
113
- removeListeners(): void;
114
- /**
115
- * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
116
- * events as a tag. Also handles the case where we only want to capture a reply
117
- * when an error occurs.
118
- **/
119
- handleGlobalEvent: (event: Event) => Event;
120
- /**
121
- * Handler for recording events.
122
- *
123
- * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
124
- */
125
- handleRecordingEmit: (event: RecordingEvent, isCheckout?: boolean) => void;
126
- /**
127
- * Handle when visibility of the page content changes. Opening a new tab will
128
- * cause the state to change to hidden because of content of current page will
129
- * be hidden. Likewise, moving a different window to cover the contents of the
130
- * page will also trigger a change to a hidden state.
131
- */
132
- handleVisibilityChange: () => void;
133
- /**
134
- * Handle when page is blurred
135
- */
136
- handleWindowBlur: () => void;
137
- /**
138
- * Handle when page is focused
139
- */
140
- handleWindowFocus: () => void;
141
- /**
142
- * Handle when page is closed
143
- */
144
- handleWindowUnload: () => void;
145
- /**
146
- * Handler for Sentry Core SDK events.
147
- *
148
- * These specific events will create span-like objects in the recording.
149
- *
150
- */
151
- handleCoreSpanListener: (type: InstrumentationTypeSpan) => (handlerData: any) => void;
152
- /**
153
- * Handler for Sentry Core SDK events.
154
- *
155
- * These events will create breadcrumb-like objects in the recording.
156
- */
157
- handleCoreBreadcrumbListener: (type: InstrumentationTypeBreadcrumb) => (handlerData: any) => void;
158
- /**
159
- * Keep a list of performance entries that will be sent with a replay
160
- */
161
- handlePerformanceObserver: (list: PerformanceObserverEntryList) => void;
162
- /**
163
- * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
164
- */
165
- doChangeToBackgroundTasks(breadcrumb?: Breadcrumb): void;
166
- /**
167
- * Tasks to run when we consider a page to be visible (via focus and/or visibility)
168
- */
169
- doChangeToForegroundTasks(breadcrumb?: Breadcrumb): void;
170
- /**
171
- * Trigger rrweb to take a full snapshot which will cause this plugin to
172
- * create a new Replay event.
173
- */
174
- triggerFullSnapshot(): void;
175
- /**
176
- * Updates the session's last activity timestamp
177
- */
178
- updateLastActivity(lastActivity?: number): void;
179
- /**
180
- * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
181
- */
182
- createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
183
- /**
184
- * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
185
- */
186
- createPerformanceSpans(entries: ReplayPerformanceEntry[]): Promise<void[]>;
187
- /**
188
- * Observed performance events are added to `this.performanceEvents`. These
189
- * are included in the replay event before it is finished and sent to Sentry.
190
- */
191
- addPerformanceEntries(): Promise<void[]>;
192
- /**
193
- * Create a "span" for the total amount of memory being used by JS objects
194
- * (including v8 internal objects).
195
- */
196
- addMemoryEntry(): Promise<void[]>;
197
- /**
198
- *
199
- *
200
- * Returns true if session is not expired, false otherwise.
201
- */
202
- checkAndHandleExpiredSession(expiry?: number): boolean;
203
- /**
204
- * Only flush if `captureOnlyOnError` is false.
205
- */
206
- conditionalFlush(lastActivity?: number): Promise<void>;
207
- /**
208
- * Return and clear context
209
- */
210
- popEventContext({ timestamp, }?: {
211
- timestamp?: number;
212
- }): CaptureReplayParams & CaptureReplayUpdateParams;
213
- /**
214
- * Flushes replay event buffer to Sentry.
215
- *
216
- * Performance events are only added right before flushing - this is probably
217
- * due to the buffered performance observer events.
218
- */
219
- flushUpdate(lastActivity?: number): Promise<void>;
220
- /**
221
- * Send replay attachment using either `sendBeacon()` or `fetch()`
222
- */
223
- sendReplayRequest({ endpoint, events }: ReplayRequest): Promise<void>;
224
- resetRetries(): void;
225
- /**
226
- * Finalize and send the current replay event to Sentry
227
- */
228
- sendReplay(eventId: string, events: RecordedEvents): Promise<boolean>;
229
- }
230
- export {};
@@ -1,5 +0,0 @@
1
- export declare const REPLAY_SESSION_KEY = "sentryReplaySession";
2
- export declare const REPLAY_EVENT_NAME = "replay_event";
3
- export declare const RECORDING_EVENT_NAME = "replay_recording";
4
- export declare const SESSION_IDLE_DURATION = 900000;
5
- export declare const VISIBILITY_CHANGE_TIMEOUT = 900000;
@@ -1,19 +0,0 @@
1
- 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
- /**
14
- * Create a new session, which in its current implementation is a Sentry event
15
- * that all replays will be saved to as attachments. Currently, we only expect
16
- * one of these Sentry events per "replay session".
17
- */
18
- export declare function createSession({ stickySession, samplingRate, }: CreateSessionParams): Session;
19
- export {};
@@ -1,5 +0,0 @@
1
- import { Session } from './Session';
2
- /**
3
- * Fetches a session from storage
4
- */
5
- export declare function fetchSession(): Session | null;
@@ -1,28 +0,0 @@
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
- * The sampling rate of the Session. See integration configuration comments
17
- * for `replaysSamplingRate`.
18
- */
19
- samplingRate?: number;
20
- }
21
- /**
22
- * Get or create a session
23
- */
24
- export declare function getSession({ expiry, currentSession, stickySession, samplingRate, }: GetSessionParams): {
25
- type: string;
26
- session: Session;
27
- };
28
- export {};
@@ -1 +0,0 @@
1
- export * from './createSession';
@@ -1,2 +0,0 @@
1
- import { Session } from './Session';
2
- export declare function saveSession(session: Session): void;
@@ -1,91 +0,0 @@
1
- import { record } from 'rrweb';
2
- import type { eventWithTime } from 'rrweb/typings/types';
3
- export declare type RecordingEvent = eventWithTime;
4
- export declare type RecordingConfig = Parameters<typeof record>[0];
5
- export declare type RecordedEvents = Uint8Array | string;
6
- export interface ReplayRequest {
7
- endpoint: string;
8
- events: RecordedEvents;
9
- }
10
- export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
11
- export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
12
- export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
13
- /**
14
- * The request payload to worker
15
- */
16
- export interface WorkerRequest {
17
- id: number;
18
- method: string;
19
- args: any[];
20
- }
21
- /**
22
- * The response from the worker
23
- */
24
- export interface WorkerResponse {
25
- id: number;
26
- method: string;
27
- success: boolean;
28
- response: string | Uint8Array;
29
- }
30
- export interface SentryReplayPluginOptions {
31
- /**
32
- * The amount of time to wait before sending a replay
33
- */
34
- flushMinDelay?: number;
35
- /**
36
- * The max amount of time to wait before sending a replay
37
- */
38
- flushMaxDelay?: number;
39
- /**
40
- * The amount of time to buffer the initial snapshot
41
- */
42
- initialFlushDelay?: number;
43
- /**
44
- * If false, will create a new session per pageload
45
- */
46
- stickySession?: boolean;
47
- /**
48
- * Attempt to use compression when web workers are available
49
- *
50
- * (default is true)
51
- */
52
- useCompression?: boolean;
53
- /**
54
- * Only capture replays when an error happens
55
- */
56
- captureOnlyOnError?: boolean;
57
- /**
58
- * The sampling rate for replays. 1.0 will record all replays, 0 will record none.
59
- */
60
- replaysSamplingRate?: number;
61
- }
62
- export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
63
- /**
64
- * Options for `rrweb.record()`
65
- */
66
- recordingConfig?: RecordingConfig;
67
- }
68
- /**
69
- * Some initial state captured before creating a root replay event
70
- */
71
- export interface InitialState {
72
- timestamp: number;
73
- url: string;
74
- }
75
- /**
76
- * Additional context that will be sent w/ `replay_event`
77
- */
78
- export interface ReplayEventContext {
79
- /**
80
- * Set of Sentry error ids that have occurred during a replay segment
81
- */
82
- errorIds: Set<string>;
83
- /**
84
- * Set of Sentry trace ids that have occurred during a replay segment
85
- */
86
- traceIds: Set<string>;
87
- /**
88
- * Ordered list of URLs that have been visited during a replay segment
89
- */
90
- urls: string[];
91
- }
@@ -1,4 +0,0 @@
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 {};
@@ -1,5 +0,0 @@
1
- import { RecordedEvents } from '@/types';
2
- export declare function createPayload({ events, headers, }: {
3
- events: RecordedEvents;
4
- headers: Record<string, any>;
5
- }): string | Uint8Array;
@@ -1,4 +0,0 @@
1
- /**
2
- * Checks is `targetHost` is a Sentry ingestion host
3
- */
4
- export declare function isIngestHost(targetHost: string): boolean;
@@ -1,7 +0,0 @@
1
- /**
2
- * Given a sample rate, returns true if replay should be sampled.
3
- *
4
- * 1.0 = 100% sampling
5
- * 0.0 = 0% sampling
6
- */
7
- export declare function isSampled(sampleRate: number): boolean;
@@ -1,5 +0,0 @@
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;
@@ -1,12 +0,0 @@
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 };
@@ -1,4 +0,0 @@
1
- /**
2
- * Determine if there is browser support for `navigator.sendBeacon`
3
- */
4
- export declare function supportsSendBeacon(): boolean;