@sentry/replay 7.49.0 → 7.50.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 +19 -6
- package/cjs/index.js +448 -162
- package/cjs/index.js.map +1 -1
- package/esm/index.js +449 -163
- package/esm/index.js.map +1 -1
- package/package.json +5 -5
- package/types/constants.d.ts +4 -2
- package/types/constants.d.ts.map +1 -1
- package/types/coreHandlers/handleAfterSendEvent.d.ts.map +1 -1
- package/types/coreHandlers/handleNetworkBreadcrumbs.d.ts.map +1 -1
- package/types/coreHandlers/handleScope.d.ts +2 -0
- package/types/coreHandlers/handleScope.d.ts.map +1 -1
- package/types/coreHandlers/util/fetchUtils.d.ts.map +1 -1
- package/types/coreHandlers/util/networkUtils.d.ts +4 -0
- package/types/coreHandlers/util/networkUtils.d.ts.map +1 -1
- package/types/coreHandlers/util/xhrUtils.d.ts.map +1 -1
- package/types/integration.d.ts +21 -14
- package/types/integration.d.ts.map +1 -1
- package/types/replay.d.ts +33 -12
- package/types/replay.d.ts.map +1 -1
- package/types/session/Session.d.ts +0 -4
- package/types/session/Session.d.ts.map +1 -1
- package/types/session/clearSession.d.ts +6 -0
- package/types/session/clearSession.d.ts.map +1 -0
- package/types/session/createSession.d.ts +6 -2
- package/types/session/createSession.d.ts.map +1 -1
- package/types/session/getSession.d.ts +1 -1
- package/types/session/getSession.d.ts.map +1 -1
- package/types/types.d.ts +56 -36
- package/types/types.d.ts.map +1 -1
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCurrentHub, addBreadcrumb, addGlobalEventProcessor, prepareEvent, setContext, captureException } from '@sentry/core';
|
|
2
|
-
import { GLOBAL_OBJ, logger, uuid4, normalize, htmlTreeAsString, SENTRY_XHR_DATA_KEY, dropUndefinedKeys, addInstrumentationHandler, browserPerformanceTimeOrigin, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, isNodeEnv } from '@sentry/utils';
|
|
2
|
+
import { GLOBAL_OBJ, logger, uuid4, normalize, htmlTreeAsString, SENTRY_XHR_DATA_KEY, dropUndefinedKeys, stringMatchesSomePattern, addInstrumentationHandler, browserPerformanceTimeOrigin, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, isNodeEnv } from '@sentry/utils';
|
|
3
3
|
|
|
4
4
|
// exporting a separate copy of `WINDOW` rather than exporting the one from `@sentry/browser`
|
|
5
5
|
// prevents the browser package from being bundled in the CDN bundle, and avoids a
|
|
@@ -11,11 +11,14 @@ const REPLAY_SESSION_KEY = 'sentryReplaySession';
|
|
|
11
11
|
const REPLAY_EVENT_NAME = 'replay_event';
|
|
12
12
|
const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay';
|
|
13
13
|
|
|
14
|
-
// The idle limit for a session
|
|
15
|
-
const
|
|
14
|
+
// The idle limit for a session after which recording is paused.
|
|
15
|
+
const SESSION_IDLE_PAUSE_DURATION = 300000; // 5 minutes in ms
|
|
16
|
+
|
|
17
|
+
// The idle limit for a session after which the session expires.
|
|
18
|
+
const SESSION_IDLE_EXPIRE_DURATION = 900000; // 15 minutes in ms
|
|
16
19
|
|
|
17
20
|
// The maximum length of a session
|
|
18
|
-
const MAX_SESSION_LIFE = 3600000; // 60 minutes
|
|
21
|
+
const MAX_SESSION_LIFE = 3600000; // 60 minutes in ms
|
|
19
22
|
|
|
20
23
|
/** Default flush delays */
|
|
21
24
|
const DEFAULT_FLUSH_MIN_DELAY = 5000;
|
|
@@ -24,7 +27,7 @@ const DEFAULT_FLUSH_MIN_DELAY = 5000;
|
|
|
24
27
|
const DEFAULT_FLUSH_MAX_DELAY = 5500;
|
|
25
28
|
|
|
26
29
|
/* How long to wait for error checkouts */
|
|
27
|
-
const
|
|
30
|
+
const BUFFER_CHECKOUT_TIME = 60000;
|
|
28
31
|
|
|
29
32
|
const RETRY_BASE_INTERVAL = 5000;
|
|
30
33
|
const RETRY_MAX_COUNT = 3;
|
|
@@ -32,6 +35,9 @@ const RETRY_MAX_COUNT = 3;
|
|
|
32
35
|
/* The max (uncompressed) size in bytes of a network body. Any body larger than this will be truncated. */
|
|
33
36
|
const NETWORK_BODY_MAX_SIZE = 150000;
|
|
34
37
|
|
|
38
|
+
/* The max size of a single console arg that is captured. Any arg larger than this will be truncated. */
|
|
39
|
+
const CONSOLE_ARG_MAX_SIZE = 5000;
|
|
40
|
+
|
|
35
41
|
var NodeType$1;
|
|
36
42
|
(function (NodeType) {
|
|
37
43
|
NodeType[NodeType["Document"] = 0] = "Document";
|
|
@@ -3696,6 +3702,31 @@ function createEventBuffer({ useCompression }) {
|
|
|
3696
3702
|
return new EventBufferArray();
|
|
3697
3703
|
}
|
|
3698
3704
|
|
|
3705
|
+
/**
|
|
3706
|
+
* Removes the session from Session Storage and unsets session in replay instance
|
|
3707
|
+
*/
|
|
3708
|
+
function clearSession(replay) {
|
|
3709
|
+
deleteSession();
|
|
3710
|
+
replay.session = undefined;
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
/**
|
|
3714
|
+
* Deletes a session from storage
|
|
3715
|
+
*/
|
|
3716
|
+
function deleteSession() {
|
|
3717
|
+
const hasSessionStorage = 'sessionStorage' in WINDOW;
|
|
3718
|
+
|
|
3719
|
+
if (!hasSessionStorage) {
|
|
3720
|
+
return;
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
try {
|
|
3724
|
+
WINDOW.sessionStorage.removeItem(REPLAY_SESSION_KEY);
|
|
3725
|
+
} catch (e) {
|
|
3726
|
+
// Ignore potential SecurityError exceptions
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3699
3730
|
/**
|
|
3700
3731
|
* Given an initial timestamp and an expiry duration, checks to see if current
|
|
3701
3732
|
* time should be considered as expired.
|
|
@@ -3726,11 +3757,26 @@ function isSessionExpired(session, timeouts, targetTime = +new Date()) {
|
|
|
3726
3757
|
// First, check that maximum session length has not been exceeded
|
|
3727
3758
|
isExpired(session.started, timeouts.maxSessionLife, targetTime) ||
|
|
3728
3759
|
// check that the idle timeout has not been exceeded (i.e. user has
|
|
3729
|
-
// performed an action within the last `
|
|
3730
|
-
isExpired(session.lastActivity, timeouts.
|
|
3760
|
+
// performed an action within the last `sessionIdleExpire` ms)
|
|
3761
|
+
isExpired(session.lastActivity, timeouts.sessionIdleExpire, targetTime)
|
|
3731
3762
|
);
|
|
3732
3763
|
}
|
|
3733
3764
|
|
|
3765
|
+
/**
|
|
3766
|
+
* Given a sample rate, returns true if replay should be sampled.
|
|
3767
|
+
*
|
|
3768
|
+
* 1.0 = 100% sampling
|
|
3769
|
+
* 0.0 = 0% sampling
|
|
3770
|
+
*/
|
|
3771
|
+
function isSampled(sampleRate) {
|
|
3772
|
+
if (sampleRate === undefined) {
|
|
3773
|
+
return false;
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
// Math.random() returns a number in range of 0 to 1 (inclusive of 0, but not 1)
|
|
3777
|
+
return Math.random() < sampleRate;
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3734
3780
|
/**
|
|
3735
3781
|
* Save a session to session storage.
|
|
3736
3782
|
*/
|
|
@@ -3747,21 +3793,6 @@ function saveSession(session) {
|
|
|
3747
3793
|
}
|
|
3748
3794
|
}
|
|
3749
3795
|
|
|
3750
|
-
/**
|
|
3751
|
-
* Given a sample rate, returns true if replay should be sampled.
|
|
3752
|
-
*
|
|
3753
|
-
* 1.0 = 100% sampling
|
|
3754
|
-
* 0.0 = 0% sampling
|
|
3755
|
-
*/
|
|
3756
|
-
function isSampled(sampleRate) {
|
|
3757
|
-
if (sampleRate === undefined) {
|
|
3758
|
-
return false;
|
|
3759
|
-
}
|
|
3760
|
-
|
|
3761
|
-
// Math.random() returns a number in range of 0 to 1 (inclusive of 0, but not 1)
|
|
3762
|
-
return Math.random() < sampleRate;
|
|
3763
|
-
}
|
|
3764
|
-
|
|
3765
3796
|
/**
|
|
3766
3797
|
* Get a session with defaults & applied sampling.
|
|
3767
3798
|
*/
|
|
@@ -3780,14 +3811,15 @@ function makeSession(session) {
|
|
|
3780
3811
|
lastActivity,
|
|
3781
3812
|
segmentId,
|
|
3782
3813
|
sampled,
|
|
3814
|
+
shouldRefresh: true,
|
|
3783
3815
|
};
|
|
3784
3816
|
}
|
|
3785
3817
|
|
|
3786
3818
|
/**
|
|
3787
3819
|
* Get the sampled status for a session based on sample rates & current sampled status.
|
|
3788
3820
|
*/
|
|
3789
|
-
function getSessionSampleType(sessionSampleRate,
|
|
3790
|
-
return isSampled(sessionSampleRate) ? 'session' :
|
|
3821
|
+
function getSessionSampleType(sessionSampleRate, allowBuffering) {
|
|
3822
|
+
return isSampled(sessionSampleRate) ? 'session' : allowBuffering ? 'buffer' : false;
|
|
3791
3823
|
}
|
|
3792
3824
|
|
|
3793
3825
|
/**
|
|
@@ -3795,8 +3827,8 @@ function getSessionSampleType(sessionSampleRate, errorSampleRate) {
|
|
|
3795
3827
|
* that all replays will be saved to as attachments. Currently, we only expect
|
|
3796
3828
|
* one of these Sentry events per "replay session".
|
|
3797
3829
|
*/
|
|
3798
|
-
function createSession({ sessionSampleRate,
|
|
3799
|
-
const sampled = getSessionSampleType(sessionSampleRate,
|
|
3830
|
+
function createSession({ sessionSampleRate, allowBuffering, stickySession = false }) {
|
|
3831
|
+
const sampled = getSessionSampleType(sessionSampleRate, allowBuffering);
|
|
3800
3832
|
const session = makeSession({
|
|
3801
3833
|
sampled,
|
|
3802
3834
|
});
|
|
@@ -3844,7 +3876,7 @@ function getSession({
|
|
|
3844
3876
|
currentSession,
|
|
3845
3877
|
stickySession,
|
|
3846
3878
|
sessionSampleRate,
|
|
3847
|
-
|
|
3879
|
+
allowBuffering,
|
|
3848
3880
|
}) {
|
|
3849
3881
|
// If session exists and is passed, use it instead of always hitting session storage
|
|
3850
3882
|
const session = currentSession || (stickySession && fetchSession());
|
|
@@ -3857,8 +3889,9 @@ function getSession({
|
|
|
3857
3889
|
|
|
3858
3890
|
if (!isExpired) {
|
|
3859
3891
|
return { type: 'saved', session };
|
|
3860
|
-
} else if (session.
|
|
3861
|
-
//
|
|
3892
|
+
} else if (!session.shouldRefresh) {
|
|
3893
|
+
// In this case, stop
|
|
3894
|
+
// This is the case if we have an error session that is completed (=triggered an error)
|
|
3862
3895
|
const discardedSession = makeSession({ sampled: false });
|
|
3863
3896
|
return { type: 'new', session: discardedSession };
|
|
3864
3897
|
} else {
|
|
@@ -3870,7 +3903,7 @@ function getSession({
|
|
|
3870
3903
|
const newSession = createSession({
|
|
3871
3904
|
stickySession,
|
|
3872
3905
|
sessionSampleRate,
|
|
3873
|
-
|
|
3906
|
+
allowBuffering,
|
|
3874
3907
|
});
|
|
3875
3908
|
|
|
3876
3909
|
return { type: 'new', session: newSession };
|
|
@@ -3904,7 +3937,7 @@ async function addEvent(
|
|
|
3904
3937
|
// page has been left open and idle for a long period of time and user
|
|
3905
3938
|
// comes back to trigger a new session. The performance entries rely on
|
|
3906
3939
|
// `performance.timeOrigin`, which is when the page first opened.
|
|
3907
|
-
if (timestampInMs + replay.timeouts.
|
|
3940
|
+
if (timestampInMs + replay.timeouts.sessionIdlePause < Date.now()) {
|
|
3908
3941
|
return null;
|
|
3909
3942
|
}
|
|
3910
3943
|
|
|
@@ -3919,7 +3952,7 @@ async function addEvent(
|
|
|
3919
3952
|
return await replay.eventBuffer.addEvent(event, isCheckout);
|
|
3920
3953
|
} catch (error) {
|
|
3921
3954
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(error);
|
|
3922
|
-
replay.stop('addEvent');
|
|
3955
|
+
await replay.stop('addEvent');
|
|
3923
3956
|
|
|
3924
3957
|
const client = getCurrentHub().getClient();
|
|
3925
3958
|
|
|
@@ -3986,23 +4019,17 @@ function handleAfterSendEvent(replay) {
|
|
|
3986
4019
|
// Trigger error recording
|
|
3987
4020
|
// Need to be very careful that this does not cause an infinite loop
|
|
3988
4021
|
if (
|
|
3989
|
-
replay.recordingMode === '
|
|
4022
|
+
replay.recordingMode === 'buffer' &&
|
|
3990
4023
|
event.exception &&
|
|
3991
4024
|
event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
|
|
3992
4025
|
) {
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
if (replay.stopRecording()) {
|
|
4001
|
-
// Reset all "capture on error" configuration before
|
|
4002
|
-
// starting a new recording
|
|
4003
|
-
replay.recordingMode = 'session';
|
|
4004
|
-
replay.startRecording();
|
|
4005
|
-
}
|
|
4026
|
+
if (!isSampled(replay.getOptions().errorSampleRate)) {
|
|
4027
|
+
return;
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
setTimeout(() => {
|
|
4031
|
+
// Capture current event buffer as new replay
|
|
4032
|
+
void replay.sendBufferedReplayOrFlush();
|
|
4006
4033
|
});
|
|
4007
4034
|
}
|
|
4008
4035
|
};
|
|
@@ -4957,6 +4984,17 @@ function makeNetworkReplayBreadcrumb(
|
|
|
4957
4984
|
return result;
|
|
4958
4985
|
}
|
|
4959
4986
|
|
|
4987
|
+
/** Build the request or response part of a replay network breadcrumb that was skipped. */
|
|
4988
|
+
function buildSkippedNetworkRequestOrResponse(bodySize) {
|
|
4989
|
+
return {
|
|
4990
|
+
headers: {},
|
|
4991
|
+
size: bodySize,
|
|
4992
|
+
_meta: {
|
|
4993
|
+
warnings: ['URL_SKIPPED'],
|
|
4994
|
+
},
|
|
4995
|
+
};
|
|
4996
|
+
}
|
|
4997
|
+
|
|
4960
4998
|
/** Build the request or response part of a replay network breadcrumb. */
|
|
4961
4999
|
function buildNetworkRequestOrResponse(
|
|
4962
5000
|
headers,
|
|
@@ -5037,8 +5075,8 @@ function normalizeNetworkBody(body)
|
|
|
5037
5075
|
};
|
|
5038
5076
|
} catch (e3) {
|
|
5039
5077
|
return {
|
|
5040
|
-
body,
|
|
5041
|
-
warnings: ['INVALID_JSON'],
|
|
5078
|
+
body: exceedsSizeLimit ? `${body.slice(0, NETWORK_BODY_MAX_SIZE)}…` : body,
|
|
5079
|
+
warnings: exceedsSizeLimit ? ['INVALID_JSON', 'TEXT_TRUNCATED'] : ['INVALID_JSON'],
|
|
5042
5080
|
};
|
|
5043
5081
|
}
|
|
5044
5082
|
}
|
|
@@ -5057,6 +5095,11 @@ function _strIsProbablyJson(str) {
|
|
|
5057
5095
|
return (first === '[' && last === ']') || (first === '{' && last === '}');
|
|
5058
5096
|
}
|
|
5059
5097
|
|
|
5098
|
+
/** Match an URL against a list of strings/Regex. */
|
|
5099
|
+
function urlMatches(url, urls) {
|
|
5100
|
+
return stringMatchesSomePattern(url, urls);
|
|
5101
|
+
}
|
|
5102
|
+
|
|
5060
5103
|
/**
|
|
5061
5104
|
* Capture a fetch breadcrumb to a replay.
|
|
5062
5105
|
* This adds additional data (where approriate).
|
|
@@ -5116,33 +5159,37 @@ async function _prepareFetchData(
|
|
|
5116
5159
|
const {
|
|
5117
5160
|
url,
|
|
5118
5161
|
method,
|
|
5119
|
-
status_code: statusCode,
|
|
5162
|
+
status_code: statusCode = 0,
|
|
5120
5163
|
request_body_size: requestBodySize,
|
|
5121
5164
|
response_body_size: responseBodySize,
|
|
5122
5165
|
} = breadcrumb.data;
|
|
5123
5166
|
|
|
5124
|
-
const
|
|
5125
|
-
|
|
5167
|
+
const captureDetails = urlMatches(url, options.networkDetailAllowUrls);
|
|
5168
|
+
|
|
5169
|
+
const request = captureDetails
|
|
5170
|
+
? _getRequestInfo(options, hint.input, requestBodySize)
|
|
5171
|
+
: buildSkippedNetworkRequestOrResponse(requestBodySize);
|
|
5172
|
+
const response = await _getResponseInfo(captureDetails, options, hint.response, responseBodySize);
|
|
5126
5173
|
|
|
5127
5174
|
return {
|
|
5128
5175
|
startTimestamp,
|
|
5129
5176
|
endTimestamp,
|
|
5130
5177
|
url,
|
|
5131
5178
|
method,
|
|
5132
|
-
statusCode
|
|
5179
|
+
statusCode,
|
|
5133
5180
|
request,
|
|
5134
5181
|
response,
|
|
5135
5182
|
};
|
|
5136
5183
|
}
|
|
5137
5184
|
|
|
5138
5185
|
function _getRequestInfo(
|
|
5139
|
-
{
|
|
5186
|
+
{ networkCaptureBodies, networkRequestHeaders },
|
|
5140
5187
|
input,
|
|
5141
5188
|
requestBodySize,
|
|
5142
5189
|
) {
|
|
5143
|
-
const headers = getRequestHeaders(input,
|
|
5190
|
+
const headers = getRequestHeaders(input, networkRequestHeaders);
|
|
5144
5191
|
|
|
5145
|
-
if (!
|
|
5192
|
+
if (!networkCaptureBodies) {
|
|
5146
5193
|
return buildNetworkRequestOrResponse(headers, requestBodySize, undefined);
|
|
5147
5194
|
}
|
|
5148
5195
|
|
|
@@ -5153,19 +5200,24 @@ function _getRequestInfo(
|
|
|
5153
5200
|
}
|
|
5154
5201
|
|
|
5155
5202
|
async function _getResponseInfo(
|
|
5203
|
+
captureDetails,
|
|
5156
5204
|
{
|
|
5157
|
-
|
|
5205
|
+
networkCaptureBodies,
|
|
5158
5206
|
textEncoder,
|
|
5159
|
-
|
|
5207
|
+
networkResponseHeaders,
|
|
5160
5208
|
}
|
|
5161
5209
|
|
|
5162
5210
|
,
|
|
5163
5211
|
response,
|
|
5164
5212
|
responseBodySize,
|
|
5165
5213
|
) {
|
|
5166
|
-
|
|
5214
|
+
if (!captureDetails && responseBodySize !== undefined) {
|
|
5215
|
+
return buildSkippedNetworkRequestOrResponse(responseBodySize);
|
|
5216
|
+
}
|
|
5217
|
+
|
|
5218
|
+
const headers = getAllHeaders(response.headers, networkResponseHeaders);
|
|
5167
5219
|
|
|
5168
|
-
if (!
|
|
5220
|
+
if (!networkCaptureBodies && responseBodySize !== undefined) {
|
|
5169
5221
|
return buildNetworkRequestOrResponse(headers, responseBodySize, undefined);
|
|
5170
5222
|
}
|
|
5171
5223
|
|
|
@@ -5180,7 +5232,11 @@ async function _getResponseInfo(
|
|
|
5180
5232
|
? getBodySize(bodyText, textEncoder)
|
|
5181
5233
|
: responseBodySize;
|
|
5182
5234
|
|
|
5183
|
-
if (
|
|
5235
|
+
if (!captureDetails) {
|
|
5236
|
+
return buildSkippedNetworkRequestOrResponse(size);
|
|
5237
|
+
}
|
|
5238
|
+
|
|
5239
|
+
if (networkCaptureBodies) {
|
|
5184
5240
|
return buildNetworkRequestOrResponse(headers, size, bodyText);
|
|
5185
5241
|
}
|
|
5186
5242
|
|
|
@@ -5313,28 +5369,44 @@ function _prepareXhrData(
|
|
|
5313
5369
|
const {
|
|
5314
5370
|
url,
|
|
5315
5371
|
method,
|
|
5316
|
-
status_code: statusCode,
|
|
5372
|
+
status_code: statusCode = 0,
|
|
5317
5373
|
request_body_size: requestBodySize,
|
|
5318
5374
|
response_body_size: responseBodySize,
|
|
5319
5375
|
} = breadcrumb.data;
|
|
5320
5376
|
|
|
5321
|
-
const xhrInfo = xhr[SENTRY_XHR_DATA_KEY];
|
|
5322
|
-
const requestHeaders = xhrInfo ? getAllowedHeaders(xhrInfo.request_headers, options.requestHeaders) : {};
|
|
5323
|
-
const responseHeaders = getAllowedHeaders(getResponseHeaders(xhr), options.responseHeaders);
|
|
5324
|
-
|
|
5325
5377
|
if (!url) {
|
|
5326
5378
|
return null;
|
|
5327
5379
|
}
|
|
5328
5380
|
|
|
5381
|
+
if (!urlMatches(url, options.networkDetailAllowUrls)) {
|
|
5382
|
+
const request = buildSkippedNetworkRequestOrResponse(requestBodySize);
|
|
5383
|
+
const response = buildSkippedNetworkRequestOrResponse(responseBodySize);
|
|
5384
|
+
return {
|
|
5385
|
+
startTimestamp,
|
|
5386
|
+
endTimestamp,
|
|
5387
|
+
url,
|
|
5388
|
+
method,
|
|
5389
|
+
statusCode,
|
|
5390
|
+
request,
|
|
5391
|
+
response,
|
|
5392
|
+
};
|
|
5393
|
+
}
|
|
5394
|
+
|
|
5395
|
+
const xhrInfo = xhr[SENTRY_XHR_DATA_KEY];
|
|
5396
|
+
const networkRequestHeaders = xhrInfo
|
|
5397
|
+
? getAllowedHeaders(xhrInfo.request_headers, options.networkRequestHeaders)
|
|
5398
|
+
: {};
|
|
5399
|
+
const networkResponseHeaders = getAllowedHeaders(getResponseHeaders(xhr), options.networkResponseHeaders);
|
|
5400
|
+
|
|
5329
5401
|
const request = buildNetworkRequestOrResponse(
|
|
5330
|
-
|
|
5402
|
+
networkRequestHeaders,
|
|
5331
5403
|
requestBodySize,
|
|
5332
|
-
options.
|
|
5404
|
+
options.networkCaptureBodies ? getBodyString(input) : undefined,
|
|
5333
5405
|
);
|
|
5334
5406
|
const response = buildNetworkRequestOrResponse(
|
|
5335
|
-
|
|
5407
|
+
networkResponseHeaders,
|
|
5336
5408
|
responseBodySize,
|
|
5337
|
-
options.
|
|
5409
|
+
options.networkCaptureBodies ? hint.xhr.responseText : undefined,
|
|
5338
5410
|
);
|
|
5339
5411
|
|
|
5340
5412
|
return {
|
|
@@ -5342,7 +5414,7 @@ function _prepareXhrData(
|
|
|
5342
5414
|
endTimestamp,
|
|
5343
5415
|
url,
|
|
5344
5416
|
method,
|
|
5345
|
-
statusCode
|
|
5417
|
+
statusCode,
|
|
5346
5418
|
request,
|
|
5347
5419
|
response,
|
|
5348
5420
|
};
|
|
@@ -5374,10 +5446,16 @@ function handleNetworkBreadcrumbs(replay) {
|
|
|
5374
5446
|
try {
|
|
5375
5447
|
const textEncoder = new TextEncoder();
|
|
5376
5448
|
|
|
5449
|
+
const { networkDetailAllowUrls, networkCaptureBodies, networkRequestHeaders, networkResponseHeaders } =
|
|
5450
|
+
replay.getOptions();
|
|
5451
|
+
|
|
5377
5452
|
const options = {
|
|
5378
5453
|
replay,
|
|
5379
5454
|
textEncoder,
|
|
5380
|
-
|
|
5455
|
+
networkDetailAllowUrls,
|
|
5456
|
+
networkCaptureBodies,
|
|
5457
|
+
networkRequestHeaders,
|
|
5458
|
+
networkResponseHeaders,
|
|
5381
5459
|
};
|
|
5382
5460
|
|
|
5383
5461
|
if (client && client.on) {
|
|
@@ -5485,9 +5563,66 @@ function handleScope(scope) {
|
|
|
5485
5563
|
return null;
|
|
5486
5564
|
}
|
|
5487
5565
|
|
|
5566
|
+
if (newBreadcrumb.category === 'console') {
|
|
5567
|
+
return normalizeConsoleBreadcrumb(newBreadcrumb);
|
|
5568
|
+
}
|
|
5569
|
+
|
|
5488
5570
|
return createBreadcrumb(newBreadcrumb);
|
|
5489
5571
|
}
|
|
5490
5572
|
|
|
5573
|
+
/** exported for tests only */
|
|
5574
|
+
function normalizeConsoleBreadcrumb(breadcrumb) {
|
|
5575
|
+
const args = breadcrumb.data && breadcrumb.data.arguments;
|
|
5576
|
+
|
|
5577
|
+
if (!Array.isArray(args) || args.length === 0) {
|
|
5578
|
+
return createBreadcrumb(breadcrumb);
|
|
5579
|
+
}
|
|
5580
|
+
|
|
5581
|
+
let isTruncated = false;
|
|
5582
|
+
|
|
5583
|
+
// Avoid giant args captures
|
|
5584
|
+
const normalizedArgs = args.map(arg => {
|
|
5585
|
+
if (!arg) {
|
|
5586
|
+
return arg;
|
|
5587
|
+
}
|
|
5588
|
+
if (typeof arg === 'string') {
|
|
5589
|
+
if (arg.length > CONSOLE_ARG_MAX_SIZE) {
|
|
5590
|
+
isTruncated = true;
|
|
5591
|
+
return `${arg.slice(0, CONSOLE_ARG_MAX_SIZE)}…`;
|
|
5592
|
+
}
|
|
5593
|
+
|
|
5594
|
+
return arg;
|
|
5595
|
+
}
|
|
5596
|
+
if (typeof arg === 'object') {
|
|
5597
|
+
try {
|
|
5598
|
+
const normalizedArg = normalize(arg, 7);
|
|
5599
|
+
const stringified = JSON.stringify(normalizedArg);
|
|
5600
|
+
if (stringified.length > CONSOLE_ARG_MAX_SIZE) {
|
|
5601
|
+
const fixedJson = fixJson(stringified.slice(0, CONSOLE_ARG_MAX_SIZE));
|
|
5602
|
+
const json = JSON.parse(fixedJson);
|
|
5603
|
+
// We only set this after JSON.parse() was successfull, so we know we didn't run into `catch`
|
|
5604
|
+
isTruncated = true;
|
|
5605
|
+
return json;
|
|
5606
|
+
}
|
|
5607
|
+
return normalizedArg;
|
|
5608
|
+
} catch (e) {
|
|
5609
|
+
// fall back to default
|
|
5610
|
+
}
|
|
5611
|
+
}
|
|
5612
|
+
|
|
5613
|
+
return arg;
|
|
5614
|
+
});
|
|
5615
|
+
|
|
5616
|
+
return createBreadcrumb({
|
|
5617
|
+
...breadcrumb,
|
|
5618
|
+
data: {
|
|
5619
|
+
...breadcrumb.data,
|
|
5620
|
+
arguments: normalizedArgs,
|
|
5621
|
+
...(isTruncated ? { _meta: { warnings: ['CONSOLE_ARG_TRUNCATED'] } } : {}),
|
|
5622
|
+
},
|
|
5623
|
+
});
|
|
5624
|
+
}
|
|
5625
|
+
|
|
5491
5626
|
/**
|
|
5492
5627
|
* Add global listeners that cannot be removed.
|
|
5493
5628
|
*/
|
|
@@ -5512,7 +5647,7 @@ function addGlobalListeners(replay) {
|
|
|
5512
5647
|
client.on('afterSendEvent', handleAfterSendEvent(replay));
|
|
5513
5648
|
client.on('createDsc', (dsc) => {
|
|
5514
5649
|
const replayId = replay.getSessionId();
|
|
5515
|
-
if (replayId) {
|
|
5650
|
+
if (replayId && replay.isEnabled()) {
|
|
5516
5651
|
dsc.replay_id = replayId;
|
|
5517
5652
|
}
|
|
5518
5653
|
});
|
|
@@ -5820,7 +5955,7 @@ function getHandleRecordingEmit(replay) {
|
|
|
5820
5955
|
// when an error occurs. Clear any state that happens before this current
|
|
5821
5956
|
// checkout. This needs to happen before `addEvent()` which updates state
|
|
5822
5957
|
// dependent on this reset.
|
|
5823
|
-
if (replay.recordingMode === '
|
|
5958
|
+
if (replay.recordingMode === 'buffer' && isCheckout) {
|
|
5824
5959
|
replay.setInitialState();
|
|
5825
5960
|
}
|
|
5826
5961
|
|
|
@@ -5846,7 +5981,7 @@ function getHandleRecordingEmit(replay) {
|
|
|
5846
5981
|
|
|
5847
5982
|
// See note above re: session start needs to reflect the most recent
|
|
5848
5983
|
// checkout.
|
|
5849
|
-
if (replay.recordingMode === '
|
|
5984
|
+
if (replay.recordingMode === 'buffer' && replay.session) {
|
|
5850
5985
|
const { earliestEvent } = replay.getContext();
|
|
5851
5986
|
if (earliestEvent) {
|
|
5852
5987
|
replay.session.started = earliestEvent;
|
|
@@ -6195,9 +6330,11 @@ class ReplayContainer {
|
|
|
6195
6330
|
__init2() {this.performanceEvents = [];}
|
|
6196
6331
|
|
|
6197
6332
|
/**
|
|
6198
|
-
* Recording can happen in one of
|
|
6199
|
-
*
|
|
6200
|
-
*
|
|
6333
|
+
* Recording can happen in one of three modes:
|
|
6334
|
+
* - session: Record the whole session, sending it continuously
|
|
6335
|
+
* - buffer: Always keep the last 60s of recording, requires:
|
|
6336
|
+
* - having replaysOnErrorSampleRate > 0 to capture replay when an error occurs
|
|
6337
|
+
* - or calling `flush()` to send the replay
|
|
6201
6338
|
*/
|
|
6202
6339
|
__init3() {this.recordingMode = 'session';}
|
|
6203
6340
|
|
|
@@ -6206,7 +6343,8 @@ class ReplayContainer {
|
|
|
6206
6343
|
* @hidden
|
|
6207
6344
|
*/
|
|
6208
6345
|
__init4() {this.timeouts = {
|
|
6209
|
-
|
|
6346
|
+
sessionIdlePause: SESSION_IDLE_PAUSE_DURATION,
|
|
6347
|
+
sessionIdleExpire: SESSION_IDLE_EXPIRE_DURATION,
|
|
6210
6348
|
maxSessionLife: MAX_SESSION_LIFE,
|
|
6211
6349
|
}; }
|
|
6212
6350
|
|
|
@@ -6267,8 +6405,6 @@ class ReplayContainer {
|
|
|
6267
6405
|
this._debouncedFlush = debounce(() => this._flush(), this._options.flushMinDelay, {
|
|
6268
6406
|
maxWait: this._options.flushMaxDelay,
|
|
6269
6407
|
});
|
|
6270
|
-
|
|
6271
|
-
this._experimentalOptions = _getExperimentalOptions(options);
|
|
6272
6408
|
}
|
|
6273
6409
|
|
|
6274
6410
|
/** Get the event context. */
|
|
@@ -6292,58 +6428,102 @@ class ReplayContainer {
|
|
|
6292
6428
|
}
|
|
6293
6429
|
|
|
6294
6430
|
/**
|
|
6295
|
-
*
|
|
6296
|
-
*
|
|
6297
|
-
* @hidden
|
|
6431
|
+
* Initializes the plugin based on sampling configuration. Should not be
|
|
6432
|
+
* called outside of constructor.
|
|
6298
6433
|
*/
|
|
6299
|
-
|
|
6300
|
-
|
|
6434
|
+
initializeSampling() {
|
|
6435
|
+
const { errorSampleRate, sessionSampleRate } = this._options;
|
|
6436
|
+
|
|
6437
|
+
// If neither sample rate is > 0, then do nothing - user will need to call one of
|
|
6438
|
+
// `start()` or `startBuffering` themselves.
|
|
6439
|
+
if (errorSampleRate <= 0 && sessionSampleRate <= 0) {
|
|
6440
|
+
return;
|
|
6441
|
+
}
|
|
6442
|
+
|
|
6443
|
+
// Otherwise if there is _any_ sample rate set, try to load an existing
|
|
6444
|
+
// session, or create a new one.
|
|
6445
|
+
const isSessionSampled = this._loadAndCheckSession();
|
|
6446
|
+
|
|
6447
|
+
if (!isSessionSampled) {
|
|
6448
|
+
// This should only occur if `errorSampleRate` is 0 and was unsampled for
|
|
6449
|
+
// session-based replay. In this case there is nothing to do.
|
|
6450
|
+
return;
|
|
6451
|
+
}
|
|
6452
|
+
|
|
6453
|
+
if (!this.session) {
|
|
6454
|
+
// This should not happen, something wrong has occurred
|
|
6455
|
+
this._handleException(new Error('Unable to initialize and create session'));
|
|
6456
|
+
return;
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
if (this.session.sampled && this.session.sampled !== 'session') {
|
|
6460
|
+
// If not sampled as session-based, then recording mode will be `buffer`
|
|
6461
|
+
// Note that we don't explicitly check if `sampled === 'buffer'` because we
|
|
6462
|
+
// could have sessions from Session storage that are still `error` from
|
|
6463
|
+
// prior SDK version.
|
|
6464
|
+
this.recordingMode = 'buffer';
|
|
6465
|
+
}
|
|
6466
|
+
|
|
6467
|
+
this._initializeRecording();
|
|
6301
6468
|
}
|
|
6302
6469
|
|
|
6303
6470
|
/**
|
|
6304
|
-
*
|
|
6471
|
+
* Start a replay regardless of sampling rate. Calling this will always
|
|
6472
|
+
* create a new session. Will throw an error if replay is already in progress.
|
|
6305
6473
|
*
|
|
6306
6474
|
* Creates or loads a session, attaches listeners to varying events (DOM,
|
|
6307
6475
|
* _performanceObserver, Recording, Sentry SDK, etc)
|
|
6308
6476
|
*/
|
|
6309
6477
|
start() {
|
|
6310
|
-
this.
|
|
6311
|
-
|
|
6312
|
-
if (!this._loadAndCheckSession()) {
|
|
6313
|
-
return;
|
|
6478
|
+
if (this._isEnabled && this.recordingMode === 'session') {
|
|
6479
|
+
throw new Error('Replay recording is already in progress');
|
|
6314
6480
|
}
|
|
6315
6481
|
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
this._handleException(new Error('No session found'));
|
|
6319
|
-
return;
|
|
6482
|
+
if (this._isEnabled && this.recordingMode === 'buffer') {
|
|
6483
|
+
throw new Error('Replay buffering is in progress, call `flush()` to save the replay');
|
|
6320
6484
|
}
|
|
6321
6485
|
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6486
|
+
const previousSessionId = this.session && this.session.id;
|
|
6487
|
+
|
|
6488
|
+
const { session } = getSession({
|
|
6489
|
+
timeouts: this.timeouts,
|
|
6490
|
+
stickySession: Boolean(this._options.stickySession),
|
|
6491
|
+
currentSession: this.session,
|
|
6492
|
+
// This is intentional: create a new session-based replay when calling `start()`
|
|
6493
|
+
sessionSampleRate: 1,
|
|
6494
|
+
allowBuffering: false,
|
|
6495
|
+
});
|
|
6496
|
+
|
|
6497
|
+
session.previousSessionId = previousSessionId;
|
|
6498
|
+
this.session = session;
|
|
6499
|
+
|
|
6500
|
+
this._initializeRecording();
|
|
6501
|
+
}
|
|
6326
6502
|
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6503
|
+
/**
|
|
6504
|
+
* Start replay buffering. Buffers until `flush()` is called or, if
|
|
6505
|
+
* `replaysOnErrorSampleRate` > 0, an error occurs.
|
|
6506
|
+
*/
|
|
6507
|
+
startBuffering() {
|
|
6508
|
+
if (this._isEnabled) {
|
|
6509
|
+
throw new Error('Replay recording is already in progress');
|
|
6331
6510
|
}
|
|
6332
6511
|
|
|
6333
|
-
|
|
6334
|
-
// should treat it as an activity
|
|
6335
|
-
this._updateSessionActivity();
|
|
6512
|
+
const previousSessionId = this.session && this.session.id;
|
|
6336
6513
|
|
|
6337
|
-
|
|
6338
|
-
|
|
6514
|
+
const { session } = getSession({
|
|
6515
|
+
timeouts: this.timeouts,
|
|
6516
|
+
stickySession: Boolean(this._options.stickySession),
|
|
6517
|
+
currentSession: this.session,
|
|
6518
|
+
sessionSampleRate: 0,
|
|
6519
|
+
allowBuffering: true,
|
|
6339
6520
|
});
|
|
6340
6521
|
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
// Need to set as enabled before we start recording, as `record()` can trigger a flush with a new checkout
|
|
6344
|
-
this._isEnabled = true;
|
|
6522
|
+
session.previousSessionId = previousSessionId;
|
|
6523
|
+
this.session = session;
|
|
6345
6524
|
|
|
6346
|
-
this.
|
|
6525
|
+
this.recordingMode = 'buffer';
|
|
6526
|
+
this._initializeRecording();
|
|
6347
6527
|
}
|
|
6348
6528
|
|
|
6349
6529
|
/**
|
|
@@ -6358,7 +6538,7 @@ class ReplayContainer {
|
|
|
6358
6538
|
// When running in error sampling mode, we need to overwrite `checkoutEveryNms`
|
|
6359
6539
|
// Without this, it would record forever, until an error happens, which we don't want
|
|
6360
6540
|
// instead, we'll always keep the last 60 seconds of replay before an error happened
|
|
6361
|
-
...(this.recordingMode === '
|
|
6541
|
+
...(this.recordingMode === 'buffer' && { checkoutEveryNms: BUFFER_CHECKOUT_TIME }),
|
|
6362
6542
|
emit: getHandleRecordingEmit(this),
|
|
6363
6543
|
onMutation: this._onMutationHandler,
|
|
6364
6544
|
});
|
|
@@ -6369,17 +6549,18 @@ class ReplayContainer {
|
|
|
6369
6549
|
|
|
6370
6550
|
/**
|
|
6371
6551
|
* Stops the recording, if it was running.
|
|
6372
|
-
*
|
|
6552
|
+
*
|
|
6553
|
+
* Returns true if it was previously stopped, or is now stopped,
|
|
6554
|
+
* otherwise false.
|
|
6373
6555
|
*/
|
|
6374
6556
|
stopRecording() {
|
|
6375
6557
|
try {
|
|
6376
6558
|
if (this._stopRecording) {
|
|
6377
6559
|
this._stopRecording();
|
|
6378
6560
|
this._stopRecording = undefined;
|
|
6379
|
-
return true;
|
|
6380
6561
|
}
|
|
6381
6562
|
|
|
6382
|
-
return
|
|
6563
|
+
return true;
|
|
6383
6564
|
} catch (err) {
|
|
6384
6565
|
this._handleException(err);
|
|
6385
6566
|
return false;
|
|
@@ -6390,7 +6571,7 @@ class ReplayContainer {
|
|
|
6390
6571
|
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK
|
|
6391
6572
|
* does not support a teardown
|
|
6392
6573
|
*/
|
|
6393
|
-
stop(reason) {
|
|
6574
|
+
async stop(reason) {
|
|
6394
6575
|
if (!this._isEnabled) {
|
|
6395
6576
|
return;
|
|
6396
6577
|
}
|
|
@@ -6406,12 +6587,24 @@ class ReplayContainer {
|
|
|
6406
6587
|
log(msg);
|
|
6407
6588
|
}
|
|
6408
6589
|
|
|
6590
|
+
// We can't move `_isEnabled` after awaiting a flush, otherwise we can
|
|
6591
|
+
// enter into an infinite loop when `stop()` is called while flushing.
|
|
6409
6592
|
this._isEnabled = false;
|
|
6410
6593
|
this._removeListeners();
|
|
6411
6594
|
this.stopRecording();
|
|
6595
|
+
|
|
6596
|
+
this._debouncedFlush.cancel();
|
|
6597
|
+
// See comment above re: `_isEnabled`, we "force" a flush, ignoring the
|
|
6598
|
+
// `_isEnabled` state of the plugin since it was disabled above.
|
|
6599
|
+
await this._flush({ force: true });
|
|
6600
|
+
|
|
6601
|
+
// After flush, destroy event buffer
|
|
6412
6602
|
this.eventBuffer && this.eventBuffer.destroy();
|
|
6413
6603
|
this.eventBuffer = null;
|
|
6414
|
-
|
|
6604
|
+
|
|
6605
|
+
// Clear session from session storage, note this means if a new session
|
|
6606
|
+
// is started after, it will not have `previousSessionId`
|
|
6607
|
+
clearSession(this);
|
|
6415
6608
|
} catch (err) {
|
|
6416
6609
|
this._handleException(err);
|
|
6417
6610
|
}
|
|
@@ -6442,6 +6635,45 @@ class ReplayContainer {
|
|
|
6442
6635
|
this.startRecording();
|
|
6443
6636
|
}
|
|
6444
6637
|
|
|
6638
|
+
/**
|
|
6639
|
+
* If not in "session" recording mode, flush event buffer which will create a new replay.
|
|
6640
|
+
* Unless `continueRecording` is false, the replay will continue to record and
|
|
6641
|
+
* behave as a "session"-based replay.
|
|
6642
|
+
*
|
|
6643
|
+
* Otherwise, queue up a flush.
|
|
6644
|
+
*/
|
|
6645
|
+
async sendBufferedReplayOrFlush({ continueRecording = true } = {}) {
|
|
6646
|
+
if (this.recordingMode === 'session') {
|
|
6647
|
+
return this.flushImmediate();
|
|
6648
|
+
}
|
|
6649
|
+
|
|
6650
|
+
// Allow flush to complete before resuming as a session recording, otherwise
|
|
6651
|
+
// the checkout from `startRecording` may be included in the payload.
|
|
6652
|
+
// Prefer to keep the error replay as a separate (and smaller) segment
|
|
6653
|
+
// than the session replay.
|
|
6654
|
+
await this.flushImmediate();
|
|
6655
|
+
|
|
6656
|
+
const hasStoppedRecording = this.stopRecording();
|
|
6657
|
+
|
|
6658
|
+
if (!continueRecording || !hasStoppedRecording) {
|
|
6659
|
+
return;
|
|
6660
|
+
}
|
|
6661
|
+
|
|
6662
|
+
// Re-start recording, but in "session" recording mode
|
|
6663
|
+
|
|
6664
|
+
// Reset all "capture on error" configuration before
|
|
6665
|
+
// starting a new recording
|
|
6666
|
+
this.recordingMode = 'session';
|
|
6667
|
+
|
|
6668
|
+
// Once this session ends, we do not want to refresh it
|
|
6669
|
+
if (this.session) {
|
|
6670
|
+
this.session.shouldRefresh = false;
|
|
6671
|
+
this._maybeSaveSession();
|
|
6672
|
+
}
|
|
6673
|
+
|
|
6674
|
+
this.startRecording();
|
|
6675
|
+
}
|
|
6676
|
+
|
|
6445
6677
|
/**
|
|
6446
6678
|
* We want to batch uploads of replay events. Save events only if
|
|
6447
6679
|
* `<flushMinDelay>` milliseconds have elapsed since the last event
|
|
@@ -6451,12 +6683,12 @@ class ReplayContainer {
|
|
|
6451
6683
|
* processing and hand back control to caller.
|
|
6452
6684
|
*/
|
|
6453
6685
|
addUpdate(cb) {
|
|
6454
|
-
// We need to always run `cb` (e.g. in the case of `this.recordingMode == '
|
|
6686
|
+
// We need to always run `cb` (e.g. in the case of `this.recordingMode == 'buffer'`)
|
|
6455
6687
|
const cbResult = cb();
|
|
6456
6688
|
|
|
6457
6689
|
// If this option is turned on then we will only want to call `flush`
|
|
6458
6690
|
// explicitly
|
|
6459
|
-
if (this.recordingMode === '
|
|
6691
|
+
if (this.recordingMode === 'buffer') {
|
|
6460
6692
|
return;
|
|
6461
6693
|
}
|
|
6462
6694
|
|
|
@@ -6528,12 +6760,12 @@ class ReplayContainer {
|
|
|
6528
6760
|
const oldSessionId = this.getSessionId();
|
|
6529
6761
|
|
|
6530
6762
|
// Prevent starting a new session if the last user activity is older than
|
|
6531
|
-
//
|
|
6763
|
+
// SESSION_IDLE_PAUSE_DURATION. Otherwise non-user activity can trigger a new
|
|
6532
6764
|
// session+recording. This creates noisy replays that do not have much
|
|
6533
6765
|
// content in them.
|
|
6534
6766
|
if (
|
|
6535
6767
|
this._lastActivity &&
|
|
6536
|
-
isExpired(this._lastActivity, this.timeouts.
|
|
6768
|
+
isExpired(this._lastActivity, this.timeouts.sessionIdlePause) &&
|
|
6537
6769
|
this.session &&
|
|
6538
6770
|
this.session.sampled === 'session'
|
|
6539
6771
|
) {
|
|
@@ -6583,6 +6815,30 @@ class ReplayContainer {
|
|
|
6583
6815
|
this._context.urls.push(url);
|
|
6584
6816
|
}
|
|
6585
6817
|
|
|
6818
|
+
/**
|
|
6819
|
+
* Initialize and start all listeners to varying events (DOM,
|
|
6820
|
+
* Performance Observer, Recording, Sentry SDK, etc)
|
|
6821
|
+
*/
|
|
6822
|
+
_initializeRecording() {
|
|
6823
|
+
this.setInitialState();
|
|
6824
|
+
|
|
6825
|
+
// this method is generally called on page load or manually - in both cases
|
|
6826
|
+
// we should treat it as an activity
|
|
6827
|
+
this._updateSessionActivity();
|
|
6828
|
+
|
|
6829
|
+
this.eventBuffer = createEventBuffer({
|
|
6830
|
+
useCompression: this._options.useCompression,
|
|
6831
|
+
});
|
|
6832
|
+
|
|
6833
|
+
this._removeListeners();
|
|
6834
|
+
this._addListeners();
|
|
6835
|
+
|
|
6836
|
+
// Need to set as enabled before we start recording, as `record()` can trigger a flush with a new checkout
|
|
6837
|
+
this._isEnabled = true;
|
|
6838
|
+
|
|
6839
|
+
this.startRecording();
|
|
6840
|
+
}
|
|
6841
|
+
|
|
6586
6842
|
/** A wrapper to conditionally capture exceptions. */
|
|
6587
6843
|
_handleException(error) {
|
|
6588
6844
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', error);
|
|
@@ -6602,7 +6858,7 @@ class ReplayContainer {
|
|
|
6602
6858
|
stickySession: Boolean(this._options.stickySession),
|
|
6603
6859
|
currentSession: this.session,
|
|
6604
6860
|
sessionSampleRate: this._options.sessionSampleRate,
|
|
6605
|
-
|
|
6861
|
+
allowBuffering: this._options.errorSampleRate > 0,
|
|
6606
6862
|
});
|
|
6607
6863
|
|
|
6608
6864
|
// If session was newly created (i.e. was not loaded from storage), then
|
|
@@ -6619,7 +6875,7 @@ class ReplayContainer {
|
|
|
6619
6875
|
this.session = session;
|
|
6620
6876
|
|
|
6621
6877
|
if (!this.session.sampled) {
|
|
6622
|
-
this.stop('session unsampled');
|
|
6878
|
+
void this.stop('session unsampled');
|
|
6623
6879
|
return false;
|
|
6624
6880
|
}
|
|
6625
6881
|
|
|
@@ -6743,7 +6999,7 @@ class ReplayContainer {
|
|
|
6743
6999
|
const isSessionActive = this.checkAndHandleExpiredSession();
|
|
6744
7000
|
|
|
6745
7001
|
if (!isSessionActive) {
|
|
6746
|
-
// If the user has come back to the page within
|
|
7002
|
+
// If the user has come back to the page within SESSION_IDLE_PAUSE_DURATION
|
|
6747
7003
|
// ms, we will re-use the existing session, otherwise create a new
|
|
6748
7004
|
// session
|
|
6749
7005
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Document has become active, but session has expired');
|
|
@@ -6817,7 +7073,7 @@ class ReplayContainer {
|
|
|
6817
7073
|
* Only flush if `this.recordingMode === 'session'`
|
|
6818
7074
|
*/
|
|
6819
7075
|
_conditionalFlush() {
|
|
6820
|
-
if (this.recordingMode === '
|
|
7076
|
+
if (this.recordingMode === 'buffer') {
|
|
6821
7077
|
return;
|
|
6822
7078
|
}
|
|
6823
7079
|
|
|
@@ -6912,7 +7168,7 @@ class ReplayContainer {
|
|
|
6912
7168
|
// This means we retried 3 times and all of them failed,
|
|
6913
7169
|
// or we ran into a problem we don't want to retry, like rate limiting.
|
|
6914
7170
|
// In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments
|
|
6915
|
-
this.stop('sendReplay');
|
|
7171
|
+
void this.stop('sendReplay');
|
|
6916
7172
|
|
|
6917
7173
|
const client = getCurrentHub().getClient();
|
|
6918
7174
|
|
|
@@ -6926,8 +7182,12 @@ class ReplayContainer {
|
|
|
6926
7182
|
* Flush recording data to Sentry. Creates a lock so that only a single flush
|
|
6927
7183
|
* can be active at a time. Do not call this directly.
|
|
6928
7184
|
*/
|
|
6929
|
-
__init16() {this._flush = async (
|
|
6930
|
-
|
|
7185
|
+
__init16() {this._flush = async ({
|
|
7186
|
+
force = false,
|
|
7187
|
+
}
|
|
7188
|
+
|
|
7189
|
+
= {}) => {
|
|
7190
|
+
if (!this._isEnabled && !force) {
|
|
6931
7191
|
// This can happen if e.g. the replay was stopped because of exceeding the retry limit
|
|
6932
7192
|
return;
|
|
6933
7193
|
}
|
|
@@ -7008,23 +7268,6 @@ class ReplayContainer {
|
|
|
7008
7268
|
};}
|
|
7009
7269
|
}
|
|
7010
7270
|
|
|
7011
|
-
function _getExperimentalOptions(options) {
|
|
7012
|
-
const requestHeaders = options._experiments.captureRequestHeaders || [];
|
|
7013
|
-
const responseHeaders = options._experiments.captureResponseHeaders || [];
|
|
7014
|
-
const captureBodies = options._experiments.captureNetworkBodies || false;
|
|
7015
|
-
|
|
7016
|
-
// Add defaults
|
|
7017
|
-
const defaultHeaders = ['content-length', 'content-type', 'accept'];
|
|
7018
|
-
|
|
7019
|
-
return {
|
|
7020
|
-
network: {
|
|
7021
|
-
captureBodies,
|
|
7022
|
-
requestHeaders: [...defaultHeaders, ...requestHeaders.map(header => header.toLowerCase())],
|
|
7023
|
-
responseHeaders: [...defaultHeaders, ...responseHeaders.map(header => header.toLowerCase())],
|
|
7024
|
-
},
|
|
7025
|
-
};
|
|
7026
|
-
}
|
|
7027
|
-
|
|
7028
7271
|
function getOption(
|
|
7029
7272
|
selectors,
|
|
7030
7273
|
defaultSelectors,
|
|
@@ -7128,6 +7371,8 @@ function isElectronNodeRenderer() {
|
|
|
7128
7371
|
const MEDIA_SELECTORS =
|
|
7129
7372
|
'img,image,svg,video,object,picture,embed,map,audio,link[rel="icon"],link[rel="apple-touch-icon"]';
|
|
7130
7373
|
|
|
7374
|
+
const DEFAULT_NETWORK_HEADERS = ['content-length', 'content-type', 'accept'];
|
|
7375
|
+
|
|
7131
7376
|
let _initialized = false;
|
|
7132
7377
|
|
|
7133
7378
|
/**
|
|
@@ -7168,6 +7413,11 @@ class Replay {
|
|
|
7168
7413
|
maskAllInputs = true,
|
|
7169
7414
|
blockAllMedia = true,
|
|
7170
7415
|
|
|
7416
|
+
networkDetailAllowUrls = [],
|
|
7417
|
+
networkCaptureBodies = true,
|
|
7418
|
+
networkRequestHeaders = [],
|
|
7419
|
+
networkResponseHeaders = [],
|
|
7420
|
+
|
|
7171
7421
|
mask = [],
|
|
7172
7422
|
unmask = [],
|
|
7173
7423
|
block = [],
|
|
@@ -7226,6 +7476,11 @@ class Replay {
|
|
|
7226
7476
|
errorSampleRate,
|
|
7227
7477
|
useCompression,
|
|
7228
7478
|
blockAllMedia,
|
|
7479
|
+
networkDetailAllowUrls,
|
|
7480
|
+
networkCaptureBodies,
|
|
7481
|
+
networkRequestHeaders: _getMergedNetworkHeaders(networkRequestHeaders),
|
|
7482
|
+
networkResponseHeaders: _getMergedNetworkHeaders(networkResponseHeaders),
|
|
7483
|
+
|
|
7229
7484
|
_experiments,
|
|
7230
7485
|
};
|
|
7231
7486
|
|
|
@@ -7279,14 +7534,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
|
|
|
7279
7534
|
}
|
|
7280
7535
|
|
|
7281
7536
|
/**
|
|
7282
|
-
*
|
|
7283
|
-
* potentially create a transaction before some native SDK integrations have run
|
|
7284
|
-
* and applied their own global event processor. An example is:
|
|
7285
|
-
* https://github.com/getsentry/sentry-javascript/blob/b47ceafbdac7f8b99093ce6023726ad4687edc48/packages/browser/src/integrations/useragent.ts
|
|
7286
|
-
*
|
|
7287
|
-
* So we call `replay.setup` in next event loop as a workaround to wait for other
|
|
7288
|
-
* global event processors to finish. This is no longer needed, but keeping it
|
|
7289
|
-
* here to avoid any future issues.
|
|
7537
|
+
* Setup and initialize replay container
|
|
7290
7538
|
*/
|
|
7291
7539
|
setupOnce() {
|
|
7292
7540
|
if (!isBrowser()) {
|
|
@@ -7295,12 +7543,20 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
|
|
|
7295
7543
|
|
|
7296
7544
|
this._setup();
|
|
7297
7545
|
|
|
7298
|
-
//
|
|
7299
|
-
|
|
7546
|
+
// Once upon a time, we tried to create a transaction in `setupOnce` and it would
|
|
7547
|
+
// potentially create a transaction before some native SDK integrations have run
|
|
7548
|
+
// and applied their own global event processor. An example is:
|
|
7549
|
+
// https://github.com/getsentry/sentry-javascript/blob/b47ceafbdac7f8b99093ce6023726ad4687edc48/packages/browser/src/integrations/useragent.ts
|
|
7550
|
+
//
|
|
7551
|
+
// So we call `this._initialize()` in next event loop as a workaround to wait for other
|
|
7552
|
+
// global event processors to finish. This is no longer needed, but keeping it
|
|
7553
|
+
// here to avoid any future issues.
|
|
7554
|
+
setTimeout(() => this._initialize());
|
|
7300
7555
|
}
|
|
7301
7556
|
|
|
7302
7557
|
/**
|
|
7303
|
-
*
|
|
7558
|
+
* Start a replay regardless of sampling rate. Calling this will always
|
|
7559
|
+
* create a new session. Will throw an error if replay is already in progress.
|
|
7304
7560
|
*
|
|
7305
7561
|
* Creates or loads a session, attaches listeners to varying events (DOM,
|
|
7306
7562
|
* PerformanceObserver, Recording, Sentry SDK, etc)
|
|
@@ -7313,27 +7569,43 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
|
|
|
7313
7569
|
this._replay.start();
|
|
7314
7570
|
}
|
|
7315
7571
|
|
|
7572
|
+
/**
|
|
7573
|
+
* Start replay buffering. Buffers until `flush()` is called or, if
|
|
7574
|
+
* `replaysOnErrorSampleRate` > 0, until an error occurs.
|
|
7575
|
+
*/
|
|
7576
|
+
startBuffering() {
|
|
7577
|
+
if (!this._replay) {
|
|
7578
|
+
return;
|
|
7579
|
+
}
|
|
7580
|
+
|
|
7581
|
+
this._replay.startBuffering();
|
|
7582
|
+
}
|
|
7583
|
+
|
|
7316
7584
|
/**
|
|
7317
7585
|
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK
|
|
7318
7586
|
* does not support a teardown
|
|
7319
7587
|
*/
|
|
7320
7588
|
stop() {
|
|
7321
7589
|
if (!this._replay) {
|
|
7322
|
-
return;
|
|
7590
|
+
return Promise.resolve();
|
|
7323
7591
|
}
|
|
7324
7592
|
|
|
7325
|
-
this._replay.stop();
|
|
7593
|
+
return this._replay.stop();
|
|
7326
7594
|
}
|
|
7327
7595
|
|
|
7328
7596
|
/**
|
|
7329
|
-
*
|
|
7597
|
+
* If not in "session" recording mode, flush event buffer which will create a new replay.
|
|
7598
|
+
* Unless `continueRecording` is false, the replay will continue to record and
|
|
7599
|
+
* behave as a "session"-based replay.
|
|
7600
|
+
*
|
|
7601
|
+
* Otherwise, queue up a flush.
|
|
7330
7602
|
*/
|
|
7331
|
-
flush() {
|
|
7603
|
+
flush(options) {
|
|
7332
7604
|
if (!this._replay || !this._replay.isEnabled()) {
|
|
7333
|
-
return;
|
|
7605
|
+
return Promise.resolve();
|
|
7334
7606
|
}
|
|
7335
7607
|
|
|
7336
|
-
return this._replay.
|
|
7608
|
+
return this._replay.sendBufferedReplayOrFlush(options);
|
|
7337
7609
|
}
|
|
7338
7610
|
|
|
7339
7611
|
/**
|
|
@@ -7346,6 +7618,16 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
|
|
|
7346
7618
|
|
|
7347
7619
|
return this._replay.getSessionId();
|
|
7348
7620
|
}
|
|
7621
|
+
/**
|
|
7622
|
+
* Initializes replay.
|
|
7623
|
+
*/
|
|
7624
|
+
_initialize() {
|
|
7625
|
+
if (!this._replay) {
|
|
7626
|
+
return;
|
|
7627
|
+
}
|
|
7628
|
+
|
|
7629
|
+
this._replay.initializeSampling();
|
|
7630
|
+
}
|
|
7349
7631
|
|
|
7350
7632
|
/** Setup the integration. */
|
|
7351
7633
|
_setup() {
|
|
@@ -7395,5 +7677,9 @@ function loadReplayOptionsFromClient(initialOptions) {
|
|
|
7395
7677
|
return finalOptions;
|
|
7396
7678
|
}
|
|
7397
7679
|
|
|
7680
|
+
function _getMergedNetworkHeaders(headers) {
|
|
7681
|
+
return [...DEFAULT_NETWORK_HEADERS, ...headers.map(header => header.toLowerCase())];
|
|
7682
|
+
}
|
|
7683
|
+
|
|
7398
7684
|
export { Replay };
|
|
7399
7685
|
//# sourceMappingURL=index.js.map
|