@sentry/replay 7.45.0 → 7.47.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 +16 -4
- package/cjs/index.js +443 -211
- package/cjs/index.js.map +1 -1
- package/esm/index.js +444 -212
- package/esm/index.js.map +1 -1
- package/package.json +5 -5
- package/types/constants.d.ts +1 -0
- package/types/constants.d.ts.map +1 -1
- package/types/coreHandlers/handleFetch.d.ts +2 -2
- package/types/coreHandlers/handleFetch.d.ts.map +1 -1
- package/types/coreHandlers/handleHistory.d.ts.map +1 -1
- package/types/coreHandlers/handleNetworkBreadcrumbs.d.ts +5 -11
- package/types/coreHandlers/handleNetworkBreadcrumbs.d.ts.map +1 -1
- package/types/coreHandlers/handleXhr.d.ts +2 -2
- package/types/coreHandlers/handleXhr.d.ts.map +1 -1
- package/types/coreHandlers/{addBreadcrumbEvent.d.ts → util/addBreadcrumbEvent.d.ts} +1 -1
- package/types/coreHandlers/util/addBreadcrumbEvent.d.ts.map +1 -0
- package/types/coreHandlers/util/addNetworkBreadcrumb.d.ts +4 -0
- package/types/coreHandlers/util/addNetworkBreadcrumb.d.ts.map +1 -0
- package/types/coreHandlers/util/fetchUtils.d.ts +24 -0
- package/types/coreHandlers/util/fetchUtils.d.ts.map +1 -0
- package/types/coreHandlers/util/networkUtils.d.ts +15 -0
- package/types/coreHandlers/util/networkUtils.d.ts.map +1 -0
- package/types/coreHandlers/util/xhrUtils.d.ts +23 -0
- package/types/coreHandlers/util/xhrUtils.d.ts.map +1 -0
- package/types/replay.d.ts +2 -0
- package/types/replay.d.ts.map +1 -1
- package/types/types.d.ts +126 -5
- package/types/types.d.ts.map +1 -1
- package/types/util/addMemoryEntry.d.ts.map +1 -1
- package/types/util/createPerformanceEntries.d.ts +2 -2
- package/types/util/createPerformanceEntries.d.ts.map +1 -1
- package/types/util/createPerformanceSpans.d.ts +2 -2
- package/types/util/createPerformanceSpans.d.ts.map +1 -1
- package/types/util/sendReplayRequest.d.ts.map +1 -1
- package/types/coreHandlers/addBreadcrumbEvent.d.ts.map +0 -1
- package/types/coreHandlers/addNetworkBreadcrumb.d.ts +0 -4
- package/types/coreHandlers/addNetworkBreadcrumb.d.ts.map +0 -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, htmlTreeAsString, addInstrumentationHandler, browserPerformanceTimeOrigin, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, isNodeEnv
|
|
2
|
+
import { GLOBAL_OBJ, logger, uuid4, normalize, htmlTreeAsString, dropUndefinedKeys, 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
|
|
@@ -29,6 +29,9 @@ const ERROR_CHECKOUT_TIME = 60000;
|
|
|
29
29
|
const RETRY_BASE_INTERVAL = 5000;
|
|
30
30
|
const RETRY_MAX_COUNT = 3;
|
|
31
31
|
|
|
32
|
+
/* The max (uncompressed) size in bytes of a network body. Any body larger than this will be dropped. */
|
|
33
|
+
const NETWORK_BODY_MAX_SIZE = 300000;
|
|
34
|
+
|
|
32
35
|
var NodeType$1;
|
|
33
36
|
(function (NodeType) {
|
|
34
37
|
NodeType[NodeType["Document"] = 0] = "Document";
|
|
@@ -4066,7 +4069,7 @@ function addBreadcrumbEvent(replay, breadcrumb) {
|
|
|
4066
4069
|
timestamp: (breadcrumb.timestamp || 0) * 1000,
|
|
4067
4070
|
data: {
|
|
4068
4071
|
tag: 'breadcrumb',
|
|
4069
|
-
payload: breadcrumb,
|
|
4072
|
+
payload: normalize(breadcrumb),
|
|
4070
4073
|
},
|
|
4071
4074
|
});
|
|
4072
4075
|
|
|
@@ -4366,7 +4369,10 @@ function _isSentryRequest(url) {
|
|
|
4366
4369
|
}
|
|
4367
4370
|
|
|
4368
4371
|
/** Add a performance entry breadcrumb */
|
|
4369
|
-
function addNetworkBreadcrumb(
|
|
4372
|
+
function addNetworkBreadcrumb(
|
|
4373
|
+
replay,
|
|
4374
|
+
result,
|
|
4375
|
+
) {
|
|
4370
4376
|
if (!replay.isEnabled()) {
|
|
4371
4377
|
return;
|
|
4372
4378
|
}
|
|
@@ -4396,18 +4402,17 @@ function handleFetch(handlerData) {
|
|
|
4396
4402
|
return null;
|
|
4397
4403
|
}
|
|
4398
4404
|
|
|
4399
|
-
|
|
4405
|
+
// This is only used as a fallback, so we know the body sizes are never set here
|
|
4406
|
+
const { method, url } = fetchData;
|
|
4400
4407
|
|
|
4401
4408
|
return {
|
|
4402
4409
|
type: 'resource.fetch',
|
|
4403
4410
|
start: startTimestamp / 1000,
|
|
4404
4411
|
end: endTimestamp / 1000,
|
|
4405
|
-
name:
|
|
4412
|
+
name: url,
|
|
4406
4413
|
data: {
|
|
4407
4414
|
method,
|
|
4408
4415
|
statusCode: response && (response ).status,
|
|
4409
|
-
requestBodySize,
|
|
4410
|
-
responseBodySize,
|
|
4411
4416
|
},
|
|
4412
4417
|
};
|
|
4413
4418
|
}
|
|
@@ -4435,13 +4440,8 @@ function handleXhr(handlerData) {
|
|
|
4435
4440
|
return null;
|
|
4436
4441
|
}
|
|
4437
4442
|
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
url,
|
|
4441
|
-
status_code: statusCode,
|
|
4442
|
-
request_body_size: requestBodySize,
|
|
4443
|
-
response_body_size: responseBodySize,
|
|
4444
|
-
} = xhr.__sentry_xhr__;
|
|
4443
|
+
// This is only used as a fallback, so we know the body sizes are never set here
|
|
4444
|
+
const { method, url, status_code: statusCode } = xhr.__sentry_xhr__;
|
|
4445
4445
|
|
|
4446
4446
|
if (url === undefined) {
|
|
4447
4447
|
return null;
|
|
@@ -4455,8 +4455,6 @@ function handleXhr(handlerData) {
|
|
|
4455
4455
|
data: {
|
|
4456
4456
|
method,
|
|
4457
4457
|
statusCode,
|
|
4458
|
-
requestBodySize,
|
|
4459
|
-
responseBodySize,
|
|
4460
4458
|
},
|
|
4461
4459
|
};
|
|
4462
4460
|
}
|
|
@@ -4476,131 +4474,202 @@ function handleXhrSpanListener(replay) {
|
|
|
4476
4474
|
};
|
|
4477
4475
|
}
|
|
4478
4476
|
|
|
4479
|
-
/**
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
*/
|
|
4488
|
-
function handleNetworkBreadcrumbs(replay) {
|
|
4489
|
-
const client = getCurrentHub().getClient();
|
|
4477
|
+
/** Get the size of a body. */
|
|
4478
|
+
function getBodySize(
|
|
4479
|
+
body,
|
|
4480
|
+
textEncoder,
|
|
4481
|
+
) {
|
|
4482
|
+
if (!body) {
|
|
4483
|
+
return undefined;
|
|
4484
|
+
}
|
|
4490
4485
|
|
|
4491
4486
|
try {
|
|
4492
|
-
|
|
4487
|
+
if (typeof body === 'string') {
|
|
4488
|
+
return textEncoder.encode(body).length;
|
|
4489
|
+
}
|
|
4493
4490
|
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
};
|
|
4491
|
+
if (body instanceof URLSearchParams) {
|
|
4492
|
+
return textEncoder.encode(body.toString()).length;
|
|
4493
|
+
}
|
|
4498
4494
|
|
|
4499
|
-
if (
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
// Fallback behavior
|
|
4503
|
-
addInstrumentationHandler('fetch', handleFetchSpanListener(replay));
|
|
4504
|
-
addInstrumentationHandler('xhr', handleXhrSpanListener(replay));
|
|
4495
|
+
if (body instanceof FormData) {
|
|
4496
|
+
const formDataStr = _serializeFormData(body);
|
|
4497
|
+
return textEncoder.encode(formDataStr).length;
|
|
4505
4498
|
}
|
|
4506
|
-
|
|
4507
|
-
|
|
4499
|
+
|
|
4500
|
+
if (body instanceof Blob) {
|
|
4501
|
+
return body.size;
|
|
4502
|
+
}
|
|
4503
|
+
|
|
4504
|
+
if (body instanceof ArrayBuffer) {
|
|
4505
|
+
return body.byteLength;
|
|
4506
|
+
}
|
|
4507
|
+
|
|
4508
|
+
// Currently unhandled types: ArrayBufferView, ReadableStream
|
|
4509
|
+
} catch (e) {
|
|
4510
|
+
// just return undefined
|
|
4508
4511
|
}
|
|
4512
|
+
|
|
4513
|
+
return undefined;
|
|
4509
4514
|
}
|
|
4510
4515
|
|
|
4511
|
-
/**
|
|
4512
|
-
function
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
+
/** Convert a Content-Length header to number/undefined. */
|
|
4517
|
+
function parseContentLengthHeader(header) {
|
|
4518
|
+
if (!header) {
|
|
4519
|
+
return undefined;
|
|
4520
|
+
}
|
|
4521
|
+
|
|
4522
|
+
const size = parseInt(header, 10);
|
|
4523
|
+
return isNaN(size) ? undefined : size;
|
|
4524
|
+
}
|
|
4525
|
+
|
|
4526
|
+
/** Get the string representation of a body. */
|
|
4527
|
+
function getBodyString(body) {
|
|
4528
|
+
if (typeof body === 'string') {
|
|
4529
|
+
return body;
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
if (body instanceof URLSearchParams) {
|
|
4533
|
+
return body.toString();
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
if (body instanceof FormData) {
|
|
4537
|
+
return _serializeFormData(body);
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
return undefined;
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4543
|
+
/** Convert ReplayNetworkRequestData to a PerformanceEntry. */
|
|
4544
|
+
function makeNetworkReplayBreadcrumb(
|
|
4545
|
+
type,
|
|
4546
|
+
data,
|
|
4516
4547
|
) {
|
|
4517
|
-
if (!
|
|
4518
|
-
return;
|
|
4548
|
+
if (!data) {
|
|
4549
|
+
return null;
|
|
4519
4550
|
}
|
|
4520
4551
|
|
|
4521
|
-
|
|
4522
|
-
if (_isXhrBreadcrumb(breadcrumb) && _isXhrHint(hint)) {
|
|
4523
|
-
_handleXhrBreadcrumb(breadcrumb, hint, options);
|
|
4524
|
-
}
|
|
4552
|
+
const { startTimestamp, endTimestamp, url, method, statusCode, request, response } = data;
|
|
4525
4553
|
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4554
|
+
const result = {
|
|
4555
|
+
type,
|
|
4556
|
+
start: startTimestamp / 1000,
|
|
4557
|
+
end: endTimestamp / 1000,
|
|
4558
|
+
name: url,
|
|
4559
|
+
data: dropUndefinedKeys({
|
|
4560
|
+
method,
|
|
4561
|
+
statusCode,
|
|
4562
|
+
request,
|
|
4563
|
+
response,
|
|
4564
|
+
}),
|
|
4565
|
+
};
|
|
4531
4566
|
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4567
|
+
return result;
|
|
4568
|
+
}
|
|
4569
|
+
|
|
4570
|
+
/** Get either a JSON network body, or a text representation. */
|
|
4571
|
+
function getNetworkBody(bodyText) {
|
|
4572
|
+
if (!bodyText) {
|
|
4573
|
+
return;
|
|
4536
4574
|
}
|
|
4575
|
+
|
|
4576
|
+
try {
|
|
4577
|
+
return JSON.parse(bodyText);
|
|
4578
|
+
} catch (e2) {
|
|
4579
|
+
// return text
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
return bodyText;
|
|
4537
4583
|
}
|
|
4538
4584
|
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4585
|
+
/** Build the request or response part of a replay network breadcrumb. */
|
|
4586
|
+
function buildNetworkRequestOrResponse(
|
|
4587
|
+
bodySize,
|
|
4588
|
+
body,
|
|
4543
4589
|
) {
|
|
4544
|
-
|
|
4545
|
-
|
|
4590
|
+
if (!bodySize) {
|
|
4591
|
+
return undefined;
|
|
4592
|
+
}
|
|
4593
|
+
|
|
4594
|
+
if (!body) {
|
|
4595
|
+
return {
|
|
4596
|
+
size: bodySize,
|
|
4597
|
+
};
|
|
4598
|
+
}
|
|
4599
|
+
|
|
4600
|
+
const info = {
|
|
4601
|
+
size: bodySize,
|
|
4602
|
+
};
|
|
4603
|
+
|
|
4604
|
+
if (bodySize < NETWORK_BODY_MAX_SIZE) {
|
|
4605
|
+
info.body = body;
|
|
4606
|
+
} else {
|
|
4607
|
+
info._meta = {
|
|
4608
|
+
errors: ['MAX_BODY_SIZE_EXCEEDED'],
|
|
4609
|
+
};
|
|
4610
|
+
}
|
|
4546
4611
|
|
|
4547
|
-
|
|
4548
|
-
const result = _makeNetworkReplayBreadcrumb('resource.xhr', breadcrumb, hint);
|
|
4549
|
-
addNetworkBreadcrumb(options.replay, result);
|
|
4612
|
+
return info;
|
|
4550
4613
|
}
|
|
4551
4614
|
|
|
4552
|
-
|
|
4615
|
+
function _serializeFormData(formData) {
|
|
4616
|
+
// This is a bit simplified, but gives us a decent estimate
|
|
4617
|
+
// This converts e.g. { name: 'Anne Smith', age: 13 } to 'name=Anne+Smith&age=13'
|
|
4618
|
+
// @ts-ignore passing FormData to URLSearchParams actually works
|
|
4619
|
+
return new URLSearchParams(formData).toString();
|
|
4620
|
+
}
|
|
4621
|
+
|
|
4622
|
+
/**
|
|
4623
|
+
* Capture a fetch breadcrumb to a replay.
|
|
4624
|
+
* This adds additional data (where approriate).
|
|
4625
|
+
*/
|
|
4626
|
+
async function captureFetchBreadcrumbToReplay(
|
|
4553
4627
|
breadcrumb,
|
|
4554
4628
|
hint,
|
|
4555
4629
|
options,
|
|
4556
4630
|
) {
|
|
4557
|
-
|
|
4631
|
+
try {
|
|
4632
|
+
const data = await _prepareFetchData(breadcrumb, hint, options);
|
|
4558
4633
|
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4634
|
+
// Create a replay performance entry from this breadcrumb
|
|
4635
|
+
const result = makeNetworkReplayBreadcrumb('resource.fetch', data);
|
|
4636
|
+
addNetworkBreadcrumb(options.replay, result);
|
|
4637
|
+
} catch (error) {
|
|
4638
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] Failed to capture fetch breadcrumb', error);
|
|
4639
|
+
}
|
|
4562
4640
|
}
|
|
4563
4641
|
|
|
4564
|
-
|
|
4565
|
-
|
|
4642
|
+
/**
|
|
4643
|
+
* Enrich a breadcrumb with additional data.
|
|
4644
|
+
* This has to be sync & mutate the given breadcrumb,
|
|
4645
|
+
* as the breadcrumb is afterwards consumed by other handlers.
|
|
4646
|
+
*/
|
|
4647
|
+
function enrichFetchBreadcrumb(
|
|
4566
4648
|
breadcrumb,
|
|
4567
4649
|
hint,
|
|
4568
4650
|
options,
|
|
4569
4651
|
) {
|
|
4570
|
-
|
|
4571
|
-
return breadcrumb;
|
|
4572
|
-
}
|
|
4652
|
+
const { input, response } = hint;
|
|
4573
4653
|
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
const response = (hint.response ).clone();
|
|
4578
|
-
const body = await response.text();
|
|
4654
|
+
const body = _getFetchRequestArgBody(input);
|
|
4655
|
+
const reqSize = getBodySize(body, options.textEncoder);
|
|
4656
|
+
const resSize = response ? parseContentLengthHeader(response.headers.get('content-length')) : undefined;
|
|
4579
4657
|
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
}
|
|
4586
|
-
} catch (e3) {
|
|
4587
|
-
// just ignore if something fails here
|
|
4658
|
+
if (reqSize !== undefined) {
|
|
4659
|
+
breadcrumb.data.request_body_size = reqSize;
|
|
4660
|
+
}
|
|
4661
|
+
if (resSize !== undefined) {
|
|
4662
|
+
breadcrumb.data.response_body_size = resSize;
|
|
4588
4663
|
}
|
|
4589
|
-
|
|
4590
|
-
return breadcrumb;
|
|
4591
4664
|
}
|
|
4592
4665
|
|
|
4593
|
-
function
|
|
4594
|
-
type,
|
|
4666
|
+
async function _prepareFetchData(
|
|
4595
4667
|
breadcrumb,
|
|
4596
4668
|
hint,
|
|
4669
|
+
options,
|
|
4597
4670
|
) {
|
|
4598
4671
|
const { startTimestamp, endTimestamp } = hint;
|
|
4599
4672
|
|
|
4600
|
-
if (!endTimestamp) {
|
|
4601
|
-
return null;
|
|
4602
|
-
}
|
|
4603
|
-
|
|
4604
4673
|
const {
|
|
4605
4674
|
url,
|
|
4606
4675
|
method,
|
|
@@ -4609,32 +4678,122 @@ function _makeNetworkReplayBreadcrumb(
|
|
|
4609
4678
|
response_body_size: responseBodySize,
|
|
4610
4679
|
} = breadcrumb.data;
|
|
4611
4680
|
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
}
|
|
4681
|
+
const request = _getRequestInfo(options, hint.input, requestBodySize);
|
|
4682
|
+
const response = await _getResponseInfo(options, hint.response, responseBodySize);
|
|
4615
4683
|
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
},
|
|
4684
|
+
return {
|
|
4685
|
+
startTimestamp,
|
|
4686
|
+
endTimestamp,
|
|
4687
|
+
url,
|
|
4688
|
+
method,
|
|
4689
|
+
statusCode: statusCode || 0,
|
|
4690
|
+
request,
|
|
4691
|
+
response,
|
|
4625
4692
|
};
|
|
4693
|
+
}
|
|
4694
|
+
|
|
4695
|
+
function _getRequestInfo(
|
|
4696
|
+
{ captureBodies },
|
|
4697
|
+
input,
|
|
4698
|
+
requestBodySize,
|
|
4699
|
+
) {
|
|
4700
|
+
if (!captureBodies) {
|
|
4701
|
+
return buildNetworkRequestOrResponse(requestBodySize, undefined);
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
// We only want to transmit string or string-like bodies
|
|
4705
|
+
const requestBody = _getFetchRequestArgBody(input);
|
|
4706
|
+
const body = getNetworkBody(getBodyString(requestBody));
|
|
4707
|
+
return buildNetworkRequestOrResponse(requestBodySize, body);
|
|
4708
|
+
}
|
|
4626
4709
|
|
|
4627
|
-
|
|
4628
|
-
|
|
4710
|
+
async function _getResponseInfo(
|
|
4711
|
+
{ captureBodies, textEncoder },
|
|
4712
|
+
response,
|
|
4713
|
+
responseBodySize,
|
|
4714
|
+
) {
|
|
4715
|
+
if (!captureBodies && responseBodySize !== undefined) {
|
|
4716
|
+
return buildNetworkRequestOrResponse(responseBodySize, undefined);
|
|
4629
4717
|
}
|
|
4630
|
-
|
|
4631
|
-
|
|
4718
|
+
|
|
4719
|
+
// Only clone the response if we need to
|
|
4720
|
+
try {
|
|
4721
|
+
// We have to clone this, as the body can only be read once
|
|
4722
|
+
const res = response.clone();
|
|
4723
|
+
const { body, bodyText } = await _parseFetchBody(res);
|
|
4724
|
+
|
|
4725
|
+
const size =
|
|
4726
|
+
bodyText && bodyText.length && responseBodySize === undefined
|
|
4727
|
+
? getBodySize(bodyText, textEncoder)
|
|
4728
|
+
: responseBodySize;
|
|
4729
|
+
|
|
4730
|
+
if (captureBodies) {
|
|
4731
|
+
return buildNetworkRequestOrResponse(size, body);
|
|
4732
|
+
}
|
|
4733
|
+
|
|
4734
|
+
return buildNetworkRequestOrResponse(size, undefined);
|
|
4735
|
+
} catch (e) {
|
|
4736
|
+
// fallback
|
|
4737
|
+
return buildNetworkRequestOrResponse(responseBodySize, undefined);
|
|
4632
4738
|
}
|
|
4739
|
+
}
|
|
4633
4740
|
|
|
4634
|
-
|
|
4741
|
+
async function _parseFetchBody(
|
|
4742
|
+
response,
|
|
4743
|
+
) {
|
|
4744
|
+
let bodyText;
|
|
4745
|
+
|
|
4746
|
+
try {
|
|
4747
|
+
bodyText = await response.text();
|
|
4748
|
+
} catch (e2) {
|
|
4749
|
+
return {};
|
|
4750
|
+
}
|
|
4751
|
+
|
|
4752
|
+
try {
|
|
4753
|
+
const body = JSON.parse(bodyText);
|
|
4754
|
+
return { body, bodyText };
|
|
4755
|
+
} catch (e3) {
|
|
4756
|
+
// just send bodyText
|
|
4757
|
+
}
|
|
4758
|
+
|
|
4759
|
+
return { bodyText, body: bodyText };
|
|
4635
4760
|
}
|
|
4636
4761
|
|
|
4637
|
-
function
|
|
4762
|
+
function _getFetchRequestArgBody(fetchArgs = []) {
|
|
4763
|
+
// We only support getting the body from the fetch options
|
|
4764
|
+
if (fetchArgs.length !== 2 || typeof fetchArgs[1] !== 'object') {
|
|
4765
|
+
return undefined;
|
|
4766
|
+
}
|
|
4767
|
+
|
|
4768
|
+
return (fetchArgs[1] ).body;
|
|
4769
|
+
}
|
|
4770
|
+
|
|
4771
|
+
/**
|
|
4772
|
+
* Capture an XHR breadcrumb to a replay.
|
|
4773
|
+
* This adds additional data (where approriate).
|
|
4774
|
+
*/
|
|
4775
|
+
async function captureXhrBreadcrumbToReplay(
|
|
4776
|
+
breadcrumb,
|
|
4777
|
+
hint,
|
|
4778
|
+
options,
|
|
4779
|
+
) {
|
|
4780
|
+
try {
|
|
4781
|
+
const data = _prepareXhrData(breadcrumb, hint, options);
|
|
4782
|
+
|
|
4783
|
+
// Create a replay performance entry from this breadcrumb
|
|
4784
|
+
const result = makeNetworkReplayBreadcrumb('resource.xhr', data);
|
|
4785
|
+
addNetworkBreadcrumb(options.replay, result);
|
|
4786
|
+
} catch (error) {
|
|
4787
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] Failed to capture fetch breadcrumb', error);
|
|
4788
|
+
}
|
|
4789
|
+
}
|
|
4790
|
+
|
|
4791
|
+
/**
|
|
4792
|
+
* Enrich a breadcrumb with additional data.
|
|
4793
|
+
* This has to be sync & mutate the given breadcrumb,
|
|
4794
|
+
* as the breadcrumb is afterwards consumed by other handlers.
|
|
4795
|
+
*/
|
|
4796
|
+
function enrichXhrBreadcrumb(
|
|
4638
4797
|
breadcrumb,
|
|
4639
4798
|
hint,
|
|
4640
4799
|
options,
|
|
@@ -4643,7 +4802,7 @@ function _enrichXhrBreadcrumb(
|
|
|
4643
4802
|
|
|
4644
4803
|
const reqSize = getBodySize(input, options.textEncoder);
|
|
4645
4804
|
const resSize = xhr.getResponseHeader('content-length')
|
|
4646
|
-
?
|
|
4805
|
+
? parseContentLengthHeader(xhr.getResponseHeader('content-length'))
|
|
4647
4806
|
: getBodySize(xhr.response, options.textEncoder);
|
|
4648
4807
|
|
|
4649
4808
|
if (reqSize !== undefined) {
|
|
@@ -4654,84 +4813,106 @@ function _enrichXhrBreadcrumb(
|
|
|
4654
4813
|
}
|
|
4655
4814
|
}
|
|
4656
4815
|
|
|
4657
|
-
function
|
|
4816
|
+
function _prepareXhrData(
|
|
4658
4817
|
breadcrumb,
|
|
4659
4818
|
hint,
|
|
4660
4819
|
options,
|
|
4661
4820
|
) {
|
|
4662
|
-
const {
|
|
4821
|
+
const { startTimestamp, endTimestamp, input } = hint;
|
|
4663
4822
|
|
|
4664
|
-
const
|
|
4665
|
-
|
|
4666
|
-
|
|
4823
|
+
const {
|
|
4824
|
+
url,
|
|
4825
|
+
method,
|
|
4826
|
+
status_code: statusCode,
|
|
4827
|
+
request_body_size: requestBodySize,
|
|
4828
|
+
response_body_size: responseBodySize,
|
|
4829
|
+
} = breadcrumb.data;
|
|
4667
4830
|
|
|
4668
|
-
if (
|
|
4669
|
-
|
|
4670
|
-
}
|
|
4671
|
-
if (resSize !== undefined) {
|
|
4672
|
-
breadcrumb.data.response_body_size = resSize;
|
|
4831
|
+
if (!url) {
|
|
4832
|
+
return null;
|
|
4673
4833
|
}
|
|
4674
|
-
}
|
|
4675
4834
|
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4835
|
+
const request = buildNetworkRequestOrResponse(
|
|
4836
|
+
requestBodySize,
|
|
4837
|
+
options.captureBodies ? getNetworkBody(getBodyString(input)) : undefined,
|
|
4838
|
+
);
|
|
4839
|
+
const response = buildNetworkRequestOrResponse(
|
|
4840
|
+
responseBodySize,
|
|
4841
|
+
options.captureBodies ? getNetworkBody(hint.xhr.responseText) : undefined,
|
|
4842
|
+
);
|
|
4684
4843
|
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4844
|
+
return {
|
|
4845
|
+
startTimestamp,
|
|
4846
|
+
endTimestamp,
|
|
4847
|
+
url,
|
|
4848
|
+
method,
|
|
4849
|
+
statusCode: statusCode || 0,
|
|
4850
|
+
request,
|
|
4851
|
+
response,
|
|
4852
|
+
};
|
|
4853
|
+
}
|
|
4689
4854
|
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4855
|
+
/**
|
|
4856
|
+
* This method does two things:
|
|
4857
|
+
* - It enriches the regular XHR/fetch breadcrumbs with request/response size data
|
|
4858
|
+
* - It captures the XHR/fetch breadcrumbs to the replay
|
|
4859
|
+
* (enriching it with further data that is _not_ added to the regular breadcrumbs)
|
|
4860
|
+
*/
|
|
4861
|
+
function handleNetworkBreadcrumbs(replay) {
|
|
4862
|
+
const client = getCurrentHub().getClient();
|
|
4693
4863
|
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
// This converts e.g. { name: 'Anne Smith', age: 13 } to 'name=Anne+Smith&age=13'
|
|
4697
|
-
// @ts-ignore passing FormData to URLSearchParams actually works
|
|
4698
|
-
const formDataStr = new URLSearchParams(body).toString();
|
|
4699
|
-
return textEncoder.encode(formDataStr).length;
|
|
4700
|
-
}
|
|
4864
|
+
try {
|
|
4865
|
+
const textEncoder = new TextEncoder();
|
|
4701
4866
|
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4867
|
+
const options = {
|
|
4868
|
+
replay,
|
|
4869
|
+
textEncoder,
|
|
4870
|
+
captureBodies: replay.getOptions()._experiments.captureNetworkBodies || false,
|
|
4871
|
+
};
|
|
4705
4872
|
|
|
4706
|
-
if (
|
|
4707
|
-
|
|
4873
|
+
if (client && client.on) {
|
|
4874
|
+
client.on('beforeAddBreadcrumb', (breadcrumb, hint) => beforeAddNetworkBreadcrumb(options, breadcrumb, hint));
|
|
4875
|
+
} else {
|
|
4876
|
+
// Fallback behavior
|
|
4877
|
+
addInstrumentationHandler('fetch', handleFetchSpanListener(replay));
|
|
4878
|
+
addInstrumentationHandler('xhr', handleXhrSpanListener(replay));
|
|
4708
4879
|
}
|
|
4709
|
-
|
|
4710
|
-
//
|
|
4711
|
-
} catch (e4) {
|
|
4712
|
-
// just return undefined
|
|
4880
|
+
} catch (e2) {
|
|
4881
|
+
// Do nothing
|
|
4713
4882
|
}
|
|
4714
|
-
|
|
4715
|
-
return undefined;
|
|
4716
4883
|
}
|
|
4717
4884
|
|
|
4718
|
-
/**
|
|
4719
|
-
function
|
|
4720
|
-
|
|
4721
|
-
|
|
4885
|
+
/** just exported for tests */
|
|
4886
|
+
function beforeAddNetworkBreadcrumb(
|
|
4887
|
+
options,
|
|
4888
|
+
breadcrumb,
|
|
4889
|
+
hint,
|
|
4890
|
+
) {
|
|
4891
|
+
if (!breadcrumb.data) {
|
|
4892
|
+
return;
|
|
4722
4893
|
}
|
|
4723
4894
|
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4895
|
+
try {
|
|
4896
|
+
if (_isXhrBreadcrumb(breadcrumb) && _isXhrHint(hint)) {
|
|
4897
|
+
// This has to be sync, as we need to ensure the breadcrumb is enriched in the same tick
|
|
4898
|
+
// Because the hook runs synchronously, and the breadcrumb is afterwards passed on
|
|
4899
|
+
// So any async mutations to it will not be reflected in the final breadcrumb
|
|
4900
|
+
enrichXhrBreadcrumb(breadcrumb, hint, options);
|
|
4727
4901
|
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
if (fetchArgs.length !== 2 || typeof fetchArgs[1] !== 'object') {
|
|
4731
|
-
return undefined;
|
|
4732
|
-
}
|
|
4902
|
+
void captureXhrBreadcrumbToReplay(breadcrumb, hint, options);
|
|
4903
|
+
}
|
|
4733
4904
|
|
|
4734
|
-
|
|
4905
|
+
if (_isFetchBreadcrumb(breadcrumb) && _isFetchHint(hint)) {
|
|
4906
|
+
// This has to be sync, as we need to ensure the breadcrumb is enriched in the same tick
|
|
4907
|
+
// Because the hook runs synchronously, and the breadcrumb is afterwards passed on
|
|
4908
|
+
// So any async mutations to it will not be reflected in the final breadcrumb
|
|
4909
|
+
enrichFetchBreadcrumb(breadcrumb, hint, options);
|
|
4910
|
+
|
|
4911
|
+
void captureFetchBreadcrumbToReplay(breadcrumb, hint, options);
|
|
4912
|
+
}
|
|
4913
|
+
} catch (e) {
|
|
4914
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('Error when enriching network breadcrumb');
|
|
4915
|
+
}
|
|
4735
4916
|
}
|
|
4736
4917
|
|
|
4737
4918
|
function _isXhrBreadcrumb(breadcrumb) {
|
|
@@ -4874,7 +5055,9 @@ function createMemoryEntry(memoryEntry) {
|
|
|
4874
5055
|
|
|
4875
5056
|
// Map entryType -> function to normalize data for event
|
|
4876
5057
|
// @ts-ignore TODO: entry type does not fit the create* functions entry type
|
|
4877
|
-
const ENTRY_TYPES
|
|
5058
|
+
const ENTRY_TYPES
|
|
5059
|
+
|
|
5060
|
+
= {
|
|
4878
5061
|
// @ts-ignore TODO: entry type does not fit the create* functions entry type
|
|
4879
5062
|
resource: createResourceEntry,
|
|
4880
5063
|
paint: createPaintEntry,
|
|
@@ -4887,7 +5070,9 @@ const ENTRY_TYPES = {
|
|
|
4887
5070
|
/**
|
|
4888
5071
|
* Create replay performance entries from the browser performance entries.
|
|
4889
5072
|
*/
|
|
4890
|
-
function createPerformanceEntries(
|
|
5073
|
+
function createPerformanceEntries(
|
|
5074
|
+
entries,
|
|
5075
|
+
) {
|
|
4891
5076
|
return entries.map(createPerformanceEntry).filter(Boolean) ;
|
|
4892
5077
|
}
|
|
4893
5078
|
|
|
@@ -4905,8 +5090,6 @@ function getAbsoluteTime(time) {
|
|
|
4905
5090
|
return ((browserPerformanceTimeOrigin || WINDOW.performance.timeOrigin) + time) / 1000;
|
|
4906
5091
|
}
|
|
4907
5092
|
|
|
4908
|
-
// TODO: type definition!
|
|
4909
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
4910
5093
|
function createPaintEntry(entry) {
|
|
4911
5094
|
const { duration, entryType, name, startTime } = entry;
|
|
4912
5095
|
|
|
@@ -4916,14 +5099,28 @@ function createPaintEntry(entry) {
|
|
|
4916
5099
|
name,
|
|
4917
5100
|
start,
|
|
4918
5101
|
end: start + duration,
|
|
5102
|
+
data: undefined,
|
|
4919
5103
|
};
|
|
4920
5104
|
}
|
|
4921
5105
|
|
|
4922
|
-
// TODO: type definition!
|
|
4923
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
4924
5106
|
function createNavigationEntry(entry) {
|
|
4925
|
-
|
|
4926
|
-
|
|
5107
|
+
const {
|
|
5108
|
+
entryType,
|
|
5109
|
+
name,
|
|
5110
|
+
decodedBodySize,
|
|
5111
|
+
duration,
|
|
5112
|
+
domComplete,
|
|
5113
|
+
encodedBodySize,
|
|
5114
|
+
domContentLoadedEventStart,
|
|
5115
|
+
domContentLoadedEventEnd,
|
|
5116
|
+
domInteractive,
|
|
5117
|
+
loadEventStart,
|
|
5118
|
+
loadEventEnd,
|
|
5119
|
+
redirectCount,
|
|
5120
|
+
startTime,
|
|
5121
|
+
transferSize,
|
|
5122
|
+
type,
|
|
5123
|
+
} = entry;
|
|
4927
5124
|
|
|
4928
5125
|
// Ignore entries with no duration, they do not seem to be useful and cause dupes
|
|
4929
5126
|
if (duration === 0) {
|
|
@@ -4937,15 +5134,34 @@ function createNavigationEntry(entry) {
|
|
|
4937
5134
|
name,
|
|
4938
5135
|
data: {
|
|
4939
5136
|
size: transferSize,
|
|
5137
|
+
decodedBodySize,
|
|
5138
|
+
encodedBodySize,
|
|
4940
5139
|
duration,
|
|
5140
|
+
domInteractive,
|
|
5141
|
+
domContentLoadedEventStart,
|
|
5142
|
+
domContentLoadedEventEnd,
|
|
5143
|
+
loadEventStart,
|
|
5144
|
+
loadEventEnd,
|
|
5145
|
+
domComplete,
|
|
5146
|
+
redirectCount,
|
|
4941
5147
|
},
|
|
4942
5148
|
};
|
|
4943
5149
|
}
|
|
4944
5150
|
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
const {
|
|
5151
|
+
function createResourceEntry(
|
|
5152
|
+
entry,
|
|
5153
|
+
) {
|
|
5154
|
+
const {
|
|
5155
|
+
entryType,
|
|
5156
|
+
initiatorType,
|
|
5157
|
+
name,
|
|
5158
|
+
responseEnd,
|
|
5159
|
+
startTime,
|
|
5160
|
+
decodedBodySize,
|
|
5161
|
+
encodedBodySize,
|
|
5162
|
+
responseStatus,
|
|
5163
|
+
transferSize,
|
|
5164
|
+
} = entry;
|
|
4949
5165
|
|
|
4950
5166
|
// Core SDK handles these
|
|
4951
5167
|
if (['fetch', 'xmlhttprequest'].includes(initiatorType)) {
|
|
@@ -4959,14 +5175,16 @@ function createResourceEntry(entry) {
|
|
|
4959
5175
|
name,
|
|
4960
5176
|
data: {
|
|
4961
5177
|
size: transferSize,
|
|
5178
|
+
statusCode: responseStatus,
|
|
5179
|
+
decodedBodySize,
|
|
4962
5180
|
encodedBodySize,
|
|
4963
5181
|
},
|
|
4964
5182
|
};
|
|
4965
5183
|
}
|
|
4966
5184
|
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
5185
|
+
function createLargestContentfulPaint(
|
|
5186
|
+
entry,
|
|
5187
|
+
) {
|
|
4970
5188
|
const { entryType, startTime, size } = entry;
|
|
4971
5189
|
|
|
4972
5190
|
let startTimeOrNavigationActivation = 0;
|
|
@@ -5280,7 +5498,6 @@ async function sendReplayRequest({
|
|
|
5280
5498
|
}
|
|
5281
5499
|
|
|
5282
5500
|
const baseEvent = {
|
|
5283
|
-
// @ts-ignore private api
|
|
5284
5501
|
type: REPLAY_EVENT_NAME,
|
|
5285
5502
|
...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
|
|
5286
5503
|
timestamp: timestamp / 1000,
|
|
@@ -5534,7 +5751,7 @@ class ReplayContainer {
|
|
|
5534
5751
|
recordingOptions,
|
|
5535
5752
|
}
|
|
5536
5753
|
|
|
5537
|
-
) {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);
|
|
5754
|
+
) {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);
|
|
5538
5755
|
this._recordingOptions = recordingOptions;
|
|
5539
5756
|
this._options = options;
|
|
5540
5757
|
|
|
@@ -5623,23 +5840,7 @@ class ReplayContainer {
|
|
|
5623
5840
|
// instead, we'll always keep the last 60 seconds of replay before an error happened
|
|
5624
5841
|
...(this.recordingMode === 'error' && { checkoutEveryNms: ERROR_CHECKOUT_TIME }),
|
|
5625
5842
|
emit: getHandleRecordingEmit(this),
|
|
5626
|
-
onMutation:
|
|
5627
|
-
if (this._options._experiments.captureMutationSize) {
|
|
5628
|
-
const count = mutations.length;
|
|
5629
|
-
|
|
5630
|
-
if (count > 500) {
|
|
5631
|
-
const breadcrumb = createBreadcrumb({
|
|
5632
|
-
category: 'replay.mutations',
|
|
5633
|
-
data: {
|
|
5634
|
-
count,
|
|
5635
|
-
},
|
|
5636
|
-
});
|
|
5637
|
-
this._createCustomBreadcrumb(breadcrumb);
|
|
5638
|
-
}
|
|
5639
|
-
}
|
|
5640
|
-
// `true` means we use the regular mutation handling by rrweb
|
|
5641
|
-
return true;
|
|
5642
|
-
},
|
|
5843
|
+
onMutation: this._onMutationHandler,
|
|
5643
5844
|
});
|
|
5644
5845
|
} catch (err) {
|
|
5645
5846
|
this._handleException(err);
|
|
@@ -6038,10 +6239,10 @@ class ReplayContainer {
|
|
|
6038
6239
|
* Trigger rrweb to take a full snapshot which will cause this plugin to
|
|
6039
6240
|
* create a new Replay event.
|
|
6040
6241
|
*/
|
|
6041
|
-
_triggerFullSnapshot() {
|
|
6242
|
+
_triggerFullSnapshot(checkout = true) {
|
|
6042
6243
|
try {
|
|
6043
6244
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Taking full rrweb snapshot');
|
|
6044
|
-
record.takeFullSnapshot(
|
|
6245
|
+
record.takeFullSnapshot(checkout);
|
|
6045
6246
|
} catch (err) {
|
|
6046
6247
|
this._handleException(err);
|
|
6047
6248
|
}
|
|
@@ -6255,6 +6456,37 @@ class ReplayContainer {
|
|
|
6255
6456
|
saveSession(this.session);
|
|
6256
6457
|
}
|
|
6257
6458
|
}
|
|
6459
|
+
|
|
6460
|
+
/** Handler for rrweb.record.onMutation */
|
|
6461
|
+
__init17() {this._onMutationHandler = (mutations) => {
|
|
6462
|
+
const count = mutations.length;
|
|
6463
|
+
|
|
6464
|
+
const mutationLimit = this._options._experiments.mutationLimit || 0;
|
|
6465
|
+
const mutationBreadcrumbLimit = this._options._experiments.mutationBreadcrumbLimit || 1000;
|
|
6466
|
+
const overMutationLimit = mutationLimit && count > mutationLimit;
|
|
6467
|
+
|
|
6468
|
+
// Create a breadcrumb if a lot of mutations happen at the same time
|
|
6469
|
+
// We can show this in the UI as an information with potential performance improvements
|
|
6470
|
+
if (count > mutationBreadcrumbLimit || overMutationLimit) {
|
|
6471
|
+
const breadcrumb = createBreadcrumb({
|
|
6472
|
+
category: 'replay.mutations',
|
|
6473
|
+
data: {
|
|
6474
|
+
count,
|
|
6475
|
+
},
|
|
6476
|
+
});
|
|
6477
|
+
this._createCustomBreadcrumb(breadcrumb);
|
|
6478
|
+
}
|
|
6479
|
+
|
|
6480
|
+
if (overMutationLimit) {
|
|
6481
|
+
// We want to skip doing an incremental snapshot if there are too many mutations
|
|
6482
|
+
// Instead, we do a full snapshot
|
|
6483
|
+
this._triggerFullSnapshot(false);
|
|
6484
|
+
return false;
|
|
6485
|
+
}
|
|
6486
|
+
|
|
6487
|
+
// `true` means we use the regular mutation handling by rrweb
|
|
6488
|
+
return true;
|
|
6489
|
+
};}
|
|
6258
6490
|
}
|
|
6259
6491
|
|
|
6260
6492
|
function getOption(
|