@sentry/replay 0.6.14-3 → 0.6.14-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +11 -198
  2. package/dist/index.es.js +100 -59
  3. package/dist/index.js +100 -59
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/src/index.d.ts +6 -14
  6. package/dist/types/src/types.d.ts +25 -11
  7. package/package.json +4 -10
  8. package/dist/config/types/jest.config.d.ts +0 -3
  9. package/dist/config/types/jest.setup.d.ts +0 -32
  10. package/dist/config/types/src/blockAllMedia.test.d.ts +0 -1
  11. package/dist/config/types/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
  12. package/dist/config/types/src/coreHandlers/getSpanHandler.d.ts +0 -5
  13. package/dist/config/types/src/coreHandlers/handleDom.d.ts +0 -1
  14. package/dist/config/types/src/coreHandlers/handleFetch.d.ts +0 -19
  15. package/dist/config/types/src/coreHandlers/handleFetch.test.d.ts +0 -1
  16. package/dist/config/types/src/coreHandlers/handleHistory.d.ts +0 -7
  17. package/dist/config/types/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  18. package/dist/config/types/src/coreHandlers/handleScope.d.ts +0 -2
  19. package/dist/config/types/src/coreHandlers/handleScope.test.d.ts +0 -1
  20. package/dist/config/types/src/coreHandlers/handleXhr.d.ts +0 -21
  21. package/dist/config/types/src/createPerformanceEntry.d.ts +0 -43
  22. package/dist/config/types/src/createPerformanceEntry.test.d.ts +0 -1
  23. package/dist/config/types/src/eventBuffer.d.ts +0 -45
  24. package/dist/config/types/src/eventBuffer.test.d.ts +0 -1
  25. package/dist/config/types/src/flags.d.ts +0 -2
  26. package/dist/config/types/src/flush.test.d.ts +0 -1
  27. package/dist/config/types/src/index-errorSampleRate.test.d.ts +0 -1
  28. package/dist/config/types/src/index-noSticky.test.d.ts +0 -1
  29. package/dist/config/types/src/index-sampling.test.d.ts +0 -1
  30. package/dist/config/types/src/index.d.ts +0 -291
  31. package/dist/config/types/src/index.test.d.ts +0 -1
  32. package/dist/config/types/src/multiple-instances.test.d.ts +0 -1
  33. package/dist/config/types/src/session/Session.d.ts +0 -63
  34. package/dist/config/types/src/session/Session.test.d.ts +0 -1
  35. package/dist/config/types/src/session/constants.d.ts +0 -11
  36. package/dist/config/types/src/session/createSession.d.ts +0 -8
  37. package/dist/config/types/src/session/createSession.test.d.ts +0 -1
  38. package/dist/config/types/src/session/deleteSession.d.ts +0 -4
  39. package/dist/config/types/src/session/deleteSession.test.d.ts +0 -1
  40. package/dist/config/types/src/session/fetchSession.d.ts +0 -6
  41. package/dist/config/types/src/session/fetchSession.test.d.ts +0 -1
  42. package/dist/config/types/src/session/getSession.d.ts +0 -20
  43. package/dist/config/types/src/session/getSession.test.d.ts +0 -1
  44. package/dist/config/types/src/session/index.d.ts +0 -1
  45. package/dist/config/types/src/session/saveSession.d.ts +0 -2
  46. package/dist/config/types/src/session/saveSession.test.d.ts +0 -1
  47. package/dist/config/types/src/stop.test.d.ts +0 -1
  48. package/dist/config/types/src/types.d.ts +0 -130
  49. package/dist/config/types/src/util/addInternalBreadcrumb.d.ts +0 -5
  50. package/dist/config/types/src/util/captureInternalException.d.ts +0 -4
  51. package/dist/config/types/src/util/createBreadcrumb.d.ts +0 -4
  52. package/dist/config/types/src/util/createPayload.d.ts +0 -5
  53. package/dist/config/types/src/util/dedupePerformanceEntries.d.ts +0 -10
  54. package/dist/config/types/src/util/dedupePerformanceEntries.test.d.ts +0 -1
  55. package/dist/config/types/src/util/isExpired.d.ts +0 -5
  56. package/dist/config/types/src/util/isExpired.test.d.ts +0 -1
  57. package/dist/config/types/src/util/isIngestHost.d.ts +0 -4
  58. package/dist/config/types/src/util/isInternal.d.ts +0 -5
  59. package/dist/config/types/src/util/isSampled.d.ts +0 -7
  60. package/dist/config/types/src/util/isSampled.test.d.ts +0 -1
  61. package/dist/config/types/src/util/isSessionExpired.d.ts +0 -5
  62. package/dist/config/types/src/util/isSessionExpired.test.d.ts +0 -1
  63. package/dist/config/types/src/util/logger.d.ts +0 -12
  64. package/dist/config/types/test/fixtures/performanceEntry/lcp.d.ts +0 -1
  65. package/dist/config/types/test/fixtures/performanceEntry/navigation.d.ts +0 -1
  66. package/dist/config/types/test/fixtures/performanceEntry/resource.d.ts +0 -1
  67. package/dist/config/types/test/index.d.ts +0 -3
  68. package/dist/config/types/test/mocks/mockRrweb.d.ts +0 -15
  69. package/dist/config/types/test/mocks/mockSdk.d.ts +0 -10
package/dist/index.js CHANGED
@@ -988,6 +988,8 @@ var Replay = /** @class */ (function () {
988
988
  traceIds: new Set(),
989
989
  urls: [],
990
990
  earliestEvent: null,
991
+ initialTimestamp: new Date().getTime(),
992
+ initialUrl: '',
991
993
  };
992
994
  /**
993
995
  * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
@@ -1388,7 +1390,13 @@ var Replay = /** @class */ (function () {
1388
1390
  * Note that this will cause a new DOM checkout
1389
1391
  */
1390
1392
  Replay.prototype.startRecording = function () {
1391
- this.stopRecording = rrweb.record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1393
+ try {
1394
+ this.stopRecording = rrweb.record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1395
+ }
1396
+ catch (err) {
1397
+ logger.error(err);
1398
+ captureInternalException(err);
1399
+ }
1392
1400
  };
1393
1401
  /**
1394
1402
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK
@@ -1399,22 +1407,35 @@ var Replay = /** @class */ (function () {
1399
1407
  if (!isBrowser) {
1400
1408
  return;
1401
1409
  }
1402
- logger.log('Stopping Replays');
1403
- this.isEnabled = false;
1404
- this.removeListeners();
1405
- (_a = this.stopRecording) === null || _a === void 0 ? void 0 : _a.call(this);
1406
- (_b = this.eventBuffer) === null || _b === void 0 ? void 0 : _b.destroy();
1407
- this.eventBuffer = null;
1410
+ try {
1411
+ logger.log('Stopping Replays');
1412
+ this.isEnabled = false;
1413
+ this.removeListeners();
1414
+ (_a = this.stopRecording) === null || _a === void 0 ? void 0 : _a.call(this);
1415
+ (_b = this.eventBuffer) === null || _b === void 0 ? void 0 : _b.destroy();
1416
+ this.eventBuffer = null;
1417
+ }
1418
+ catch (err) {
1419
+ logger.error(err);
1420
+ captureInternalException(err);
1421
+ }
1408
1422
  };
1409
1423
  /**
1410
1424
  * Pause some replay functionality. See comments for `isPaused`.
1411
1425
  * This differs from stop as this only stops DOM recording, it is
1412
- * not as thorough of a shutdown as `stop()`. */
1426
+ * not as thorough of a shutdown as `stop()`.
1427
+ */
1413
1428
  Replay.prototype.pause = function () {
1414
1429
  this.isPaused = true;
1415
- if (this.stopRecording) {
1416
- this.stopRecording();
1417
- this.stopRecording = undefined;
1430
+ try {
1431
+ if (this.stopRecording) {
1432
+ this.stopRecording();
1433
+ this.stopRecording = undefined;
1434
+ }
1435
+ }
1436
+ catch (err) {
1437
+ logger.error(err);
1438
+ captureInternalException(err);
1418
1439
  }
1419
1440
  };
1420
1441
  /**
@@ -1428,8 +1449,14 @@ var Replay = /** @class */ (function () {
1428
1449
  this.startRecording();
1429
1450
  };
1430
1451
  Replay.prototype.clearSession = function () {
1431
- deleteSession();
1432
- this.session = undefined;
1452
+ try {
1453
+ deleteSession();
1454
+ this.session = undefined;
1455
+ }
1456
+ catch (err) {
1457
+ logger.error(err);
1458
+ captureInternalException(err);
1459
+ }
1433
1460
  };
1434
1461
  /**
1435
1462
  * Loads a session from storage, or creates a new one if it does not exist or
@@ -1466,10 +1493,8 @@ var Replay = /** @class */ (function () {
1466
1493
  this.performanceEvents = [];
1467
1494
  // Reset context as well
1468
1495
  this.clearContext();
1469
- this.initialState = {
1470
- timestamp: new Date().getTime(),
1471
- url: url,
1472
- };
1496
+ this.context.initialUrl = url;
1497
+ this.context.initialTimestamp = new Date().getTime();
1473
1498
  this.context.urls.push(url);
1474
1499
  };
1475
1500
  /**
@@ -1477,22 +1502,28 @@ var Replay = /** @class */ (function () {
1477
1502
  */
1478
1503
  Replay.prototype.addListeners = function () {
1479
1504
  var _this = this;
1480
- document.addEventListener('visibilitychange', this.handleVisibilityChange);
1481
- window.addEventListener('blur', this.handleWindowBlur);
1482
- window.addEventListener('focus', this.handleWindowFocus);
1483
- // There is no way to remove these listeners, so ensure they are only added once
1484
- if (!this.hasInitializedCoreListeners) {
1485
- // Listeners from core SDK //
1486
- var scope = core.getCurrentHub().getScope();
1487
- scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1488
- utils.addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1489
- utils.addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1490
- utils.addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
1491
- utils.addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
1492
- // Tag all (non replay) events that get sent to Sentry with the current
1493
- // replay ID so that we can reference them later in the UI
1494
- core.addGlobalEventProcessor(this.handleGlobalEvent);
1495
- this.hasInitializedCoreListeners = true;
1505
+ try {
1506
+ document.addEventListener('visibilitychange', this.handleVisibilityChange);
1507
+ window.addEventListener('blur', this.handleWindowBlur);
1508
+ window.addEventListener('focus', this.handleWindowFocus);
1509
+ // There is no way to remove these listeners, so ensure they are only added once
1510
+ if (!this.hasInitializedCoreListeners) {
1511
+ // Listeners from core SDK //
1512
+ var scope = core.getCurrentHub().getScope();
1513
+ scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1514
+ utils.addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1515
+ utils.addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1516
+ utils.addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
1517
+ utils.addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
1518
+ // Tag all (non replay) events that get sent to Sentry with the current
1519
+ // replay ID so that we can reference them later in the UI
1520
+ core.addGlobalEventProcessor(this.handleGlobalEvent);
1521
+ this.hasInitializedCoreListeners = true;
1522
+ }
1523
+ }
1524
+ catch (err) {
1525
+ logger.error(err);
1526
+ captureInternalException(err);
1496
1527
  }
1497
1528
  // PerformanceObserver //
1498
1529
  if (!('PerformanceObserver' in window)) {
@@ -1528,12 +1559,18 @@ var Replay = /** @class */ (function () {
1528
1559
  * Cleans up listeners that were created in `addListeners`
1529
1560
  */
1530
1561
  Replay.prototype.removeListeners = function () {
1531
- document.removeEventListener('visibilitychange', this.handleVisibilityChange);
1532
- window.removeEventListener('blur', this.handleWindowBlur);
1533
- window.removeEventListener('focus', this.handleWindowFocus);
1534
- if (this.performanceObserver) {
1535
- this.performanceObserver.disconnect();
1536
- this.performanceObserver = null;
1562
+ try {
1563
+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);
1564
+ window.removeEventListener('blur', this.handleWindowBlur);
1565
+ window.removeEventListener('focus', this.handleWindowFocus);
1566
+ if (this.performanceObserver) {
1567
+ this.performanceObserver.disconnect();
1568
+ this.performanceObserver = null;
1569
+ }
1570
+ }
1571
+ catch (err) {
1572
+ logger.error(err);
1573
+ captureInternalException(err);
1537
1574
  }
1538
1575
  };
1539
1576
  /**
@@ -1790,6 +1827,7 @@ var Replay = /** @class */ (function () {
1790
1827
  * Clear context
1791
1828
  */
1792
1829
  Replay.prototype.clearContext = function () {
1830
+ // XXX: `initialTimestamp` and `initialUrl` do not get cleared
1793
1831
  this.context.errorIds.clear();
1794
1832
  this.context.traceIds.clear();
1795
1833
  this.context.urls = [];
@@ -1799,14 +1837,13 @@ var Replay = /** @class */ (function () {
1799
1837
  * Return and clear context
1800
1838
  */
1801
1839
  Replay.prototype.popEventContext = function () {
1802
- var initialState = this.initialState;
1803
- if (this.initialState &&
1804
- this.context.earliestEvent &&
1805
- this.context.earliestEvent < this.initialState.timestamp) {
1806
- initialState.timestamp = this.context.earliestEvent;
1840
+ if (this.context.earliestEvent &&
1841
+ this.context.earliestEvent < this.context.initialTimestamp) {
1842
+ this.context.initialTimestamp = this.context.earliestEvent;
1807
1843
  }
1808
1844
  var context = {
1809
- initialState: initialState,
1845
+ initialTimestamp: this.context.initialTimestamp,
1846
+ initialUrl: this.context.initialUrl,
1810
1847
  errorIds: Array.from(this.context.errorIds).filter(Boolean),
1811
1848
  traceIds: Array.from(this.context.traceIds).filter(Boolean),
1812
1849
  urls: this.context.urls,
@@ -1825,7 +1862,7 @@ var Replay = /** @class */ (function () {
1825
1862
  Replay.prototype.runFlush = function () {
1826
1863
  var _a;
1827
1864
  return __awaiter(this, void 0, void 0, function () {
1828
- var recordingData, replayId, segmentId, err_2;
1865
+ var recordingData, replayId, eventContext, segmentId, err_2;
1829
1866
  return __generator(this, function (_b) {
1830
1867
  switch (_b.label) {
1831
1868
  case 0:
@@ -1851,12 +1888,14 @@ var Replay = /** @class */ (function () {
1851
1888
  case 4:
1852
1889
  recordingData = _b.sent();
1853
1890
  replayId = this.session.id;
1891
+ eventContext = this.popEventContext();
1854
1892
  segmentId = this.session.segmentId++;
1855
1893
  return [4 /*yield*/, this.sendReplay({
1856
1894
  replayId: replayId,
1857
1895
  events: recordingData,
1858
1896
  segmentId: segmentId,
1859
1897
  includeReplayStartTimestamp: segmentId === 0,
1898
+ eventContext: eventContext,
1860
1899
  })];
1861
1900
  case 5:
1862
1901
  _b.sent();
@@ -1887,12 +1926,12 @@ var Replay = /** @class */ (function () {
1887
1926
  */
1888
1927
  Replay.prototype.sendReplayRequest = function (_a) {
1889
1928
  var _b;
1890
- var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1929
+ var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp, eventContext = _a.eventContext;
1891
1930
  return __awaiter(this, void 0, void 0, function () {
1892
- var payloadWithSequence, _c, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, client;
1931
+ var payloadWithSequence, urls, errorIds, traceIds, initialTimestamp, currentTimestamp, sdkInfo, replayEvent, envelope, client;
1893
1932
  var _this = this;
1894
- return __generator(this, function (_d) {
1895
- switch (_d.label) {
1933
+ return __generator(this, function (_c) {
1934
+ switch (_c.label) {
1896
1935
  case 0:
1897
1936
  payloadWithSequence = createPayload({
1898
1937
  events: events,
@@ -1900,11 +1939,11 @@ var Replay = /** @class */ (function () {
1900
1939
  segment_id: segment_id,
1901
1940
  },
1902
1941
  });
1903
- _c = this.popEventContext(), urls = _c.urls, errorIds = _c.errorIds, traceIds = _c.traceIds, initialState = _c.initialState;
1904
- timestamp = new Date().getTime();
1942
+ urls = eventContext.urls, errorIds = eventContext.errorIds, traceIds = eventContext.traceIds, initialTimestamp = eventContext.initialTimestamp;
1943
+ currentTimestamp = new Date().getTime();
1905
1944
  sdkInfo = {
1906
1945
  name: 'sentry.javascript.integration.replay',
1907
- version: "0.6.14-3",
1946
+ version: "0.6.14-5",
1908
1947
  };
1909
1948
  return [4 /*yield*/, new Promise(function (resolve) {
1910
1949
  var _a;
@@ -1914,8 +1953,8 @@ var Replay = /** @class */ (function () {
1914
1953
  return __generator(this, function (_b) {
1915
1954
  switch (_b.label) {
1916
1955
  case 0: return [4 /*yield*/, client._prepareEvent(__assign(__assign({ type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
1917
- ? { replay_start_timestamp: initialState.timestamp / 1000 }
1918
- : {})), { timestamp: timestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: event_id, segment_id: segment_id }), { event_id: event_id }, scope)];
1956
+ ? { replay_start_timestamp: initialTimestamp / 1000 }
1957
+ : {})), { timestamp: currentTimestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: event_id, segment_id: segment_id }), { event_id: event_id }, scope)];
1919
1958
  case 1:
1920
1959
  preparedEvent = _b.sent();
1921
1960
  session = scope && scope.getSession();
@@ -1931,7 +1970,7 @@ var Replay = /** @class */ (function () {
1931
1970
  }); });
1932
1971
  })];
1933
1972
  case 1:
1934
- replayEvent = _d.sent();
1973
+ replayEvent = _c.sent();
1935
1974
  envelope = utils.createEnvelope({
1936
1975
  event_id: event_id,
1937
1976
  sent_at: new Date().toISOString(),
@@ -1953,7 +1992,7 @@ var Replay = /** @class */ (function () {
1953
1992
  try {
1954
1993
  return [2 /*return*/, (_b = client === null || client === void 0 ? void 0 : client.getTransport()) === null || _b === void 0 ? void 0 : _b.send(envelope)];
1955
1994
  }
1956
- catch (_e) {
1995
+ catch (_d) {
1957
1996
  throw new Error(UNABLE_TO_SEND_REPLAY);
1958
1997
  }
1959
1998
  return [2 /*return*/];
@@ -1969,14 +2008,14 @@ var Replay = /** @class */ (function () {
1969
2008
  * Finalize and send the current replay event to Sentry
1970
2009
  */
1971
2010
  Replay.prototype.sendReplay = function (_a) {
1972
- var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
2011
+ var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp, eventContext = _a.eventContext;
1973
2012
  return __awaiter(this, void 0, void 0, function () {
1974
2013
  var ex_1;
1975
2014
  var _this = this;
1976
2015
  return __generator(this, function (_b) {
1977
2016
  switch (_b.label) {
1978
2017
  case 0:
1979
- // short circuit if there's no events to upload
2018
+ // short circuit if there's no events to upload (this shouldn't happen as runFlush makes this check)
1980
2019
  if (!events.length) {
1981
2020
  return [2 /*return*/];
1982
2021
  }
@@ -1988,6 +2027,7 @@ var Replay = /** @class */ (function () {
1988
2027
  replayId: replayId,
1989
2028
  segmentId: segmentId,
1990
2029
  includeReplayStartTimestamp: includeReplayStartTimestamp,
2030
+ eventContext: eventContext,
1991
2031
  })];
1992
2032
  case 2:
1993
2033
  _b.sent();
@@ -2021,6 +2061,7 @@ var Replay = /** @class */ (function () {
2021
2061
  events: events,
2022
2062
  segmentId: segmentId,
2023
2063
  includeReplayStartTimestamp: includeReplayStartTimestamp,
2064
+ eventContext: eventContext,
2024
2065
  })];
2025
2066
  case 1:
2026
2067
  _a.sent();