@sentry/replay 0.6.14-2 → 0.6.14-4

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 (70) hide show
  1. package/LICENSE +11 -198
  2. package/README.md +1 -1
  3. package/dist/index.es.js +46 -43
  4. package/dist/index.js +46 -43
  5. package/dist/index.js.map +1 -1
  6. package/dist/types/src/index.d.ts +17 -23
  7. package/dist/types/src/types.d.ts +25 -11
  8. package/package.json +3 -3
  9. package/dist/config/types/jest.config.d.ts +0 -3
  10. package/dist/config/types/jest.setup.d.ts +0 -32
  11. package/dist/config/types/src/blockAllMedia.test.d.ts +0 -1
  12. package/dist/config/types/src/coreHandlers/getBreadcrumbHandler.d.ts +0 -3
  13. package/dist/config/types/src/coreHandlers/getSpanHandler.d.ts +0 -5
  14. package/dist/config/types/src/coreHandlers/handleDom.d.ts +0 -1
  15. package/dist/config/types/src/coreHandlers/handleFetch.d.ts +0 -19
  16. package/dist/config/types/src/coreHandlers/handleFetch.test.d.ts +0 -1
  17. package/dist/config/types/src/coreHandlers/handleHistory.d.ts +0 -7
  18. package/dist/config/types/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  19. package/dist/config/types/src/coreHandlers/handleScope.d.ts +0 -2
  20. package/dist/config/types/src/coreHandlers/handleScope.test.d.ts +0 -1
  21. package/dist/config/types/src/coreHandlers/handleXhr.d.ts +0 -21
  22. package/dist/config/types/src/createPerformanceEntry.d.ts +0 -43
  23. package/dist/config/types/src/createPerformanceEntry.test.d.ts +0 -1
  24. package/dist/config/types/src/eventBuffer.d.ts +0 -45
  25. package/dist/config/types/src/eventBuffer.test.d.ts +0 -1
  26. package/dist/config/types/src/flags.d.ts +0 -2
  27. package/dist/config/types/src/flush.test.d.ts +0 -1
  28. package/dist/config/types/src/index-errorSampleRate.test.d.ts +0 -1
  29. package/dist/config/types/src/index-noSticky.test.d.ts +0 -1
  30. package/dist/config/types/src/index-sampling.test.d.ts +0 -1
  31. package/dist/config/types/src/index.d.ts +0 -288
  32. package/dist/config/types/src/index.test.d.ts +0 -1
  33. package/dist/config/types/src/multiple-instances.test.d.ts +0 -1
  34. package/dist/config/types/src/session/Session.d.ts +0 -63
  35. package/dist/config/types/src/session/Session.test.d.ts +0 -1
  36. package/dist/config/types/src/session/constants.d.ts +0 -11
  37. package/dist/config/types/src/session/createSession.d.ts +0 -8
  38. package/dist/config/types/src/session/createSession.test.d.ts +0 -1
  39. package/dist/config/types/src/session/deleteSession.d.ts +0 -4
  40. package/dist/config/types/src/session/deleteSession.test.d.ts +0 -1
  41. package/dist/config/types/src/session/fetchSession.d.ts +0 -6
  42. package/dist/config/types/src/session/fetchSession.test.d.ts +0 -1
  43. package/dist/config/types/src/session/getSession.d.ts +0 -20
  44. package/dist/config/types/src/session/getSession.test.d.ts +0 -1
  45. package/dist/config/types/src/session/index.d.ts +0 -1
  46. package/dist/config/types/src/session/saveSession.d.ts +0 -2
  47. package/dist/config/types/src/session/saveSession.test.d.ts +0 -1
  48. package/dist/config/types/src/stop.test.d.ts +0 -1
  49. package/dist/config/types/src/types.d.ts +0 -130
  50. package/dist/config/types/src/util/addInternalBreadcrumb.d.ts +0 -5
  51. package/dist/config/types/src/util/captureInternalException.d.ts +0 -4
  52. package/dist/config/types/src/util/createBreadcrumb.d.ts +0 -4
  53. package/dist/config/types/src/util/createPayload.d.ts +0 -5
  54. package/dist/config/types/src/util/dedupePerformanceEntries.d.ts +0 -10
  55. package/dist/config/types/src/util/dedupePerformanceEntries.test.d.ts +0 -1
  56. package/dist/config/types/src/util/isExpired.d.ts +0 -5
  57. package/dist/config/types/src/util/isExpired.test.d.ts +0 -1
  58. package/dist/config/types/src/util/isIngestHost.d.ts +0 -4
  59. package/dist/config/types/src/util/isInternal.d.ts +0 -5
  60. package/dist/config/types/src/util/isSampled.d.ts +0 -7
  61. package/dist/config/types/src/util/isSampled.test.d.ts +0 -1
  62. package/dist/config/types/src/util/isSessionExpired.d.ts +0 -5
  63. package/dist/config/types/src/util/isSessionExpired.test.d.ts +0 -1
  64. package/dist/config/types/src/util/logger.d.ts +0 -12
  65. package/dist/config/types/test/fixtures/performanceEntry/lcp.d.ts +0 -1
  66. package/dist/config/types/test/fixtures/performanceEntry/navigation.d.ts +0 -1
  67. package/dist/config/types/test/fixtures/performanceEntry/resource.d.ts +0 -1
  68. package/dist/config/types/test/index.d.ts +0 -3
  69. package/dist/config/types/test/mocks/mockRrweb.d.ts +0 -15
  70. 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]
@@ -1157,7 +1159,6 @@ var Replay = /** @class */ (function () {
1157
1159
  * Handler for Sentry Core SDK events.
1158
1160
  *
1159
1161
  * These specific events will create span-like objects in the recording.
1160
- *
1161
1162
  */
1162
1163
  this.handleCoreSpanListener = function (type) { return function (handlerData) {
1163
1164
  if (!_this.isEnabled) {
@@ -1171,7 +1172,6 @@ var Replay = /** @class */ (function () {
1171
1172
  if (type === 'history') {
1172
1173
  // Need to collect visited URLs
1173
1174
  _this.context.urls.push(result.name);
1174
- _this.updateUserActivity();
1175
1175
  _this.triggerUserActivity();
1176
1176
  }
1177
1177
  _this.addUpdate(function () {
@@ -1327,13 +1327,14 @@ var Replay = /** @class */ (function () {
1327
1327
  _initialized = true;
1328
1328
  }
1329
1329
  /**
1330
- * Because we create a transaction in `setupOnce`, we can potentially create a
1331
- * transaction before some native SDK integrations have run and applied their
1332
- * own global event processor. An example is:
1330
+ * We previously used to create a transaction in `setupOnce` and it would
1331
+ * potentially create a transaction before some native SDK integrations have run
1332
+ * and applied their own global event processor. An example is:
1333
1333
  * https://github.com/getsentry/sentry-javascript/blob/b47ceafbdac7f8b99093ce6023726ad4687edc48/packages/browser/src/integrations/useragent.ts
1334
1334
  *
1335
- * So we call `this.setup` in next event loop as a workaround to wait for
1336
- * other global event processors to finish
1335
+ * So we call `this.setup` in next event loop as a workaround to wait for other
1336
+ * global event processors to finish. This is no longer needed, but keeping it
1337
+ * here to avoid any future issues.
1337
1338
  */
1338
1339
  Replay.prototype.setupOnce = function () {
1339
1340
  var _this = this;
@@ -1346,7 +1347,8 @@ var Replay = /** @class */ (function () {
1346
1347
  /**
1347
1348
  * Initializes the plugin.
1348
1349
  *
1349
- * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
1350
+ * Creates or loads a session, attaches listeners to varying events (DOM,
1351
+ * PerformanceObserver, Recording, Sentry SDK, etc)
1350
1352
  */
1351
1353
  Replay.prototype.start = function () {
1352
1354
  if (!isBrowser) {
@@ -1391,7 +1393,8 @@ var Replay = /** @class */ (function () {
1391
1393
  this.stopRecording = rrweb.record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1392
1394
  };
1393
1395
  /**
1394
- * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
1396
+ * Currently, this needs to be manually called (e.g. for tests). Sentry SDK
1397
+ * does not support a teardown
1395
1398
  */
1396
1399
  Replay.prototype.stop = function () {
1397
1400
  var _a, _b;
@@ -1465,10 +1468,8 @@ var Replay = /** @class */ (function () {
1465
1468
  this.performanceEvents = [];
1466
1469
  // Reset context as well
1467
1470
  this.clearContext();
1468
- this.initialState = {
1469
- timestamp: new Date().getTime(),
1470
- url: url,
1471
- };
1471
+ this.context.initialUrl = url;
1472
+ this.context.initialTimestamp = new Date().getTime();
1472
1473
  this.context.urls.push(url);
1473
1474
  };
1474
1475
  /**
@@ -1655,8 +1656,9 @@ var Replay = /** @class */ (function () {
1655
1656
  }
1656
1657
  };
1657
1658
  /**
1658
- * Updates the user activity timestamp and resumes recording. This should be called in an event handler for a user action that we consider as the user being "active" (e.g. a mouse click).
1659
- *
1659
+ * Updates the user activity timestamp and resumes recording. This should be
1660
+ * called in an event handler for a user action that we consider as the user
1661
+ * being "active" (e.g. a mouse click).
1660
1662
  */
1661
1663
  Replay.prototype.triggerUserActivity = function () {
1662
1664
  return __awaiter(this, void 0, void 0, function () {
@@ -1665,7 +1667,8 @@ var Replay = /** @class */ (function () {
1665
1667
  // This case means that recording was once stopped due to inactivity.
1666
1668
  // Ensure that recording is resumed.
1667
1669
  if (!this.stopRecording) {
1668
- // Create a new session, otherwise when the user action is flushed, it will get rejected due to an expired session.
1670
+ // Create a new session, otherwise when the user action is flushed, it
1671
+ // will get rejected due to an expired session.
1669
1672
  this.loadSession({ expiry: SESSION_IDLE_DURATION });
1670
1673
  // Note: This will cause a new DOM checkout
1671
1674
  this.resume();
@@ -1770,11 +1773,7 @@ var Replay = /** @class */ (function () {
1770
1773
  if (!expired) {
1771
1774
  return true;
1772
1775
  }
1773
- // TODO: We could potentially figure out a way to save the last session,
1774
- // and produce a checkout based on a previous checkout + updates, and then
1775
- // replay the event on top. Or maybe replay the event on top of a refresh
1776
- // snapshot.
1777
- // For now create a new snapshot
1776
+ // Session is expired, trigger a full snapshot (which will create a new session)
1778
1777
  this.triggerFullSnapshot();
1779
1778
  return false;
1780
1779
  };
@@ -1791,6 +1790,7 @@ var Replay = /** @class */ (function () {
1791
1790
  * Clear context
1792
1791
  */
1793
1792
  Replay.prototype.clearContext = function () {
1793
+ // XXX: `initialTimestamp` and `initialUrl` do not get cleared
1794
1794
  this.context.errorIds.clear();
1795
1795
  this.context.traceIds.clear();
1796
1796
  this.context.urls = [];
@@ -1800,14 +1800,13 @@ var Replay = /** @class */ (function () {
1800
1800
  * Return and clear context
1801
1801
  */
1802
1802
  Replay.prototype.popEventContext = function () {
1803
- var initialState = this.initialState;
1804
- if (this.initialState &&
1805
- this.context.earliestEvent &&
1806
- this.context.earliestEvent < this.initialState.timestamp) {
1807
- initialState.timestamp = this.context.earliestEvent;
1803
+ if (this.context.earliestEvent &&
1804
+ this.context.earliestEvent < this.context.initialTimestamp) {
1805
+ this.context.initialTimestamp = this.context.earliestEvent;
1808
1806
  }
1809
1807
  var context = {
1810
- initialState: initialState,
1808
+ initialTimestamp: this.context.initialTimestamp,
1809
+ initialUrl: this.context.initialUrl,
1811
1810
  errorIds: Array.from(this.context.errorIds).filter(Boolean),
1812
1811
  traceIds: Array.from(this.context.traceIds).filter(Boolean),
1813
1812
  urls: this.context.urls,
@@ -1826,7 +1825,7 @@ var Replay = /** @class */ (function () {
1826
1825
  Replay.prototype.runFlush = function () {
1827
1826
  var _a;
1828
1827
  return __awaiter(this, void 0, void 0, function () {
1829
- var replayId, segmentId, recordingData, err_2;
1828
+ var recordingData, replayId, eventContext, segmentId, err_2;
1830
1829
  return __generator(this, function (_b) {
1831
1830
  switch (_b.label) {
1832
1831
  case 0:
@@ -1845,19 +1844,21 @@ var Replay = /** @class */ (function () {
1845
1844
  case 2:
1846
1845
  // Only attach memory event if eventBuffer is not empty
1847
1846
  _b.sent();
1848
- replayId = this.session.id;
1849
- segmentId = this.session.segmentId++;
1850
1847
  _b.label = 3;
1851
1848
  case 3:
1852
1849
  _b.trys.push([3, 6, , 7]);
1853
1850
  return [4 /*yield*/, this.eventBuffer.finish()];
1854
1851
  case 4:
1855
1852
  recordingData = _b.sent();
1853
+ replayId = this.session.id;
1854
+ eventContext = this.popEventContext();
1855
+ segmentId = this.session.segmentId++;
1856
1856
  return [4 /*yield*/, this.sendReplay({
1857
1857
  replayId: replayId,
1858
1858
  events: recordingData,
1859
1859
  segmentId: segmentId,
1860
1860
  includeReplayStartTimestamp: segmentId === 0,
1861
+ eventContext: eventContext,
1861
1862
  })];
1862
1863
  case 5:
1863
1864
  _b.sent();
@@ -1888,12 +1889,12 @@ var Replay = /** @class */ (function () {
1888
1889
  */
1889
1890
  Replay.prototype.sendReplayRequest = function (_a) {
1890
1891
  var _b;
1891
- var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1892
+ var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp, eventContext = _a.eventContext;
1892
1893
  return __awaiter(this, void 0, void 0, function () {
1893
- var payloadWithSequence, _c, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, client;
1894
+ var payloadWithSequence, urls, errorIds, traceIds, initialTimestamp, currentTimestamp, sdkInfo, replayEvent, envelope, client;
1894
1895
  var _this = this;
1895
- return __generator(this, function (_d) {
1896
- switch (_d.label) {
1896
+ return __generator(this, function (_c) {
1897
+ switch (_c.label) {
1897
1898
  case 0:
1898
1899
  payloadWithSequence = createPayload({
1899
1900
  events: events,
@@ -1901,11 +1902,11 @@ var Replay = /** @class */ (function () {
1901
1902
  segment_id: segment_id,
1902
1903
  },
1903
1904
  });
1904
- _c = this.popEventContext(), urls = _c.urls, errorIds = _c.errorIds, traceIds = _c.traceIds, initialState = _c.initialState;
1905
- timestamp = new Date().getTime();
1905
+ urls = eventContext.urls, errorIds = eventContext.errorIds, traceIds = eventContext.traceIds, initialTimestamp = eventContext.initialTimestamp;
1906
+ currentTimestamp = new Date().getTime();
1906
1907
  sdkInfo = {
1907
1908
  name: 'sentry.javascript.integration.replay',
1908
- version: "0.6.14-2",
1909
+ version: "0.6.14-4",
1909
1910
  };
1910
1911
  return [4 /*yield*/, new Promise(function (resolve) {
1911
1912
  var _a;
@@ -1915,8 +1916,8 @@ var Replay = /** @class */ (function () {
1915
1916
  return __generator(this, function (_b) {
1916
1917
  switch (_b.label) {
1917
1918
  case 0: return [4 /*yield*/, client._prepareEvent(__assign(__assign({ type: REPLAY_EVENT_NAME }, (includeReplayStartTimestamp
1918
- ? { replay_start_timestamp: initialState.timestamp / 1000 }
1919
- : {})), { timestamp: timestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: event_id, segment_id: segment_id }), { event_id: event_id }, scope)];
1919
+ ? { replay_start_timestamp: initialTimestamp / 1000 }
1920
+ : {})), { timestamp: currentTimestamp / 1000, error_ids: errorIds, trace_ids: traceIds, urls: urls, replay_id: event_id, segment_id: segment_id }), { event_id: event_id }, scope)];
1920
1921
  case 1:
1921
1922
  preparedEvent = _b.sent();
1922
1923
  session = scope && scope.getSession();
@@ -1932,7 +1933,7 @@ var Replay = /** @class */ (function () {
1932
1933
  }); });
1933
1934
  })];
1934
1935
  case 1:
1935
- replayEvent = _d.sent();
1936
+ replayEvent = _c.sent();
1936
1937
  envelope = utils.createEnvelope({
1937
1938
  event_id: event_id,
1938
1939
  sent_at: new Date().toISOString(),
@@ -1954,7 +1955,7 @@ var Replay = /** @class */ (function () {
1954
1955
  try {
1955
1956
  return [2 /*return*/, (_b = client === null || client === void 0 ? void 0 : client.getTransport()) === null || _b === void 0 ? void 0 : _b.send(envelope)];
1956
1957
  }
1957
- catch (_e) {
1958
+ catch (_d) {
1958
1959
  throw new Error(UNABLE_TO_SEND_REPLAY);
1959
1960
  }
1960
1961
  return [2 /*return*/];
@@ -1970,14 +1971,14 @@ var Replay = /** @class */ (function () {
1970
1971
  * Finalize and send the current replay event to Sentry
1971
1972
  */
1972
1973
  Replay.prototype.sendReplay = function (_a) {
1973
- var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1974
+ var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp, eventContext = _a.eventContext;
1974
1975
  return __awaiter(this, void 0, void 0, function () {
1975
1976
  var ex_1;
1976
1977
  var _this = this;
1977
1978
  return __generator(this, function (_b) {
1978
1979
  switch (_b.label) {
1979
1980
  case 0:
1980
- // short circuit if there's no events to upload
1981
+ // short circuit if there's no events to upload (this shouldn't happen as runFlush makes this check)
1981
1982
  if (!events.length) {
1982
1983
  return [2 /*return*/];
1983
1984
  }
@@ -1989,6 +1990,7 @@ var Replay = /** @class */ (function () {
1989
1990
  replayId: replayId,
1990
1991
  segmentId: segmentId,
1991
1992
  includeReplayStartTimestamp: includeReplayStartTimestamp,
1993
+ eventContext: eventContext,
1992
1994
  })];
1993
1995
  case 2:
1994
1996
  _b.sent();
@@ -2022,6 +2024,7 @@ var Replay = /** @class */ (function () {
2022
2024
  events: events,
2023
2025
  segmentId: segmentId,
2024
2026
  includeReplayStartTimestamp: includeReplayStartTimestamp,
2027
+ eventContext: eventContext,
2025
2028
  })];
2026
2029
  case 1:
2027
2030
  _a.sent();