@sentry/replay 0.6.10-0 → 0.6.10

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 CHANGED
@@ -36,12 +36,33 @@ Sentry.init({
36
36
  // This sets the sample rate to be 10%. You may want this to be 100% while
37
37
  // in development and sample at a lower rate in production
38
38
  replaysSamplingRate: 0.1,
39
+
40
+ // Mask all text content with asterisks (*). Passes text
41
+ // content through to `maskTextFn` before sending to server.
42
+ //
43
+ // Defaults to true, uncomment to change
44
+ // maskAllText: true,
45
+
46
+ // Block all media elements (img, svg, video, object,
47
+ // picture, embed, map, audio)
48
+ //
49
+ // Defaults to true, uncomment to change
50
+ // blockAllMedia: true,
39
51
  })
40
52
  ],
41
53
  // ...
42
54
  });
43
55
  ```
44
56
 
57
+ ### Identifying Users
58
+
59
+ If you have only followed the above instructions to setup session replays, you will only see IP addresses in Sentry's UI. In order to associate a user identity to a session replay, use [`setUser`](https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/).
60
+
61
+ ```javascript
62
+ import * as Sentry from "@sentry/browser";
63
+ Sentry.setUser({ email: "jane.doe@example.com" });
64
+ ```
65
+
45
66
  ### Start and Stop Recording
46
67
 
47
68
  Replay recording only starts automatically when it is included in the `integrations` key when calling `Sentry.init`. Otherwise you can initialize the plugin and manually call the `start()` method on the integration instance. To stop recording you can call the `stop()`.
@@ -30,11 +30,6 @@ export declare class Replay implements Integration {
30
30
  private retryCount;
31
31
  private retryInterval;
32
32
  private debouncedFlush;
33
- /**
34
- * Flag when a new session has been created. Captured replay events behave
35
- * slightly differently in this case: `replay_start_timestamp` is included.
36
- */
37
- private newSessionCreated;
38
33
  private flushLock;
39
34
  /**
40
35
  * Timestamp of the last user activity. This lives across sessions.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine if there is browser support for `navigator.sendBeacon`
3
+ */
4
+ export declare function supportsSendBeacon(): boolean;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentHub, addBreadcrumb, captureException, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
1
+ import { getCurrentHub, captureException, addBreadcrumb, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
2
2
  import { htmlTreeAsString, logger as logger$1, uuid4, browserPerformanceTimeOrigin, addInstrumentationHandler, createEnvelope, serializeEnvelope } from '@sentry/utils';
3
3
  import debounce from 'lodash.debounce';
4
4
  import { record, EventType } from 'rrweb';
@@ -436,6 +436,16 @@ function createSession(_a) {
436
436
  return session;
437
437
  }
438
438
 
439
+ /**
440
+ * Captures exceptions to Sentry only when it occurs on sentry.io
441
+ */
442
+ function captureInternalException(err) {
443
+ if (!isInternal()) {
444
+ return;
445
+ }
446
+ captureException(err);
447
+ }
448
+
439
449
  /**
440
450
  * Fetches a session from storage
441
451
  */
@@ -444,10 +454,17 @@ function fetchSession() {
444
454
  if (!hasSessionStorage) {
445
455
  return null;
446
456
  }
457
+ var sessionStringFromStorage = window.sessionStorage.getItem(REPLAY_SESSION_KEY);
458
+ if (!sessionStringFromStorage) {
459
+ return null;
460
+ }
447
461
  try {
448
- return new Session(
449
- // @ts-expect-error: Type 'null' is not assignable to type 'string'.ts(2345)
450
- JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
462
+ var sessionObj = JSON.parse(sessionStringFromStorage);
463
+ // NOTE: This shouldn't happen
464
+ if (sessionObj.segmentId === 0) {
465
+ captureInternalException(new Error('Session storage object with segmentId = 0'));
466
+ }
467
+ return new Session(sessionObj,
451
468
  // We are assuming that if there is a saved item, then the session is sticky,
452
469
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
453
470
  { stickySession: true });
@@ -492,16 +509,6 @@ function addInternalBreadcrumb(arg) {
492
509
  addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
493
510
  }
494
511
 
495
- /**
496
- * Captures exceptions to Sentry only when it occurs on sentry.io
497
- */
498
- function captureInternalException(err) {
499
- if (!isInternal()) {
500
- return;
501
- }
502
- captureException(err);
503
- }
504
-
505
512
  function createPayload(_a) {
506
513
  var events = _a.events, headers = _a.headers;
507
514
  var payloadWithSequence;
@@ -914,11 +921,6 @@ var Replay = /** @class */ (function () {
914
921
  this.performanceObserver = null;
915
922
  this.retryCount = 0;
916
923
  this.retryInterval = BASE_RETRY_INTERVAL;
917
- /**
918
- * Flag when a new session has been created. Captured replay events behave
919
- * slightly differently in this case: `replay_start_timestamp` is included.
920
- */
921
- this.newSessionCreated = false;
922
924
  this.flushLock = null;
923
925
  /**
924
926
  * Timestamp of the last user activity. This lives across sessions.
@@ -1350,7 +1352,6 @@ var Replay = /** @class */ (function () {
1350
1352
  // If session was newly created (i.e. was not loaded from storage), then
1351
1353
  // enable flag to create the root replay
1352
1354
  if (type === 'new') {
1353
- this.newSessionCreated = true;
1354
1355
  this.setInitialState();
1355
1356
  }
1356
1357
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1510,6 +1511,7 @@ var Replay = /** @class */ (function () {
1510
1511
  * Add an event to the event buffer
1511
1512
  */
1512
1513
  Replay.prototype.addEvent = function (event, isCheckout) {
1514
+ var _a;
1513
1515
  if (!this.eventBuffer) {
1514
1516
  // This implies that `isEnabled` is false
1515
1517
  return;
@@ -1531,7 +1533,7 @@ var Replay = /** @class */ (function () {
1531
1533
  }
1532
1534
  // Only record earliest event if a new session was created, otherwise it
1533
1535
  // shouldn't be relevant
1534
- if (this.newSessionCreated &&
1536
+ if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.segmentId) === 0 &&
1535
1537
  (!this.context.earliestEvent ||
1536
1538
  timestampInMs < this.context.earliestEvent)) {
1537
1539
  this.context.earliestEvent = timestampInMs;
@@ -1726,7 +1728,7 @@ var Replay = /** @class */ (function () {
1726
1728
  Replay.prototype.runFlush = function () {
1727
1729
  var _a;
1728
1730
  return __awaiter(this, void 0, void 0, function () {
1729
- var replayId, newSessionCreated, segmentId, recordingData, err_2;
1731
+ var replayId, segmentId, recordingData, err_2;
1730
1732
  return __generator(this, function (_b) {
1731
1733
  switch (_b.label) {
1732
1734
  case 0:
@@ -1746,7 +1748,6 @@ var Replay = /** @class */ (function () {
1746
1748
  // Only attach memory event if eventBuffer is not empty
1747
1749
  _b.sent();
1748
1750
  replayId = this.session.id;
1749
- newSessionCreated = this.newSessionCreated;
1750
1751
  segmentId = this.session.segmentId++;
1751
1752
  _b.label = 3;
1752
1753
  case 3:
@@ -1758,11 +1759,10 @@ var Replay = /** @class */ (function () {
1758
1759
  replayId: replayId,
1759
1760
  events: recordingData,
1760
1761
  segmentId: segmentId,
1761
- includeReplayStartTimestamp: newSessionCreated,
1762
+ includeReplayStartTimestamp: segmentId === 0,
1762
1763
  })];
1763
1764
  case 5:
1764
1765
  _b.sent();
1765
- this.newSessionCreated = false;
1766
1766
  return [3 /*break*/, 7];
1767
1767
  case 6:
1768
1768
  err_2 = _b.sent();
@@ -1807,7 +1807,7 @@ var Replay = /** @class */ (function () {
1807
1807
  timestamp = new Date().getTime();
1808
1808
  sdkInfo = {
1809
1809
  name: 'sentry.javascript.integration.replay',
1810
- version: "0.6.10-0",
1810
+ version: "0.6.10",
1811
1811
  };
1812
1812
  return [4 /*yield*/, new Promise(function (resolve) {
1813
1813
  var _a;
package/dist/index.js CHANGED
@@ -444,6 +444,16 @@ function createSession(_a) {
444
444
  return session;
445
445
  }
446
446
 
447
+ /**
448
+ * Captures exceptions to Sentry only when it occurs on sentry.io
449
+ */
450
+ function captureInternalException(err) {
451
+ if (!isInternal()) {
452
+ return;
453
+ }
454
+ core.captureException(err);
455
+ }
456
+
447
457
  /**
448
458
  * Fetches a session from storage
449
459
  */
@@ -452,10 +462,17 @@ function fetchSession() {
452
462
  if (!hasSessionStorage) {
453
463
  return null;
454
464
  }
465
+ var sessionStringFromStorage = window.sessionStorage.getItem(REPLAY_SESSION_KEY);
466
+ if (!sessionStringFromStorage) {
467
+ return null;
468
+ }
455
469
  try {
456
- return new Session(
457
- // @ts-expect-error: Type 'null' is not assignable to type 'string'.ts(2345)
458
- JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
470
+ var sessionObj = JSON.parse(sessionStringFromStorage);
471
+ // NOTE: This shouldn't happen
472
+ if (sessionObj.segmentId === 0) {
473
+ captureInternalException(new Error('Session storage object with segmentId = 0'));
474
+ }
475
+ return new Session(sessionObj,
459
476
  // We are assuming that if there is a saved item, then the session is sticky,
460
477
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
461
478
  { stickySession: true });
@@ -500,16 +517,6 @@ function addInternalBreadcrumb(arg) {
500
517
  core.addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
501
518
  }
502
519
 
503
- /**
504
- * Captures exceptions to Sentry only when it occurs on sentry.io
505
- */
506
- function captureInternalException(err) {
507
- if (!isInternal()) {
508
- return;
509
- }
510
- core.captureException(err);
511
- }
512
-
513
520
  function createPayload(_a) {
514
521
  var events = _a.events, headers = _a.headers;
515
522
  var payloadWithSequence;
@@ -922,11 +929,6 @@ var Replay = /** @class */ (function () {
922
929
  this.performanceObserver = null;
923
930
  this.retryCount = 0;
924
931
  this.retryInterval = BASE_RETRY_INTERVAL;
925
- /**
926
- * Flag when a new session has been created. Captured replay events behave
927
- * slightly differently in this case: `replay_start_timestamp` is included.
928
- */
929
- this.newSessionCreated = false;
930
932
  this.flushLock = null;
931
933
  /**
932
934
  * Timestamp of the last user activity. This lives across sessions.
@@ -1358,7 +1360,6 @@ var Replay = /** @class */ (function () {
1358
1360
  // If session was newly created (i.e. was not loaded from storage), then
1359
1361
  // enable flag to create the root replay
1360
1362
  if (type === 'new') {
1361
- this.newSessionCreated = true;
1362
1363
  this.setInitialState();
1363
1364
  }
1364
1365
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1518,6 +1519,7 @@ var Replay = /** @class */ (function () {
1518
1519
  * Add an event to the event buffer
1519
1520
  */
1520
1521
  Replay.prototype.addEvent = function (event, isCheckout) {
1522
+ var _a;
1521
1523
  if (!this.eventBuffer) {
1522
1524
  // This implies that `isEnabled` is false
1523
1525
  return;
@@ -1539,7 +1541,7 @@ var Replay = /** @class */ (function () {
1539
1541
  }
1540
1542
  // Only record earliest event if a new session was created, otherwise it
1541
1543
  // shouldn't be relevant
1542
- if (this.newSessionCreated &&
1544
+ if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.segmentId) === 0 &&
1543
1545
  (!this.context.earliestEvent ||
1544
1546
  timestampInMs < this.context.earliestEvent)) {
1545
1547
  this.context.earliestEvent = timestampInMs;
@@ -1734,7 +1736,7 @@ var Replay = /** @class */ (function () {
1734
1736
  Replay.prototype.runFlush = function () {
1735
1737
  var _a;
1736
1738
  return __awaiter(this, void 0, void 0, function () {
1737
- var replayId, newSessionCreated, segmentId, recordingData, err_2;
1739
+ var replayId, segmentId, recordingData, err_2;
1738
1740
  return __generator(this, function (_b) {
1739
1741
  switch (_b.label) {
1740
1742
  case 0:
@@ -1754,7 +1756,6 @@ var Replay = /** @class */ (function () {
1754
1756
  // Only attach memory event if eventBuffer is not empty
1755
1757
  _b.sent();
1756
1758
  replayId = this.session.id;
1757
- newSessionCreated = this.newSessionCreated;
1758
1759
  segmentId = this.session.segmentId++;
1759
1760
  _b.label = 3;
1760
1761
  case 3:
@@ -1766,11 +1767,10 @@ var Replay = /** @class */ (function () {
1766
1767
  replayId: replayId,
1767
1768
  events: recordingData,
1768
1769
  segmentId: segmentId,
1769
- includeReplayStartTimestamp: newSessionCreated,
1770
+ includeReplayStartTimestamp: segmentId === 0,
1770
1771
  })];
1771
1772
  case 5:
1772
1773
  _b.sent();
1773
- this.newSessionCreated = false;
1774
1774
  return [3 /*break*/, 7];
1775
1775
  case 6:
1776
1776
  err_2 = _b.sent();
@@ -1815,7 +1815,7 @@ var Replay = /** @class */ (function () {
1815
1815
  timestamp = new Date().getTime();
1816
1816
  sdkInfo = {
1817
1817
  name: 'sentry.javascript.integration.replay',
1818
- version: "0.6.10-0",
1818
+ version: "0.6.10",
1819
1819
  };
1820
1820
  return [4 /*yield*/, new Promise(function (resolve) {
1821
1821
  var _a;