@sentry/replay 0.6.10 → 0.6.11-0
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 +10 -7
- package/dist/config/types/src/index.d.ts +8 -4
- package/dist/config/types/src/session/Session.d.ts +4 -6
- package/dist/config/types/src/session/constants.d.ts +5 -0
- package/dist/config/types/src/session/createSession.d.ts +2 -13
- package/dist/config/types/src/session/fetchSession.d.ts +2 -1
- package/dist/config/types/src/session/getSession.d.ts +3 -11
- package/dist/config/types/src/types.d.ts +39 -13
- package/dist/config/types/src/util/isSampled.d.ts +1 -1
- package/dist/index.es.js +87 -32
- package/dist/index.js +87 -32
- package/dist/index.js.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/session/Session.d.ts +4 -6
- package/dist/types/src/session/constants.d.ts +5 -0
- package/dist/types/src/session/createSession.d.ts +2 -13
- package/dist/types/src/session/fetchSession.d.ts +2 -1
- package/dist/types/src/session/getSession.d.ts +3 -11
- package/dist/types/src/types.d.ts +39 -13
- package/dist/types/src/util/isSampled.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,11 @@ Sentry.init({
|
|
|
35
35
|
new Replay({
|
|
36
36
|
// This sets the sample rate to be 10%. You may want this to be 100% while
|
|
37
37
|
// in development and sample at a lower rate in production
|
|
38
|
-
|
|
38
|
+
sessionSampleRate: 0.1,
|
|
39
|
+
|
|
40
|
+
// If the entire session is not sampled, use the below sample rate to sample
|
|
41
|
+
// sessions when an error occurs.
|
|
42
|
+
errorSampleRate: 1.0,
|
|
39
43
|
|
|
40
44
|
// Mask all text content with asterisks (*). Passes text
|
|
41
45
|
// content through to `maskTextFn` before sending to server.
|
|
@@ -79,12 +83,11 @@ replay.stop(); // Stop recording
|
|
|
79
83
|
|
|
80
84
|
### General Configuration
|
|
81
85
|
|
|
82
|
-
| key | type | default | description
|
|
83
|
-
| ------------------- | ------- | ------- | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
|
|
|
87
|
-
| stickySession | boolean | `true` | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
|
|
86
|
+
| key | type | default | description |
|
|
87
|
+
| ------------------- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
+
| sessionSampleRate | number | `0.1` | The sample rate for all sessions, which will capture the entirety from when a user begins a session until the session ends. (1.0 will collect all replays, 0 will collect no replays) |
|
|
89
|
+
| errorSampleRate | number | `1.0` | If a session isn't already being recorded via `sessionSampleRate`, based on `errorSampleRate` the SDK will send the captured replay when an error occurs. (1.0 capturing all sessions with an error, and 0 capturing none). |
|
|
90
|
+
| stickySession | boolean | `true` | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
|
|
88
91
|
|
|
89
92
|
### Privacy Configuration
|
|
90
93
|
|
|
@@ -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,
|
|
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 `
|
|
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():
|
|
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:
|
|
50
|
-
constructor(session
|
|
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({
|
|
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,
|
|
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
|
|
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
|
|
62
|
+
flushMinDelay: number;
|
|
41
63
|
/**
|
|
42
64
|
* The max amount of time to wait before sending a replay
|
|
43
65
|
*/
|
|
44
|
-
flushMaxDelay
|
|
66
|
+
flushMaxDelay: number;
|
|
45
67
|
/**
|
|
46
68
|
* The amount of time to buffer the initial snapshot
|
|
47
69
|
*/
|
|
48
|
-
initialFlushDelay
|
|
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
|
|
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
|
|
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
|
|
94
|
+
maskAllText: boolean;
|
|
71
95
|
/**
|
|
72
96
|
* Block all media (e.g. images, svg, video) in recordings.
|
|
73
97
|
*/
|
|
74
|
-
blockAllMedia
|
|
98
|
+
blockAllMedia: boolean;
|
|
75
99
|
}
|
|
76
|
-
|
|
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 {};
|
package/dist/index.es.js
CHANGED
|
@@ -252,6 +252,11 @@ var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
|
|
|
252
252
|
var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
|
|
253
253
|
// The maximum length of a session
|
|
254
254
|
var MAX_SESSION_LIFE = 1800000; // 30 minutes
|
|
255
|
+
/**
|
|
256
|
+
* Defaults for sampling rates
|
|
257
|
+
*/
|
|
258
|
+
var DEFAULT_SESSION_SAMPLE_RATE = 0.1;
|
|
259
|
+
var DEFAULT_ERROR_SAMPLE_RATE = 1.0;
|
|
255
260
|
|
|
256
261
|
/**
|
|
257
262
|
* Deletes a session from storage
|
|
@@ -330,6 +335,9 @@ function saveSession(session) {
|
|
|
330
335
|
* 0.0 = 0% sampling
|
|
331
336
|
*/
|
|
332
337
|
function isSampled(sampleRate) {
|
|
338
|
+
if (sampleRate === undefined) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
333
341
|
// Math.random() returns a number in range of 0 to 1 (inclusive of 0, but not 1)
|
|
334
342
|
return Math.random() < sampleRate;
|
|
335
343
|
}
|
|
@@ -337,14 +345,15 @@ function isSampled(sampleRate) {
|
|
|
337
345
|
var Session = /** @class */ (function () {
|
|
338
346
|
function Session(session, _a) {
|
|
339
347
|
if (session === void 0) { session = {}; }
|
|
340
|
-
var
|
|
341
|
-
var
|
|
348
|
+
var stickySession = _a.stickySession, sessionSampleRate = _a.sessionSampleRate, errorSampleRate = _a.errorSampleRate;
|
|
349
|
+
var _b, _c, _d, _e;
|
|
342
350
|
var now = new Date().getTime();
|
|
343
351
|
this._id = session.id || uuid4();
|
|
344
|
-
this._started = (
|
|
345
|
-
this._lastActivity = (
|
|
346
|
-
this._segmentId = (
|
|
347
|
-
this._sampled =
|
|
352
|
+
this._started = (_b = session.started) !== null && _b !== void 0 ? _b : now;
|
|
353
|
+
this._lastActivity = (_c = session.lastActivity) !== null && _c !== void 0 ? _c : now;
|
|
354
|
+
this._segmentId = (_d = session.segmentId) !== null && _d !== void 0 ? _d : 0;
|
|
355
|
+
this._sampled =
|
|
356
|
+
(_e = session.sampled) !== null && _e !== void 0 ? _e : (isSampled(sessionSampleRate) || isSampled(errorSampleRate));
|
|
348
357
|
this.options = {
|
|
349
358
|
stickySession: stickySession,
|
|
350
359
|
};
|
|
@@ -427,8 +436,12 @@ var Session = /** @class */ (function () {
|
|
|
427
436
|
* one of these Sentry events per "replay session".
|
|
428
437
|
*/
|
|
429
438
|
function createSession(_a) {
|
|
430
|
-
var
|
|
431
|
-
var session = new Session(undefined, {
|
|
439
|
+
var sessionSampleRate = _a.sessionSampleRate, errorSampleRate = _a.errorSampleRate, _b = _a.stickySession, stickySession = _b === void 0 ? false : _b;
|
|
440
|
+
var session = new Session(undefined, {
|
|
441
|
+
stickySession: stickySession,
|
|
442
|
+
errorSampleRate: errorSampleRate,
|
|
443
|
+
sessionSampleRate: sessionSampleRate,
|
|
444
|
+
});
|
|
432
445
|
logger.log("Creating new session: ".concat(session.id));
|
|
433
446
|
if (stickySession) {
|
|
434
447
|
saveSession(session);
|
|
@@ -449,7 +462,8 @@ function captureInternalException(err) {
|
|
|
449
462
|
/**
|
|
450
463
|
* Fetches a session from storage
|
|
451
464
|
*/
|
|
452
|
-
function fetchSession() {
|
|
465
|
+
function fetchSession(_a) {
|
|
466
|
+
var sessionSampleRate = _a.sessionSampleRate, errorSampleRate = _a.errorSampleRate;
|
|
453
467
|
var hasSessionStorage = 'sessionStorage' in window;
|
|
454
468
|
if (!hasSessionStorage) {
|
|
455
469
|
return null;
|
|
@@ -467,9 +481,9 @@ function fetchSession() {
|
|
|
467
481
|
return new Session(sessionObj,
|
|
468
482
|
// We are assuming that if there is a saved item, then the session is sticky,
|
|
469
483
|
// however this could break down if we used a different storage mechanism (e.g. localstorage)
|
|
470
|
-
{ stickySession: true });
|
|
484
|
+
{ stickySession: true, sessionSampleRate: sessionSampleRate, errorSampleRate: errorSampleRate });
|
|
471
485
|
}
|
|
472
|
-
catch (
|
|
486
|
+
catch (_b) {
|
|
473
487
|
return null;
|
|
474
488
|
}
|
|
475
489
|
}
|
|
@@ -478,9 +492,10 @@ function fetchSession() {
|
|
|
478
492
|
* Get or create a session
|
|
479
493
|
*/
|
|
480
494
|
function getSession(_a) {
|
|
481
|
-
var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession,
|
|
495
|
+
var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession, sessionSampleRate = _a.sessionSampleRate, errorSampleRate = _a.errorSampleRate;
|
|
482
496
|
// If session exists and is passed, use it instead of always hitting session storage
|
|
483
|
-
var session = currentSession ||
|
|
497
|
+
var session = currentSession ||
|
|
498
|
+
(stickySession && fetchSession({ sessionSampleRate: sessionSampleRate, errorSampleRate: errorSampleRate }));
|
|
484
499
|
if (session) {
|
|
485
500
|
// If there is a session, check if it is valid (e.g. "last activity" time
|
|
486
501
|
// should be within the "session idle time", and "session started" time is
|
|
@@ -494,7 +509,11 @@ function getSession(_a) {
|
|
|
494
509
|
}
|
|
495
510
|
// Otherwise continue to create a new session
|
|
496
511
|
}
|
|
497
|
-
var newSession = createSession({
|
|
512
|
+
var newSession = createSession({
|
|
513
|
+
stickySession: stickySession,
|
|
514
|
+
sessionSampleRate: sessionSampleRate,
|
|
515
|
+
errorSampleRate: errorSampleRate,
|
|
516
|
+
});
|
|
498
517
|
return { type: 'new', session: newSession };
|
|
499
518
|
}
|
|
500
519
|
|
|
@@ -909,7 +928,7 @@ var Replay = /** @class */ (function () {
|
|
|
909
928
|
function Replay(_a) {
|
|
910
929
|
if (_a === void 0) { _a = {}; }
|
|
911
930
|
var _this = this;
|
|
912
|
-
var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.
|
|
931
|
+
var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.sessionSampleRate, sessionSampleRate = _g === void 0 ? DEFAULT_SESSION_SAMPLE_RATE : _g, _h = _a.errorSampleRate, errorSampleRate = _h === void 0 ? DEFAULT_ERROR_SAMPLE_RATE : _h, _j = _a.maskAllText, maskAllText = _j === void 0 ? true : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? true : _k, _l = _a.blockAllMedia, blockAllMedia = _l === void 0 ? true : _l, _m = _a.blockClass, blockClass = _m === void 0 ? 'sentry-block' : _m, _o = _a.ignoreClass, ignoreClass = _o === void 0 ? 'sentry-ignore' : _o, _p = _a.maskTextClass, maskTextClass = _p === void 0 ? 'sentry-mask' : _p, _q = _a.blockSelector, blockSelector = _q === void 0 ? '[data-sentry-block]' : _q, replaysSamplingRate = _a.replaysSamplingRate, captureOnlyOnError = _a.captureOnlyOnError, recordingOptions = __rest(_a, ["flushMinDelay", "flushMaxDelay", "initialFlushDelay", "stickySession", "useCompression", "sessionSampleRate", "errorSampleRate", "maskAllText", "maskAllInputs", "blockAllMedia", "blockClass", "ignoreClass", "maskTextClass", "blockSelector", "replaysSamplingRate", "captureOnlyOnError"]);
|
|
913
932
|
/**
|
|
914
933
|
* @inheritDoc
|
|
915
934
|
*/
|
|
@@ -931,12 +950,16 @@ var Replay = /** @class */ (function () {
|
|
|
931
950
|
*/
|
|
932
951
|
this.isEnabled = false;
|
|
933
952
|
/**
|
|
934
|
-
*
|
|
935
953
|
* Paused is a state where:
|
|
936
954
|
* - DOM Recording is not listening at all
|
|
937
955
|
* - Nothing will be added to event buffer (e.g. core SDK events)
|
|
938
956
|
*/
|
|
939
957
|
this.isPaused = false;
|
|
958
|
+
/**
|
|
959
|
+
* Integration will wait until an error occurs before creating and sending a
|
|
960
|
+
* replay.
|
|
961
|
+
*/
|
|
962
|
+
this.waitForError = false;
|
|
940
963
|
/**
|
|
941
964
|
* Have we attached listeners to the core SDK?
|
|
942
965
|
* Note we have to track this as there is no way to remove instrumentation handlers.
|
|
@@ -981,13 +1004,28 @@ var Replay = /** @class */ (function () {
|
|
|
981
1004
|
message: "Tagging event (".concat(event.event_id, ") - ").concat(event.message, " - ").concat((exc === null || exc === void 0 ? void 0 : exc.type) || 'Unknown', ": ").concat((exc === null || exc === void 0 ? void 0 : exc.value) || 'n/a'),
|
|
982
1005
|
});
|
|
983
1006
|
// Need to be very careful that this does not cause an infinite loop
|
|
984
|
-
if (_this.
|
|
1007
|
+
if (_this.waitForError &&
|
|
985
1008
|
event.exception &&
|
|
986
|
-
event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because
|
|
1009
|
+
event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
|
|
987
1010
|
) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1011
|
+
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1012
|
+
return __generator(this, function (_a) {
|
|
1013
|
+
switch (_a.label) {
|
|
1014
|
+
case 0: return [4 /*yield*/, this.flushImmediate()];
|
|
1015
|
+
case 1:
|
|
1016
|
+
_a.sent();
|
|
1017
|
+
if (this.stopRecording) {
|
|
1018
|
+
this.stopRecording();
|
|
1019
|
+
// Reset all "capture on error" configuration before
|
|
1020
|
+
// starting a new recording
|
|
1021
|
+
delete this.recordingOptions.checkoutEveryNms;
|
|
1022
|
+
this.waitForError = false;
|
|
1023
|
+
this.startRecording();
|
|
1024
|
+
}
|
|
1025
|
+
return [2 /*return*/];
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
}); });
|
|
991
1029
|
}
|
|
992
1030
|
return event;
|
|
993
1031
|
};
|
|
@@ -1200,21 +1238,37 @@ var Replay = /** @class */ (function () {
|
|
|
1200
1238
|
});
|
|
1201
1239
|
}); };
|
|
1202
1240
|
this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass, blockSelector: blockSelector }, recordingOptions);
|
|
1241
|
+
var usingDeprecatedReplaysSamplingRate = replaysSamplingRate !== undefined;
|
|
1242
|
+
var usingDeprecatedCaptureOnlyOnError = captureOnlyOnError !== undefined;
|
|
1203
1243
|
this.options = {
|
|
1204
1244
|
flushMinDelay: flushMinDelay,
|
|
1205
1245
|
flushMaxDelay: flushMaxDelay,
|
|
1206
1246
|
stickySession: stickySession,
|
|
1207
1247
|
initialFlushDelay: initialFlushDelay,
|
|
1208
|
-
|
|
1209
|
-
|
|
1248
|
+
sessionSampleRate: usingDeprecatedReplaysSamplingRate
|
|
1249
|
+
? replaysSamplingRate
|
|
1250
|
+
: sessionSampleRate,
|
|
1251
|
+
errorSampleRate: usingDeprecatedCaptureOnlyOnError
|
|
1252
|
+
? 1.0
|
|
1253
|
+
: errorSampleRate,
|
|
1210
1254
|
useCompression: useCompression,
|
|
1211
1255
|
maskAllText: maskAllText,
|
|
1212
1256
|
blockAllMedia: blockAllMedia,
|
|
1213
1257
|
};
|
|
1214
|
-
// Modify
|
|
1215
|
-
|
|
1258
|
+
// Modify recording options to checkoutEveryNthSecond if this is defined, as we
|
|
1259
|
+
// don't know when an error will occur, so we need to keep a buffer of replay events.
|
|
1260
|
+
if (this.options.errorSampleRate > 0 &&
|
|
1261
|
+
this.options.sessionSampleRate < 1.0) {
|
|
1216
1262
|
// Checkout every minute, meaning we only get up-to one minute of events before the error happens
|
|
1217
1263
|
this.recordingOptions.checkoutEveryNms = 60000;
|
|
1264
|
+
this.waitForError = true;
|
|
1265
|
+
}
|
|
1266
|
+
// TODO(deprecated): Maintain backwards compatibility for alpha users
|
|
1267
|
+
if (usingDeprecatedCaptureOnlyOnError) {
|
|
1268
|
+
console.warn('[@sentry/replay]: The `captureOnlyOnError` option is deprecated! Please configure `errorSampleRate` instead.');
|
|
1269
|
+
}
|
|
1270
|
+
if (usingDeprecatedReplaysSamplingRate) {
|
|
1271
|
+
console.warn('[@sentry/replay]: The `replaysSamplingRate` option is deprecated! Please configure `sessionSampleRate` instead.');
|
|
1218
1272
|
}
|
|
1219
1273
|
if (this.options.maskAllText) {
|
|
1220
1274
|
// `maskAllText` is a more user friendly option to configure
|
|
@@ -1347,7 +1401,8 @@ var Replay = /** @class */ (function () {
|
|
|
1347
1401
|
expiry: expiry,
|
|
1348
1402
|
stickySession: Boolean(this.options.stickySession),
|
|
1349
1403
|
currentSession: this.session,
|
|
1350
|
-
|
|
1404
|
+
sessionSampleRate: this.options.sessionSampleRate,
|
|
1405
|
+
errorSampleRate: this.options.errorSampleRate,
|
|
1351
1406
|
}), type = _d.type, session = _d.session;
|
|
1352
1407
|
// If session was newly created (i.e. was not loaded from storage), then
|
|
1353
1408
|
// enable flag to create the root replay
|
|
@@ -1446,11 +1501,11 @@ var Replay = /** @class */ (function () {
|
|
|
1446
1501
|
* processing and hand back control to caller.
|
|
1447
1502
|
*/
|
|
1448
1503
|
Replay.prototype.addUpdate = function (cb) {
|
|
1449
|
-
// We need to always run `cb` (e.g. in the case of
|
|
1504
|
+
// We need to always run `cb` (e.g. in the case of `this.waitForError == true`)
|
|
1450
1505
|
var cbResult = cb === null || cb === void 0 ? void 0 : cb();
|
|
1451
1506
|
// If this option is turned on then we will only want to call `flush`
|
|
1452
1507
|
// explicitly
|
|
1453
|
-
if (this.
|
|
1508
|
+
if (this.waitForError) {
|
|
1454
1509
|
return;
|
|
1455
1510
|
}
|
|
1456
1511
|
// If callback is true, we do not want to continue with flushing -- the
|
|
@@ -1681,10 +1736,10 @@ var Replay = /** @class */ (function () {
|
|
|
1681
1736
|
return false;
|
|
1682
1737
|
};
|
|
1683
1738
|
/**
|
|
1684
|
-
* Only flush if `
|
|
1739
|
+
* Only flush if `this.waitForError` is false.
|
|
1685
1740
|
*/
|
|
1686
1741
|
Replay.prototype.conditionalFlush = function () {
|
|
1687
|
-
if (this.
|
|
1742
|
+
if (this.waitForError) {
|
|
1688
1743
|
return;
|
|
1689
1744
|
}
|
|
1690
1745
|
this.flushImmediate();
|
|
@@ -1783,7 +1838,7 @@ var Replay = /** @class */ (function () {
|
|
|
1783
1838
|
Replay.prototype.flushImmediate = function () {
|
|
1784
1839
|
this.debouncedFlush();
|
|
1785
1840
|
// `.flush` is provided by lodash.debounce
|
|
1786
|
-
this.debouncedFlush.flush();
|
|
1841
|
+
return this.debouncedFlush.flush();
|
|
1787
1842
|
};
|
|
1788
1843
|
/**
|
|
1789
1844
|
* Send replay attachment using `fetch()`
|
|
@@ -1807,7 +1862,7 @@ var Replay = /** @class */ (function () {
|
|
|
1807
1862
|
timestamp = new Date().getTime();
|
|
1808
1863
|
sdkInfo = {
|
|
1809
1864
|
name: 'sentry.javascript.integration.replay',
|
|
1810
|
-
version: "0.6.
|
|
1865
|
+
version: "0.6.11-0",
|
|
1811
1866
|
};
|
|
1812
1867
|
return [4 /*yield*/, new Promise(function (resolve) {
|
|
1813
1868
|
var _a;
|