@sentry/replay 7.24.1 → 7.25.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 +3 -4
- package/cjs/_virtual/_commonjsHelpers.js +42 -0
- package/cjs/_virtual/_commonjsHelpers.js.map +1 -0
- package/cjs/constants.js +8 -0
- package/cjs/constants.js.map +1 -1
- package/cjs/coreHandlers/breadcrumbHandler.js.map +1 -1
- package/cjs/coreHandlers/handleFetch.js +33 -6
- package/cjs/coreHandlers/handleFetch.js.map +1 -1
- package/cjs/coreHandlers/handleGlobalEvent.js +91 -0
- package/cjs/coreHandlers/handleGlobalEvent.js.map +1 -0
- package/cjs/coreHandlers/handleHistory.js +30 -1
- package/cjs/coreHandlers/handleHistory.js.map +1 -1
- package/cjs/coreHandlers/handleScope.js +4 -12
- package/cjs/coreHandlers/handleScope.js.map +1 -1
- package/cjs/coreHandlers/handleXhr.js +33 -4
- package/cjs/coreHandlers/handleXhr.js.map +1 -1
- package/cjs/coreHandlers/performanceObserver.js +47 -0
- package/cjs/coreHandlers/performanceObserver.js.map +1 -0
- package/cjs/createPerformanceEntry.js +0 -6
- package/cjs/createPerformanceEntry.js.map +1 -1
- package/cjs/eventBuffer.js.map +1 -1
- package/cjs/index.js +2 -185
- package/cjs/index.js.map +1 -1
- package/cjs/integration.js +194 -0
- package/cjs/integration.js.map +1 -0
- package/cjs/node_modules/lodash.debounce/index.js +384 -0
- package/cjs/node_modules/lodash.debounce/index.js.map +1 -0
- package/cjs/replay.js +201 -414
- package/cjs/replay.js.map +1 -1
- package/cjs/session/Session.js.map +1 -1
- package/cjs/session/createSession.js.map +1 -1
- package/cjs/session/fetchSession.js.map +1 -1
- package/cjs/session/getSession.js.map +1 -1
- package/cjs/session/saveSession.js.map +1 -1
- package/cjs/util/addEvent.js +47 -0
- package/cjs/util/addEvent.js.map +1 -0
- package/cjs/util/addMemoryEntry.js +23 -0
- package/cjs/util/addMemoryEntry.js.map +1 -0
- package/cjs/util/createPayload.js.map +1 -1
- package/cjs/util/createPerformanceSpans.js +30 -0
- package/cjs/util/createPerformanceSpans.js.map +1 -0
- package/cjs/util/createReplayEnvelope.js +34 -0
- package/cjs/util/createReplayEnvelope.js.map +1 -0
- package/cjs/util/getReplayEvent.js +32 -0
- package/cjs/util/getReplayEvent.js.map +1 -0
- package/cjs/util/isSessionExpired.js.map +1 -1
- package/cjs/util/monkeyPatchRecordDroppedEvent.js +44 -0
- package/cjs/util/monkeyPatchRecordDroppedEvent.js.map +1 -0
- package/cjs/util/shouldFilterRequest.js +30 -0
- package/cjs/util/shouldFilterRequest.js.map +1 -0
- package/esm/_virtual/_commonjsHelpers.js +35 -0
- package/esm/_virtual/_commonjsHelpers.js.map +1 -0
- package/esm/constants.js +7 -1
- package/esm/constants.js.map +1 -1
- package/esm/coreHandlers/breadcrumbHandler.js.map +1 -1
- package/esm/coreHandlers/handleFetch.js +33 -7
- package/esm/coreHandlers/handleFetch.js.map +1 -1
- package/esm/coreHandlers/handleGlobalEvent.js +86 -0
- package/esm/coreHandlers/handleGlobalEvent.js.map +1 -0
- package/esm/coreHandlers/handleHistory.js +30 -1
- package/esm/coreHandlers/handleHistory.js.map +1 -1
- package/esm/coreHandlers/handleScope.js +4 -9
- package/esm/coreHandlers/handleScope.js.map +1 -1
- package/esm/coreHandlers/handleXhr.js +33 -4
- package/esm/coreHandlers/handleXhr.js.map +1 -1
- package/esm/coreHandlers/performanceObserver.js +45 -0
- package/esm/coreHandlers/performanceObserver.js.map +1 -0
- package/esm/createPerformanceEntry.js +0 -6
- package/esm/createPerformanceEntry.js.map +1 -1
- package/esm/eventBuffer.js.map +1 -1
- package/esm/index.js +1 -188
- package/esm/index.js.map +1 -1
- package/esm/integration.js +192 -0
- package/esm/integration.js.map +1 -0
- package/esm/node_modules/lodash.debounce/index.js +382 -0
- package/esm/node_modules/lodash.debounce/index.js.map +1 -0
- package/esm/replay.js +200 -413
- package/esm/replay.js.map +1 -1
- package/esm/session/Session.js.map +1 -1
- package/esm/session/createSession.js.map +1 -1
- package/esm/session/fetchSession.js.map +1 -1
- package/esm/session/getSession.js.map +1 -1
- package/esm/session/saveSession.js.map +1 -1
- package/esm/util/addEvent.js +42 -0
- package/esm/util/addEvent.js.map +1 -0
- package/esm/util/addMemoryEntry.js +21 -0
- package/esm/util/addMemoryEntry.js.map +1 -0
- package/esm/util/createPayload.js.map +1 -1
- package/esm/util/createPerformanceSpans.js +28 -0
- package/esm/util/createPerformanceSpans.js.map +1 -0
- package/esm/util/createReplayEnvelope.js +32 -0
- package/esm/util/createReplayEnvelope.js.map +1 -0
- package/esm/util/getReplayEvent.js +30 -0
- package/esm/util/getReplayEvent.js.map +1 -0
- package/esm/util/isSessionExpired.js.map +1 -1
- package/esm/util/monkeyPatchRecordDroppedEvent.js +41 -0
- package/esm/util/monkeyPatchRecordDroppedEvent.js.map +1 -0
- package/esm/util/shouldFilterRequest.js +25 -0
- package/esm/util/shouldFilterRequest.js.map +1 -0
- package/package.json +7 -8
- package/types/constants.d.ts +5 -0
- package/types/constants.d.ts.map +1 -1
- package/types/coreHandlers/breadcrumbHandler.d.ts +1 -1
- package/types/coreHandlers/breadcrumbHandler.d.ts.map +1 -1
- package/types/coreHandlers/handleFetch.d.ts +9 -2
- package/types/coreHandlers/handleFetch.d.ts.map +1 -1
- package/types/coreHandlers/handleGlobalEvent.d.ts +7 -0
- package/types/coreHandlers/handleGlobalEvent.d.ts.map +1 -0
- package/types/coreHandlers/handleHistory.d.ts +7 -3
- package/types/coreHandlers/handleHistory.d.ts.map +1 -1
- package/types/coreHandlers/handleScope.d.ts.map +1 -1
- package/types/coreHandlers/handleXhr.d.ts +6 -3
- package/types/coreHandlers/handleXhr.d.ts.map +1 -1
- package/types/coreHandlers/performanceObserver.d.ts +6 -0
- package/types/coreHandlers/performanceObserver.d.ts.map +1 -0
- package/types/createPerformanceEntry.d.ts +1 -1
- package/types/createPerformanceEntry.d.ts.map +1 -1
- package/types/eventBuffer.d.ts +1 -7
- package/types/eventBuffer.d.ts.map +1 -1
- package/types/index.d.ts +1 -47
- package/types/index.d.ts.map +1 -1
- package/types/integration.d.ts +48 -0
- package/types/integration.d.ts.map +1 -0
- package/types/replay.d.ts +30 -59
- package/types/replay.d.ts.map +1 -1
- package/types/session/Session.d.ts +1 -26
- package/types/session/Session.d.ts.map +1 -1
- package/types/session/createSession.d.ts +1 -2
- package/types/session/createSession.d.ts.map +1 -1
- package/types/session/fetchSession.d.ts +1 -1
- package/types/session/fetchSession.d.ts.map +1 -1
- package/types/session/getSession.d.ts +1 -2
- package/types/session/getSession.d.ts.map +1 -1
- package/types/session/saveSession.d.ts +1 -1
- package/types/session/saveSession.d.ts.map +1 -1
- package/types/types/rrweb.d.ts +35 -0
- package/types/types/rrweb.d.ts.map +1 -0
- package/types/types.d.ts +65 -4
- package/types/types.d.ts.map +1 -1
- package/types/util/addEvent.d.ts +6 -0
- package/types/util/addEvent.d.ts.map +1 -0
- package/types/util/addMemoryEntry.d.ts +7 -0
- package/types/util/addMemoryEntry.d.ts.map +1 -0
- package/types/util/createPayload.d.ts +1 -1
- package/types/util/createPayload.d.ts.map +1 -1
- package/types/util/createPerformanceSpans.d.ts +7 -0
- package/types/util/createPerformanceSpans.d.ts.map +1 -0
- package/types/util/createReplayEnvelope.d.ts +3 -0
- package/types/util/createReplayEnvelope.d.ts.map +1 -0
- package/types/util/getReplayEvent.d.ts +9 -0
- package/types/util/getReplayEvent.d.ts.map +1 -0
- package/types/util/isSessionExpired.d.ts +1 -1
- package/types/util/isSessionExpired.d.ts.map +1 -1
- package/types/util/monkeyPatchRecordDroppedEvent.d.ts +3 -0
- package/types/util/monkeyPatchRecordDroppedEvent.d.ts.map +1 -0
- package/types/util/shouldFilterRequest.d.ts +6 -0
- package/types/util/shouldFilterRequest.d.ts.map +1 -0
- package/cjs/coreHandlers/spanHandler.js +0 -20
- package/cjs/coreHandlers/spanHandler.js.map +0 -1
- package/cjs/util/addInternalBreadcrumb.js +0 -25
- package/cjs/util/addInternalBreadcrumb.js.map +0 -1
- package/cjs/util/captureInternalException.js +0 -18
- package/cjs/util/captureInternalException.js.map +0 -1
- package/cjs/util/isIngestHost.js +0 -26
- package/cjs/util/isIngestHost.js.map +0 -1
- package/cjs/util/isInternal.js +0 -15
- package/cjs/util/isInternal.js.map +0 -1
- package/esm/coreHandlers/spanHandler.js +0 -18
- package/esm/coreHandlers/spanHandler.js.map +0 -1
- package/esm/util/addInternalBreadcrumb.js +0 -23
- package/esm/util/addInternalBreadcrumb.js.map +0 -1
- package/esm/util/captureInternalException.js +0 -16
- package/esm/util/captureInternalException.js.map +0 -1
- package/esm/util/isIngestHost.js +0 -21
- package/esm/util/isIngestHost.js.map +0 -1
- package/esm/util/isInternal.js +0 -13
- package/esm/util/isInternal.js.map +0 -1
- package/types/coreHandlers/spanHandler.d.ts +0 -4
- package/types/coreHandlers/spanHandler.d.ts.map +0 -1
- package/types/util/addInternalBreadcrumb.d.ts +0 -6
- package/types/util/addInternalBreadcrumb.d.ts.map +0 -1
- package/types/util/captureInternalException.d.ts +0 -5
- package/types/util/captureInternalException.d.ts.map +0 -1
- package/types/util/isIngestHost.d.ts +0 -5
- package/types/util/isIngestHost.d.ts.map +0 -1
- package/types/util/isInternal.d.ts +0 -6
- package/types/util/isInternal.d.ts.map +0 -1
package/esm/replay.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
|
|
2
|
-
import { getCurrentHub, addGlobalEventProcessor, setContext } from '@sentry/core';
|
|
3
|
-
import { logger, addInstrumentationHandler
|
|
4
|
-
import
|
|
2
|
+
import { captureException, getCurrentHub, addGlobalEventProcessor, setContext } from '@sentry/core';
|
|
3
|
+
import { logger, addInstrumentationHandler } from '@sentry/utils';
|
|
4
|
+
import lodash_debounce from './node_modules/lodash.debounce/index.js';
|
|
5
5
|
import './node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js';
|
|
6
|
-
import { SESSION_IDLE_DURATION, WINDOW,
|
|
6
|
+
import { SESSION_IDLE_DURATION, WINDOW, VISIBILITY_CHANGE_TIMEOUT, MAX_SESSION_LIFE, REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from './constants.js';
|
|
7
7
|
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { handleFetchSpanListener } from './coreHandlers/handleFetch.js';
|
|
9
|
+
import { handleGlobalEventListener } from './coreHandlers/handleGlobalEvent.js';
|
|
10
|
+
import { handleHistorySpanListener } from './coreHandlers/handleHistory.js';
|
|
11
|
+
import { handleXhrSpanListener } from './coreHandlers/handleXhr.js';
|
|
12
|
+
import { setupPerformanceObserver } from './coreHandlers/performanceObserver.js';
|
|
13
|
+
import { createPerformanceEntries } from './createPerformanceEntry.js';
|
|
10
14
|
import { createEventBuffer } from './eventBuffer.js';
|
|
11
15
|
import { deleteSession } from './session/deleteSession.js';
|
|
12
16
|
import { getSession } from './session/getSession.js';
|
|
13
17
|
import { saveSession } from './session/saveSession.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
18
|
+
import { addEvent } from './util/addEvent.js';
|
|
19
|
+
import { addMemoryEntry } from './util/addMemoryEntry.js';
|
|
16
20
|
import { createBreadcrumb } from './util/createBreadcrumb.js';
|
|
17
21
|
import { createPayload } from './util/createPayload.js';
|
|
18
|
-
import {
|
|
22
|
+
import { createPerformanceSpans } from './util/createPerformanceSpans.js';
|
|
23
|
+
import { createReplayEnvelope } from './util/createReplayEnvelope.js';
|
|
24
|
+
import { getReplayEvent } from './util/getReplayEvent.js';
|
|
19
25
|
import { isExpired } from './util/isExpired.js';
|
|
20
26
|
import { isSessionExpired } from './util/isSessionExpired.js';
|
|
27
|
+
import { overwriteRecordDroppedEvent, restoreRecordDroppedEvent } from './util/monkeyPatchRecordDroppedEvent.js';
|
|
21
28
|
import record from './node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js';
|
|
22
29
|
import { EventType } from './node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js';
|
|
23
30
|
|
|
@@ -29,9 +36,8 @@ import { EventType } from './node_modules/rrweb/es/rrweb/packages/rrweb/src/type
|
|
|
29
36
|
|
|
30
37
|
const BASE_RETRY_INTERVAL = 5000;
|
|
31
38
|
const MAX_RETRY_COUNT = 3;
|
|
32
|
-
const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay';
|
|
33
39
|
|
|
34
|
-
class ReplayContainer
|
|
40
|
+
class ReplayContainer {
|
|
35
41
|
__init() {this.eventBuffer = null;}
|
|
36
42
|
|
|
37
43
|
/**
|
|
@@ -39,39 +45,40 @@ class ReplayContainer {
|
|
|
39
45
|
*/
|
|
40
46
|
__init2() {this.performanceEvents = [];}
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Recording can happen in one of two modes:
|
|
50
|
+
* * session: Record the whole session, sending it continuously
|
|
51
|
+
* * error: Always keep the last 60s of recording, and when an error occurs, send it immediately
|
|
52
|
+
*/
|
|
53
|
+
__init3() {this.recordingMode = 'session';}
|
|
54
|
+
|
|
42
55
|
/**
|
|
43
56
|
* Options to pass to `rrweb.record()`
|
|
44
57
|
*/
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
__init4() {this._performanceObserver = null;}
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
__init5() {this._retryCount = 0;}
|
|
62
|
+
__init6() {this._retryInterval = BASE_RETRY_INTERVAL;}
|
|
50
63
|
|
|
51
|
-
|
|
64
|
+
__init7() {this._flushLock = null;}
|
|
52
65
|
|
|
53
66
|
/**
|
|
54
67
|
* Timestamp of the last user activity. This lives across sessions.
|
|
55
68
|
*/
|
|
56
|
-
|
|
69
|
+
__init8() {this._lastActivity = new Date().getTime();}
|
|
57
70
|
|
|
58
71
|
/**
|
|
59
72
|
* Is the integration currently active?
|
|
60
73
|
*/
|
|
61
|
-
|
|
74
|
+
__init9() {this._isEnabled = false;}
|
|
62
75
|
|
|
63
76
|
/**
|
|
64
77
|
* Paused is a state where:
|
|
65
78
|
* - DOM Recording is not listening at all
|
|
66
79
|
* - Nothing will be added to event buffer (e.g. core SDK events)
|
|
67
80
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Integration will wait until an error occurs before creating and sending a
|
|
72
|
-
* replay.
|
|
73
|
-
*/
|
|
74
|
-
__init10() {this._waitForError = false;}
|
|
81
|
+
__init10() {this._isPaused = false;}
|
|
75
82
|
|
|
76
83
|
/**
|
|
77
84
|
* Have we attached listeners to the core SDK?
|
|
@@ -84,10 +91,6 @@ class ReplayContainer {
|
|
|
84
91
|
*/
|
|
85
92
|
__init12() {this._stopRecording = null;}
|
|
86
93
|
|
|
87
|
-
/**
|
|
88
|
-
* We overwrite `client.recordDroppedEvent`, but store the original method here so we can restore it.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
94
|
__init13() {this._context = {
|
|
92
95
|
errorIds: new Set(),
|
|
93
96
|
traceIds: new Set(),
|
|
@@ -97,15 +100,35 @@ class ReplayContainer {
|
|
|
97
100
|
initialUrl: '',
|
|
98
101
|
};}
|
|
99
102
|
|
|
100
|
-
constructor({ options, recordingOptions }) {;ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);ReplayContainer.prototype.__init18.call(this);ReplayContainer.prototype.__init19.call(this);
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
+
constructor({ options, recordingOptions }) {;ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);ReplayContainer.prototype.__init18.call(this);ReplayContainer.prototype.__init19.call(this);
|
|
104
|
+
this._recordingOptions = recordingOptions;
|
|
105
|
+
this._options = options;
|
|
103
106
|
|
|
104
|
-
this._debouncedFlush =
|
|
105
|
-
maxWait: this.
|
|
107
|
+
this._debouncedFlush = lodash_debounce(() => this.flush(), this._options.flushMinDelay, {
|
|
108
|
+
maxWait: this._options.flushMaxDelay,
|
|
106
109
|
});
|
|
107
110
|
}
|
|
108
111
|
|
|
112
|
+
/** Get the event context. */
|
|
113
|
+
getContext() {
|
|
114
|
+
return this._context;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** If recording is currently enabled. */
|
|
118
|
+
isEnabled() {
|
|
119
|
+
return this._isEnabled;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** If recording is currently paused. */
|
|
123
|
+
isPaused() {
|
|
124
|
+
return this._isPaused;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Get the replay integration options. */
|
|
128
|
+
getOptions() {
|
|
129
|
+
return this._options;
|
|
130
|
+
}
|
|
131
|
+
|
|
109
132
|
/**
|
|
110
133
|
* Initializes the plugin.
|
|
111
134
|
*
|
|
@@ -119,7 +142,7 @@ class ReplayContainer {
|
|
|
119
142
|
|
|
120
143
|
// If there is no session, then something bad has happened - can't continue
|
|
121
144
|
if (!this.session) {
|
|
122
|
-
|
|
145
|
+
this.handleException(new Error('No session found'));
|
|
123
146
|
return;
|
|
124
147
|
}
|
|
125
148
|
|
|
@@ -133,9 +156,7 @@ class ReplayContainer {
|
|
|
133
156
|
// when an error will occur, so we need to keep a buffer of
|
|
134
157
|
// replay events.
|
|
135
158
|
if (this.session.sampled === 'error') {
|
|
136
|
-
|
|
137
|
-
this.recordingOptions.checkoutEveryNms = 60000;
|
|
138
|
-
this._waitForError = true;
|
|
159
|
+
this.recordingMode = 'error';
|
|
139
160
|
}
|
|
140
161
|
|
|
141
162
|
// setup() is generally called on page load or manually - in both cases we
|
|
@@ -143,7 +164,7 @@ class ReplayContainer {
|
|
|
143
164
|
this.updateSessionActivity();
|
|
144
165
|
|
|
145
166
|
this.eventBuffer = createEventBuffer({
|
|
146
|
-
useCompression: Boolean(this.
|
|
167
|
+
useCompression: Boolean(this._options.useCompression),
|
|
147
168
|
});
|
|
148
169
|
|
|
149
170
|
this.addListeners();
|
|
@@ -161,15 +182,31 @@ class ReplayContainer {
|
|
|
161
182
|
startRecording() {
|
|
162
183
|
try {
|
|
163
184
|
this._stopRecording = record({
|
|
164
|
-
...this.
|
|
185
|
+
...this._recordingOptions,
|
|
186
|
+
// When running in error sampling mode, we need to overwrite `checkoutEveryNth`
|
|
187
|
+
// Without this, it would record forever, until an error happens, which we don't want
|
|
188
|
+
// instead, we'll always keep the last 60 seconds of replay before an error happened
|
|
189
|
+
...(this.recordingMode === 'error' && { checkoutEveryNth: 60000 }),
|
|
165
190
|
emit: this.handleRecordingEmit,
|
|
166
191
|
});
|
|
167
192
|
} catch (err) {
|
|
168
|
-
|
|
169
|
-
captureInternalException(err);
|
|
193
|
+
this.handleException(err);
|
|
170
194
|
}
|
|
171
195
|
}
|
|
172
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Stops the recording, if it was running.
|
|
199
|
+
* Returns true if it was stopped, else false.
|
|
200
|
+
*/
|
|
201
|
+
stopRecording() {
|
|
202
|
+
if (this._stopRecording) {
|
|
203
|
+
this._stopRecording();
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
173
210
|
/**
|
|
174
211
|
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK
|
|
175
212
|
* does not support a teardown
|
|
@@ -179,12 +216,11 @@ class ReplayContainer {
|
|
|
179
216
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Stopping Replays');
|
|
180
217
|
this._isEnabled = false;
|
|
181
218
|
this.removeListeners();
|
|
182
|
-
_optionalChain([this, 'access',
|
|
183
|
-
_optionalChain([this, 'access',
|
|
219
|
+
_optionalChain([this, 'access', _11 => _11._stopRecording, 'optionalCall', _12 => _12()]);
|
|
220
|
+
_optionalChain([this, 'access', _13 => _13.eventBuffer, 'optionalAccess', _14 => _14.destroy, 'call', _15 => _15()]);
|
|
184
221
|
this.eventBuffer = null;
|
|
185
222
|
} catch (err) {
|
|
186
|
-
|
|
187
|
-
captureInternalException(err);
|
|
223
|
+
this.handleException(err);
|
|
188
224
|
}
|
|
189
225
|
}
|
|
190
226
|
|
|
@@ -201,8 +237,7 @@ class ReplayContainer {
|
|
|
201
237
|
this._stopRecording = undefined;
|
|
202
238
|
}
|
|
203
239
|
} catch (err) {
|
|
204
|
-
|
|
205
|
-
captureInternalException(err);
|
|
240
|
+
this.handleException(err);
|
|
206
241
|
}
|
|
207
242
|
}
|
|
208
243
|
|
|
@@ -217,14 +252,22 @@ class ReplayContainer {
|
|
|
217
252
|
this.startRecording();
|
|
218
253
|
}
|
|
219
254
|
|
|
255
|
+
/** A wrapper to conditionally capture exceptions. */
|
|
256
|
+
handleException(error) {
|
|
257
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', error);
|
|
258
|
+
|
|
259
|
+
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && this._options._experiments && this._options._experiments.captureExceptions) {
|
|
260
|
+
captureException(error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
220
264
|
/** for tests only */
|
|
221
265
|
clearSession() {
|
|
222
266
|
try {
|
|
223
267
|
deleteSession();
|
|
224
268
|
this.session = undefined;
|
|
225
269
|
} catch (err) {
|
|
226
|
-
|
|
227
|
-
captureInternalException(err);
|
|
270
|
+
this.handleException(err);
|
|
228
271
|
}
|
|
229
272
|
}
|
|
230
273
|
|
|
@@ -235,10 +278,10 @@ class ReplayContainer {
|
|
|
235
278
|
loadSession({ expiry }) {
|
|
236
279
|
const { type, session } = getSession({
|
|
237
280
|
expiry,
|
|
238
|
-
stickySession: Boolean(this.
|
|
281
|
+
stickySession: Boolean(this._options.stickySession),
|
|
239
282
|
currentSession: this.session,
|
|
240
|
-
sessionSampleRate: this.
|
|
241
|
-
errorSampleRate: this.
|
|
283
|
+
sessionSampleRate: this._options.sessionSampleRate,
|
|
284
|
+
errorSampleRate: this._options.errorSampleRate,
|
|
242
285
|
});
|
|
243
286
|
|
|
244
287
|
// If session was newly created (i.e. was not loaded from storage), then
|
|
@@ -247,8 +290,8 @@ class ReplayContainer {
|
|
|
247
290
|
this.setInitialState();
|
|
248
291
|
}
|
|
249
292
|
|
|
250
|
-
if (session.id !== _optionalChain([this, 'access',
|
|
251
|
-
session.previousSessionId = _optionalChain([this, 'access',
|
|
293
|
+
if (session.id !== _optionalChain([this, 'access', _16 => _16.session, 'optionalAccess', _17 => _17.id])) {
|
|
294
|
+
session.previousSessionId = _optionalChain([this, 'access', _18 => _18.session, 'optionalAccess', _19 => _19.id]);
|
|
252
295
|
}
|
|
253
296
|
|
|
254
297
|
this.session = session;
|
|
@@ -283,27 +326,26 @@ class ReplayContainer {
|
|
|
283
326
|
WINDOW.addEventListener('focus', this.handleWindowFocus);
|
|
284
327
|
|
|
285
328
|
// We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
|
|
286
|
-
this.
|
|
329
|
+
overwriteRecordDroppedEvent(this._context.errorIds);
|
|
287
330
|
|
|
288
331
|
// There is no way to remove these listeners, so ensure they are only added once
|
|
289
332
|
if (!this._hasInitializedCoreListeners) {
|
|
290
333
|
// Listeners from core SDK //
|
|
291
334
|
const scope = getCurrentHub().getScope();
|
|
292
|
-
_optionalChain([scope, 'optionalAccess',
|
|
335
|
+
_optionalChain([scope, 'optionalAccess', _20 => _20.addScopeListener, 'call', _21 => _21(this.handleCoreBreadcrumbListener('scope'))]);
|
|
293
336
|
addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
|
|
294
|
-
addInstrumentationHandler('fetch', this
|
|
295
|
-
addInstrumentationHandler('xhr', this
|
|
296
|
-
addInstrumentationHandler('history', this
|
|
337
|
+
addInstrumentationHandler('fetch', handleFetchSpanListener(this));
|
|
338
|
+
addInstrumentationHandler('xhr', handleXhrSpanListener(this));
|
|
339
|
+
addInstrumentationHandler('history', handleHistorySpanListener(this));
|
|
297
340
|
|
|
298
341
|
// Tag all (non replay) events that get sent to Sentry with the current
|
|
299
342
|
// replay ID so that we can reference them later in the UI
|
|
300
|
-
addGlobalEventProcessor(this
|
|
343
|
+
addGlobalEventProcessor(handleGlobalEventListener(this));
|
|
301
344
|
|
|
302
345
|
this._hasInitializedCoreListeners = true;
|
|
303
346
|
}
|
|
304
347
|
} catch (err) {
|
|
305
|
-
|
|
306
|
-
captureInternalException(err);
|
|
348
|
+
this.handleException(err);
|
|
307
349
|
}
|
|
308
350
|
|
|
309
351
|
// _performanceObserver //
|
|
@@ -311,30 +353,7 @@ class ReplayContainer {
|
|
|
311
353
|
return;
|
|
312
354
|
}
|
|
313
355
|
|
|
314
|
-
this._performanceObserver =
|
|
315
|
-
|
|
316
|
-
// Observe almost everything for now (no mark/measure)
|
|
317
|
-
[
|
|
318
|
-
'element',
|
|
319
|
-
'event',
|
|
320
|
-
'first-input',
|
|
321
|
-
'largest-contentful-paint',
|
|
322
|
-
'layout-shift',
|
|
323
|
-
'longtask',
|
|
324
|
-
'navigation',
|
|
325
|
-
'paint',
|
|
326
|
-
'resource',
|
|
327
|
-
].forEach(type => {
|
|
328
|
-
try {
|
|
329
|
-
_optionalChain([this, 'access', _32 => _32._performanceObserver, 'optionalAccess', _33 => _33.observe, 'call', _34 => _34({
|
|
330
|
-
type,
|
|
331
|
-
buffered: true,
|
|
332
|
-
})]);
|
|
333
|
-
} catch (e) {
|
|
334
|
-
// This can throw if an entry type is not supported in the browser.
|
|
335
|
-
// Ignore these errors.
|
|
336
|
-
}
|
|
337
|
-
});
|
|
356
|
+
this._performanceObserver = setupPerformanceObserver(this);
|
|
338
357
|
}
|
|
339
358
|
|
|
340
359
|
/**
|
|
@@ -347,15 +366,14 @@ class ReplayContainer {
|
|
|
347
366
|
WINDOW.removeEventListener('blur', this.handleWindowBlur);
|
|
348
367
|
WINDOW.removeEventListener('focus', this.handleWindowFocus);
|
|
349
368
|
|
|
350
|
-
|
|
369
|
+
restoreRecordDroppedEvent();
|
|
351
370
|
|
|
352
371
|
if (this._performanceObserver) {
|
|
353
372
|
this._performanceObserver.disconnect();
|
|
354
373
|
this._performanceObserver = null;
|
|
355
374
|
}
|
|
356
375
|
} catch (err) {
|
|
357
|
-
|
|
358
|
-
captureInternalException(err);
|
|
376
|
+
this.handleException(err);
|
|
359
377
|
}
|
|
360
378
|
}
|
|
361
379
|
|
|
@@ -368,12 +386,12 @@ class ReplayContainer {
|
|
|
368
386
|
* processing and hand back control to caller.
|
|
369
387
|
*/
|
|
370
388
|
addUpdate(cb) {
|
|
371
|
-
// We need to always run `cb` (e.g. in the case of `this.
|
|
372
|
-
const cbResult = _optionalChain([cb, 'optionalCall',
|
|
389
|
+
// We need to always run `cb` (e.g. in the case of `this.recordingMode == 'error'`)
|
|
390
|
+
const cbResult = _optionalChain([cb, 'optionalCall', _22 => _22()]);
|
|
373
391
|
|
|
374
392
|
// If this option is turned on then we will only want to call `flush`
|
|
375
393
|
// explicitly
|
|
376
|
-
if (this.
|
|
394
|
+
if (this.recordingMode === 'error') {
|
|
377
395
|
return;
|
|
378
396
|
}
|
|
379
397
|
|
|
@@ -388,79 +406,12 @@ class ReplayContainer {
|
|
|
388
406
|
this._debouncedFlush();
|
|
389
407
|
}
|
|
390
408
|
|
|
391
|
-
/**
|
|
392
|
-
* Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
|
|
393
|
-
* events as a tag. Also handles the case where we only want to capture a reply
|
|
394
|
-
* when an error occurs.
|
|
395
|
-
**/
|
|
396
|
-
__init14() {this.handleGlobalEvent = (event) => {
|
|
397
|
-
// Do not apply replayId to the root event
|
|
398
|
-
if (
|
|
399
|
-
// @ts-ignore new event type
|
|
400
|
-
event.type === REPLAY_EVENT_NAME
|
|
401
|
-
) {
|
|
402
|
-
// Replays have separate set of breadcrumbs, do not include breadcrumbs
|
|
403
|
-
// from core SDK
|
|
404
|
-
delete event.breadcrumbs;
|
|
405
|
-
return event;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Only tag transactions with replayId if not waiting for an error
|
|
409
|
-
if (event.type !== 'transaction' || !this._waitForError) {
|
|
410
|
-
event.tags = { ...event.tags, replayId: _optionalChain([this, 'access', _36 => _36.session, 'optionalAccess', _37 => _37.id]) };
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// Collect traceIds in _context regardless of `_waitForError` - if it's true,
|
|
414
|
-
// _context gets cleared on every checkout
|
|
415
|
-
if (event.type === 'transaction') {
|
|
416
|
-
this._context.traceIds.add(String(_optionalChain([event, 'access', _38 => _38.contexts, 'optionalAccess', _39 => _39.trace, 'optionalAccess', _40 => _40.trace_id]) || ''));
|
|
417
|
-
return event;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// XXX: Is it safe to assume that all other events are error events?
|
|
421
|
-
// @ts-ignore: Type 'undefined' is not assignable to type 'string'.ts(2345)
|
|
422
|
-
this._context.errorIds.add(event.event_id);
|
|
423
|
-
|
|
424
|
-
const exc = _optionalChain([event, 'access', _41 => _41.exception, 'optionalAccess', _42 => _42.values, 'optionalAccess', _43 => _43[0]]);
|
|
425
|
-
addInternalBreadcrumb({
|
|
426
|
-
message: `Tagging event (${event.event_id}) - ${event.message} - ${_optionalChain([exc, 'optionalAccess', _44 => _44.type]) || 'Unknown'}: ${
|
|
427
|
-
_optionalChain([exc, 'optionalAccess', _45 => _45.value]) || 'n/a'
|
|
428
|
-
}`,
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Need to be very careful that this does not cause an infinite loop
|
|
432
|
-
if (
|
|
433
|
-
this._waitForError &&
|
|
434
|
-
event.exception &&
|
|
435
|
-
event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
|
|
436
|
-
) {
|
|
437
|
-
setTimeout(async () => {
|
|
438
|
-
// Allow flush to complete before resuming as a session recording, otherwise
|
|
439
|
-
// the checkout from `startRecording` may be included in the payload.
|
|
440
|
-
// Prefer to keep the error replay as a separate (and smaller) segment
|
|
441
|
-
// than the session replay.
|
|
442
|
-
await this.flushImmediate();
|
|
443
|
-
|
|
444
|
-
if (this._stopRecording) {
|
|
445
|
-
this._stopRecording();
|
|
446
|
-
// Reset all "capture on error" configuration before
|
|
447
|
-
// starting a new recording
|
|
448
|
-
delete this.recordingOptions.checkoutEveryNms;
|
|
449
|
-
this._waitForError = false;
|
|
450
|
-
this.startRecording();
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return event;
|
|
456
|
-
};}
|
|
457
|
-
|
|
458
409
|
/**
|
|
459
410
|
* Handler for recording events.
|
|
460
411
|
*
|
|
461
412
|
* Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
|
|
462
413
|
*/
|
|
463
|
-
|
|
414
|
+
__init14() {this.handleRecordingEmit = (
|
|
464
415
|
event,
|
|
465
416
|
isCheckout,
|
|
466
417
|
) => {
|
|
@@ -477,13 +428,13 @@ class ReplayContainer {
|
|
|
477
428
|
// when an error occurs. Clear any state that happens before this current
|
|
478
429
|
// checkout. This needs to happen before `addEvent()` which updates state
|
|
479
430
|
// dependent on this reset.
|
|
480
|
-
if (this.
|
|
431
|
+
if (this.recordingMode === 'error' && event.type === 2) {
|
|
481
432
|
this.setInitialState();
|
|
482
433
|
}
|
|
483
434
|
|
|
484
435
|
// We need to clear existing events on a checkout, otherwise they are
|
|
485
436
|
// incremental event updates and should be appended
|
|
486
|
-
|
|
437
|
+
addEvent(this, event, isCheckout);
|
|
487
438
|
|
|
488
439
|
// Different behavior for full snapshots (type=2), ignore other event types
|
|
489
440
|
// See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
|
|
@@ -497,13 +448,13 @@ class ReplayContainer {
|
|
|
497
448
|
// of the previous session. Do not immediately flush in this case
|
|
498
449
|
// to avoid capturing only the checkout and instead the replay will
|
|
499
450
|
// be captured if they perform any follow-up actions.
|
|
500
|
-
if (_optionalChain([this, 'access',
|
|
451
|
+
if (_optionalChain([this, 'access', _23 => _23.session, 'optionalAccess', _24 => _24.previousSessionId])) {
|
|
501
452
|
return true;
|
|
502
453
|
}
|
|
503
454
|
|
|
504
455
|
// See note above re: session start needs to reflect the most recent
|
|
505
456
|
// checkout.
|
|
506
|
-
if (this.
|
|
457
|
+
if (this.recordingMode === 'error' && this.session && this._context.earliestEvent) {
|
|
507
458
|
this.session.started = this._context.earliestEvent;
|
|
508
459
|
this._maybeSaveSession();
|
|
509
460
|
}
|
|
@@ -512,7 +463,7 @@ class ReplayContainer {
|
|
|
512
463
|
// a previous session ID. In this case, we want to buffer events
|
|
513
464
|
// for a set amount of time before flushing. This can help avoid
|
|
514
465
|
// capturing replays of users that immediately close the window.
|
|
515
|
-
setTimeout(() => this.conditionalFlush(), this.
|
|
466
|
+
setTimeout(() => this.conditionalFlush(), this._options.initialFlushDelay);
|
|
516
467
|
|
|
517
468
|
// Cancel any previously debounced flushes to ensure there are no [near]
|
|
518
469
|
// simultaneous flushes happening. The latter request should be
|
|
@@ -522,7 +473,7 @@ class ReplayContainer {
|
|
|
522
473
|
// This can happen because there's no guarantee that a recording event
|
|
523
474
|
// happens first. e.g. a mouse click can happen and trigger a debounced
|
|
524
475
|
// flush before the checkout.
|
|
525
|
-
_optionalChain([this, 'access',
|
|
476
|
+
_optionalChain([this, 'access', _25 => _25._debouncedFlush, 'optionalAccess', _26 => _26.cancel, 'call', _27 => _27()]);
|
|
526
477
|
|
|
527
478
|
return true;
|
|
528
479
|
});
|
|
@@ -534,7 +485,7 @@ class ReplayContainer {
|
|
|
534
485
|
* be hidden. Likewise, moving a different window to cover the contents of the
|
|
535
486
|
* page will also trigger a change to a hidden state.
|
|
536
487
|
*/
|
|
537
|
-
|
|
488
|
+
__init15() {this.handleVisibilityChange = () => {
|
|
538
489
|
if (WINDOW.document.visibilityState === 'visible') {
|
|
539
490
|
this.doChangeToForegroundTasks();
|
|
540
491
|
} else {
|
|
@@ -545,7 +496,7 @@ class ReplayContainer {
|
|
|
545
496
|
/**
|
|
546
497
|
* Handle when page is blurred
|
|
547
498
|
*/
|
|
548
|
-
|
|
499
|
+
__init16() {this.handleWindowBlur = () => {
|
|
549
500
|
const breadcrumb = createBreadcrumb({
|
|
550
501
|
category: 'ui.blur',
|
|
551
502
|
});
|
|
@@ -558,7 +509,7 @@ class ReplayContainer {
|
|
|
558
509
|
/**
|
|
559
510
|
* Handle when page is focused
|
|
560
511
|
*/
|
|
561
|
-
|
|
512
|
+
__init17() {this.handleWindowFocus = () => {
|
|
562
513
|
const breadcrumb = createBreadcrumb({
|
|
563
514
|
category: 'ui.focus',
|
|
564
515
|
});
|
|
@@ -568,45 +519,12 @@ class ReplayContainer {
|
|
|
568
519
|
this.doChangeToForegroundTasks(breadcrumb);
|
|
569
520
|
};}
|
|
570
521
|
|
|
571
|
-
/**
|
|
572
|
-
* Handler for Sentry Core SDK events.
|
|
573
|
-
*
|
|
574
|
-
* These specific events will create span-like objects in the recording.
|
|
575
|
-
*/
|
|
576
|
-
__init19() {this.handleCoreSpanListener =
|
|
577
|
-
(type) =>
|
|
578
|
-
(handlerData) => {
|
|
579
|
-
if (!this._isEnabled) {
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
const result = spanHandler(type, handlerData);
|
|
584
|
-
|
|
585
|
-
if (result === null) {
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
if (type === 'history') {
|
|
590
|
-
// Need to collect visited URLs
|
|
591
|
-
this._context.urls.push(result.name);
|
|
592
|
-
this.triggerUserActivity();
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
this.addUpdate(() => {
|
|
596
|
-
void this.createPerformanceSpans([result ]);
|
|
597
|
-
// Returning true will cause `addUpdate` to not flush
|
|
598
|
-
// We do not want network requests to cause a flush. This will prevent
|
|
599
|
-
// recurring/polling requests from keeping the replay session alive.
|
|
600
|
-
return ['xhr', 'fetch'].includes(type);
|
|
601
|
-
});
|
|
602
|
-
};}
|
|
603
|
-
|
|
604
522
|
/**
|
|
605
523
|
* Handler for Sentry Core SDK events.
|
|
606
524
|
*
|
|
607
525
|
* These events will create breadcrumb-like objects in the recording.
|
|
608
526
|
*/
|
|
609
|
-
|
|
527
|
+
__init18() {this.handleCoreBreadcrumbListener =
|
|
610
528
|
(type) =>
|
|
611
529
|
(handlerData) => {
|
|
612
530
|
if (!this._isEnabled) {
|
|
@@ -630,7 +548,7 @@ class ReplayContainer {
|
|
|
630
548
|
}
|
|
631
549
|
|
|
632
550
|
this.addUpdate(() => {
|
|
633
|
-
|
|
551
|
+
addEvent(this, {
|
|
634
552
|
type: EventType.Custom,
|
|
635
553
|
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
|
|
636
554
|
// but maybe we should just keep them as milliseconds
|
|
@@ -646,19 +564,6 @@ class ReplayContainer {
|
|
|
646
564
|
});
|
|
647
565
|
};}
|
|
648
566
|
|
|
649
|
-
/**
|
|
650
|
-
* Keep a list of performance entries that will be sent with a replay
|
|
651
|
-
*/
|
|
652
|
-
__init21() {this.handle_performanceObserver = (list) => {
|
|
653
|
-
// For whatever reason the observer was returning duplicate navigation
|
|
654
|
-
// entries (the other entry types were not duplicated).
|
|
655
|
-
const newPerformanceEntries = dedupePerformanceEntries(
|
|
656
|
-
this.performanceEvents,
|
|
657
|
-
list.getEntries() ,
|
|
658
|
-
);
|
|
659
|
-
this.performanceEvents = newPerformanceEntries;
|
|
660
|
-
};}
|
|
661
|
-
|
|
662
567
|
/**
|
|
663
568
|
* Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
|
|
664
569
|
*/
|
|
@@ -713,45 +618,6 @@ class ReplayContainer {
|
|
|
713
618
|
record.takeFullSnapshot(true);
|
|
714
619
|
}
|
|
715
620
|
|
|
716
|
-
/**
|
|
717
|
-
* Add an event to the event buffer
|
|
718
|
-
*/
|
|
719
|
-
addEvent(event, isCheckout) {
|
|
720
|
-
if (!this.eventBuffer) {
|
|
721
|
-
// This implies that `_isEnabled` is false
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
if (this._isPaused) {
|
|
726
|
-
// Do not add to event buffer when recording is paused
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// TODO: sadness -- we will want to normalize timestamps to be in ms -
|
|
731
|
-
// requires coordination with frontend
|
|
732
|
-
const isMs = event.timestamp > 9999999999;
|
|
733
|
-
const timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
|
|
734
|
-
|
|
735
|
-
// Throw out events that happen more than 5 minutes ago. This can happen if
|
|
736
|
-
// page has been left open and idle for a long period of time and user
|
|
737
|
-
// comes back to trigger a new session. The performance entries rely on
|
|
738
|
-
// `performance.timeOrigin`, which is when the page first opened.
|
|
739
|
-
if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// Only record earliest event if a new session was created, otherwise it
|
|
744
|
-
// shouldn't be relevant
|
|
745
|
-
if (
|
|
746
|
-
_optionalChain([this, 'access', _51 => _51.session, 'optionalAccess', _52 => _52.segmentId]) === 0 &&
|
|
747
|
-
(!this._context.earliestEvent || timestampInMs < this._context.earliestEvent)
|
|
748
|
-
) {
|
|
749
|
-
this._context.earliestEvent = timestampInMs;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
this.eventBuffer.addEvent(event, isCheckout);
|
|
753
|
-
}
|
|
754
|
-
|
|
755
621
|
/**
|
|
756
622
|
* Update user activity (across session lifespans)
|
|
757
623
|
*/
|
|
@@ -800,7 +666,7 @@ class ReplayContainer {
|
|
|
800
666
|
*/
|
|
801
667
|
createCustomBreadcrumb(breadcrumb) {
|
|
802
668
|
this.addUpdate(() => {
|
|
803
|
-
|
|
669
|
+
addEvent(this, {
|
|
804
670
|
type: EventType.Custom,
|
|
805
671
|
timestamp: breadcrumb.timestamp || 0,
|
|
806
672
|
data: {
|
|
@@ -811,30 +677,6 @@ class ReplayContainer {
|
|
|
811
677
|
});
|
|
812
678
|
}
|
|
813
679
|
|
|
814
|
-
/**
|
|
815
|
-
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
|
|
816
|
-
*/
|
|
817
|
-
createPerformanceSpans(entries) {
|
|
818
|
-
return Promise.all(
|
|
819
|
-
entries.map(({ type, start, end, name, data }) =>
|
|
820
|
-
this.addEvent({
|
|
821
|
-
type: EventType.Custom,
|
|
822
|
-
timestamp: start,
|
|
823
|
-
data: {
|
|
824
|
-
tag: 'performanceSpan',
|
|
825
|
-
payload: {
|
|
826
|
-
op: type,
|
|
827
|
-
description: name,
|
|
828
|
-
startTimestamp: start,
|
|
829
|
-
endTimestamp: end,
|
|
830
|
-
data,
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
}),
|
|
834
|
-
),
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
|
|
838
680
|
/**
|
|
839
681
|
* Observed performance events are added to `this.performanceEvents`. These
|
|
840
682
|
* are included in the replay event before it is finished and sent to Sentry.
|
|
@@ -844,24 +686,7 @@ class ReplayContainer {
|
|
|
844
686
|
const entries = [...this.performanceEvents];
|
|
845
687
|
this.performanceEvents = [];
|
|
846
688
|
|
|
847
|
-
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* Create a "span" for the total amount of memory being used by JS objects
|
|
852
|
-
* (including v8 internal objects).
|
|
853
|
-
*/
|
|
854
|
-
addMemoryEntry() {
|
|
855
|
-
// window.performance.memory is a non-standard API and doesn't work on all browsers
|
|
856
|
-
// so we check before creating the event.
|
|
857
|
-
if (!('memory' in WINDOW.performance)) {
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
return this.createPerformanceSpans([
|
|
862
|
-
// @ts-ignore memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
|
|
863
|
-
createMemoryEntry(WINDOW.performance.memory),
|
|
864
|
-
]);
|
|
689
|
+
createPerformanceSpans(this, createPerformanceEntries(entries));
|
|
865
690
|
}
|
|
866
691
|
|
|
867
692
|
/**
|
|
@@ -872,7 +697,7 @@ class ReplayContainer {
|
|
|
872
697
|
* Returns true if session is not expired, false otherwise.
|
|
873
698
|
*/
|
|
874
699
|
checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
|
|
875
|
-
const oldSessionId = _optionalChain([this, 'access',
|
|
700
|
+
const oldSessionId = _optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id]);
|
|
876
701
|
|
|
877
702
|
// Prevent starting a new session if the last user activity is older than
|
|
878
703
|
// MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
|
|
@@ -889,7 +714,7 @@ class ReplayContainer {
|
|
|
889
714
|
this.loadSession({ expiry });
|
|
890
715
|
|
|
891
716
|
// Session was expired if session ids do not match
|
|
892
|
-
const expired = oldSessionId !== _optionalChain([this, 'access',
|
|
717
|
+
const expired = oldSessionId !== _optionalChain([this, 'access', _30 => _30.session, 'optionalAccess', _31 => _31.id]);
|
|
893
718
|
|
|
894
719
|
if (!expired) {
|
|
895
720
|
return true;
|
|
@@ -902,10 +727,10 @@ class ReplayContainer {
|
|
|
902
727
|
}
|
|
903
728
|
|
|
904
729
|
/**
|
|
905
|
-
* Only flush if `this.
|
|
730
|
+
* Only flush if `this.recordingMode === 'session'`
|
|
906
731
|
*/
|
|
907
732
|
conditionalFlush() {
|
|
908
|
-
if (this.
|
|
733
|
+
if (this.recordingMode === 'error') {
|
|
909
734
|
return;
|
|
910
735
|
}
|
|
911
736
|
|
|
@@ -960,12 +785,12 @@ class ReplayContainer {
|
|
|
960
785
|
|
|
961
786
|
await this.addPerformanceEntries();
|
|
962
787
|
|
|
963
|
-
if (!_optionalChain([this, 'access',
|
|
788
|
+
if (!_optionalChain([this, 'access', _32 => _32.eventBuffer, 'optionalAccess', _33 => _33.length])) {
|
|
964
789
|
return;
|
|
965
790
|
}
|
|
966
791
|
|
|
967
792
|
// Only attach memory event if eventBuffer is not empty
|
|
968
|
-
await
|
|
793
|
+
await addMemoryEntry(this);
|
|
969
794
|
|
|
970
795
|
try {
|
|
971
796
|
// Note this empties the event buffer regardless of outcome of sending replay
|
|
@@ -987,8 +812,7 @@ class ReplayContainer {
|
|
|
987
812
|
eventContext,
|
|
988
813
|
});
|
|
989
814
|
} catch (err) {
|
|
990
|
-
|
|
991
|
-
captureInternalException(err);
|
|
815
|
+
this.handleException(err);
|
|
992
816
|
}
|
|
993
817
|
}
|
|
994
818
|
|
|
@@ -996,7 +820,7 @@ class ReplayContainer {
|
|
|
996
820
|
* Flush recording data to Sentry. Creates a lock so that only a single flush
|
|
997
821
|
* can be active at a time. Do not call this directly.
|
|
998
822
|
*/
|
|
999
|
-
|
|
823
|
+
__init19() {this.flush = async () => {
|
|
1000
824
|
if (!this._isEnabled) {
|
|
1001
825
|
// This is just a precaution, there should be no listeners that would
|
|
1002
826
|
// cause a flush.
|
|
@@ -1008,13 +832,13 @@ class ReplayContainer {
|
|
|
1008
832
|
return;
|
|
1009
833
|
}
|
|
1010
834
|
|
|
1011
|
-
if (!_optionalChain([this, 'access',
|
|
835
|
+
if (!_optionalChain([this, 'access', _34 => _34.session, 'optionalAccess', _35 => _35.id])) {
|
|
1012
836
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] No session found to flush.');
|
|
1013
837
|
return;
|
|
1014
838
|
}
|
|
1015
839
|
|
|
1016
840
|
// A flush is about to happen, cancel any queued flushes
|
|
1017
|
-
_optionalChain([this, 'access',
|
|
841
|
+
_optionalChain([this, 'access', _36 => _36._debouncedFlush, 'optionalAccess', _37 => _37.cancel, 'call', _38 => _38()]);
|
|
1018
842
|
|
|
1019
843
|
// No existing flush in progress, proceed with flushing.
|
|
1020
844
|
// this._flushLock acts as a lock so that future calls to `flush()`
|
|
@@ -1058,7 +882,7 @@ class ReplayContainer {
|
|
|
1058
882
|
*/
|
|
1059
883
|
async sendReplayRequest({
|
|
1060
884
|
events,
|
|
1061
|
-
replayId
|
|
885
|
+
replayId,
|
|
1062
886
|
segmentId: segment_id,
|
|
1063
887
|
includeReplayStartTimestamp,
|
|
1064
888
|
eventContext,
|
|
@@ -1074,78 +898,77 @@ class ReplayContainer {
|
|
|
1074
898
|
|
|
1075
899
|
const currentTimestamp = new Date().getTime();
|
|
1076
900
|
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
901
|
+
const hub = getCurrentHub();
|
|
902
|
+
const client = hub.getClient();
|
|
903
|
+
const scope = hub.getScope();
|
|
904
|
+
const transport = client && client.getTransport();
|
|
1081
905
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
, 'optionalAccess', _65 => _65._withClient, 'call', _66 => _66(async (client, scope) => {
|
|
1086
|
-
// XXX: This event does not trigger `beforeSend` in SDK
|
|
1087
|
-
// @ts-ignore private api
|
|
1088
|
-
const preparedEvent = await client._prepareEvent(
|
|
1089
|
-
{
|
|
1090
|
-
type: REPLAY_EVENT_NAME,
|
|
1091
|
-
...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
|
|
1092
|
-
timestamp: currentTimestamp / 1000,
|
|
1093
|
-
error_ids: errorIds,
|
|
1094
|
-
trace_ids: traceIds,
|
|
1095
|
-
urls,
|
|
1096
|
-
replay_id: event_id,
|
|
1097
|
-
segment_id,
|
|
1098
|
-
},
|
|
1099
|
-
{ event_id },
|
|
1100
|
-
scope,
|
|
1101
|
-
);
|
|
1102
|
-
const session = scope && scope.getSession();
|
|
1103
|
-
if (session) {
|
|
1104
|
-
// @ts-ignore private api
|
|
1105
|
-
client._updateSessionFromEvent(session, preparedEvent);
|
|
1106
|
-
}
|
|
906
|
+
if (!client || !scope || !transport) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
1107
909
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
910
|
+
const baseEvent = {
|
|
911
|
+
// @ts-ignore private api
|
|
912
|
+
type: REPLAY_EVENT_NAME,
|
|
913
|
+
...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
|
|
914
|
+
timestamp: currentTimestamp / 1000,
|
|
915
|
+
error_ids: errorIds,
|
|
916
|
+
trace_ids: traceIds,
|
|
917
|
+
urls,
|
|
918
|
+
replay_id: replayId,
|
|
919
|
+
segment_id,
|
|
920
|
+
};
|
|
1112
921
|
|
|
1113
|
-
|
|
1114
|
-
...preparedEvent.tags,
|
|
1115
|
-
sessionSampleRate: this.options.sessionSampleRate,
|
|
1116
|
-
errorSampleRate: this.options.errorSampleRate,
|
|
1117
|
-
replayType: _optionalChain([this, 'access', _67 => _67.session, 'optionalAccess', _68 => _68.sampled]),
|
|
1118
|
-
};
|
|
922
|
+
const replayEvent = await getReplayEvent({ scope, client, replayId, event: baseEvent });
|
|
1119
923
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
924
|
+
replayEvent.tags = {
|
|
925
|
+
...replayEvent.tags,
|
|
926
|
+
sessionSampleRate: this._options.sessionSampleRate,
|
|
927
|
+
errorSampleRate: this._options.errorSampleRate,
|
|
928
|
+
replayType: _optionalChain([this, 'access', _39 => _39.session, 'optionalAccess', _40 => _40.sampled]),
|
|
929
|
+
};
|
|
1123
930
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
{
|
|
1135
|
-
// @ts-ignore setting envelope
|
|
1136
|
-
type: 'replay_recording',
|
|
1137
|
-
length: payloadWithSequence.length,
|
|
1138
|
-
},
|
|
1139
|
-
// @ts-ignore: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
|
|
1140
|
-
payloadWithSequence,
|
|
931
|
+
/*
|
|
932
|
+
For reference, the fully built event looks something like this:
|
|
933
|
+
{
|
|
934
|
+
"type": "replay_event",
|
|
935
|
+
"timestamp": 1670837008.634,
|
|
936
|
+
"error_ids": [
|
|
937
|
+
"errorId"
|
|
938
|
+
],
|
|
939
|
+
"trace_ids": [
|
|
940
|
+
"traceId"
|
|
1141
941
|
],
|
|
1142
|
-
|
|
1143
|
-
|
|
942
|
+
"urls": [
|
|
943
|
+
"https://example.com"
|
|
944
|
+
],
|
|
945
|
+
"replay_id": "eventId",
|
|
946
|
+
"segment_id": 3,
|
|
947
|
+
"platform": "javascript",
|
|
948
|
+
"event_id": "eventId",
|
|
949
|
+
"environment": "production",
|
|
950
|
+
"sdk": {
|
|
951
|
+
"integrations": [
|
|
952
|
+
"BrowserTracing",
|
|
953
|
+
"Replay"
|
|
954
|
+
],
|
|
955
|
+
"name": "sentry.javascript.integration.replay",
|
|
956
|
+
"version": "7.24.2"
|
|
957
|
+
},
|
|
958
|
+
"sdkProcessingMetadata": {},
|
|
959
|
+
"tags": {
|
|
960
|
+
"sessionSampleRate": 1,
|
|
961
|
+
"errorSampleRate": 0,
|
|
962
|
+
"replayType": "error"
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
*/
|
|
966
|
+
|
|
967
|
+
const envelope = createReplayEnvelope(replayId, replayEvent, payloadWithSequence);
|
|
1144
968
|
|
|
1145
|
-
const client = getCurrentHub().getClient();
|
|
1146
969
|
try {
|
|
1147
|
-
return
|
|
1148
|
-
} catch (
|
|
970
|
+
return transport.send(envelope);
|
|
971
|
+
} catch (e) {
|
|
1149
972
|
throw new Error(UNABLE_TO_SEND_REPLAY);
|
|
1150
973
|
}
|
|
1151
974
|
}
|
|
@@ -1181,12 +1004,11 @@ class ReplayContainer {
|
|
|
1181
1004
|
this.resetRetries();
|
|
1182
1005
|
return true;
|
|
1183
1006
|
} catch (err) {
|
|
1184
|
-
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
|
|
1185
1007
|
// Capture error for every failed replay
|
|
1186
1008
|
setContext('Replays', {
|
|
1187
1009
|
_retryCount: this._retryCount,
|
|
1188
1010
|
});
|
|
1189
|
-
|
|
1011
|
+
this.handleException(err);
|
|
1190
1012
|
|
|
1191
1013
|
// If an error happened here, it's likely that uploading the attachment
|
|
1192
1014
|
// failed, we'll can retry with the same events payload
|
|
@@ -1219,45 +1041,10 @@ class ReplayContainer {
|
|
|
1219
1041
|
|
|
1220
1042
|
/** Save the session, if it is sticky */
|
|
1221
1043
|
_maybeSaveSession() {
|
|
1222
|
-
if (this.session && this.
|
|
1044
|
+
if (this.session && this._options.stickySession) {
|
|
1223
1045
|
saveSession(this.session);
|
|
1224
1046
|
}
|
|
1225
1047
|
}
|
|
1226
|
-
|
|
1227
|
-
_overwriteRecordDroppedEvent() {
|
|
1228
|
-
const client = getCurrentHub().getClient();
|
|
1229
|
-
|
|
1230
|
-
if (!client) {
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
const _originalCallback = client.recordDroppedEvent.bind(client);
|
|
1235
|
-
|
|
1236
|
-
const recordDroppedEvent = (
|
|
1237
|
-
reason,
|
|
1238
|
-
category,
|
|
1239
|
-
event,
|
|
1240
|
-
) => {
|
|
1241
|
-
if (event && event.event_id) {
|
|
1242
|
-
this._context.errorIds.delete(event.event_id);
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
return _originalCallback(reason, category, event);
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
client.recordDroppedEvent = recordDroppedEvent;
|
|
1249
|
-
this._originalRecordDroppedEvent = _originalCallback;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
_restoreRecordDroppedEvent() {
|
|
1253
|
-
const client = getCurrentHub().getClient();
|
|
1254
|
-
|
|
1255
|
-
if (!client || !this._originalRecordDroppedEvent) {
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
client.recordDroppedEvent = this._originalRecordDroppedEvent;
|
|
1260
|
-
}
|
|
1261
1048
|
}
|
|
1262
1049
|
|
|
1263
1050
|
export { ReplayContainer };
|