@sentry/replay 0.5.8 → 0.5.11

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,7 +36,7 @@ Sentry.init({
36
36
  dsn: '__DSN__',
37
37
  integrations: [
38
38
  new SentryReplay({
39
- stickySession: true, // Default is false
39
+ stickySession: false, // Default is true
40
40
  recordingConfig: {
41
41
  maskAllInputs: false, // Default is true
42
42
  },
@@ -54,7 +54,7 @@ Sentry.init({
54
54
  | `flushMinDelay` | `number` | `5000` | The minimum time to wait (in ms) before sending the recording payload. The payload is sent if `flushMinDelay` ms have elapsed between two events. |
55
55
  | `flushMaxDelay` | `number` | `15000` | The maximum time to wait (in ms) when sending the recording payload. The payload is sent if events occur at an interval less than `flushMinDelay` and `flushMaxDelay` ms have elapsed since the last time a payload was sent. |
56
56
  | `initialFlushDelay` | `number` | `5000` | The amount of time to wait (in ms) before sending the initial recording payload. This helps drop recordings where users visit and close the page quickly. |
57
- | `stickySession` | `boolean` | `false` | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
57
+ | `stickySession` | `boolean` | `true` | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
58
58
  | `useCompression` | `boolean` | `true` | Uses `WebWorkers` (if available) to compress the recording payload before uploading to Sentry. |
59
59
  | `captureOnlyOnError` | `boolean` | `false` | Only capture the recording when an error happens. |
60
60
  | `replaysSamplingRate` | `number` | `1.0` | The rate at which to sample replays. (1.0 will collect all replays, 0 will collect no replays). |
@@ -0,0 +1,15 @@
1
+ import { InitialState } from '@/types';
2
+ export interface CaptureReplayEventParams {
3
+ initialState: InitialState;
4
+ includeReplayStartTimestamp: boolean;
5
+ errorIds: string[];
6
+ replayId: string;
7
+ segmentId: number;
8
+ /**
9
+ * Timestamp of the event in milliseconds
10
+ */
11
+ timestamp: number;
12
+ traceIds: string[];
13
+ urls: string[];
14
+ }
15
+ export declare function captureReplayEvent({ initialState, includeReplayStartTimestamp, errorIds, replayId: replay_id, segmentId: segment_id, timestamp, traceIds, urls, }: CaptureReplayEventParams): void;
@@ -58,8 +58,7 @@ export declare class SentryReplay implements Integration {
58
58
  private initialState;
59
59
  private context;
60
60
  session: Session | undefined;
61
- constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
62
- useCompression, captureOnlyOnError, replaysSamplingRate, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
61
+ constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, useCompression, captureOnlyOnError, replaysSamplingRate, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
63
62
  /**
64
63
  * Because we create a transaction in `setupOnce`, we can potentially create a
65
64
  * transaction before some native SDK integrations have run and applied their
@@ -203,7 +202,7 @@ export declare class SentryReplay implements Integration {
203
202
  /**
204
203
  * Only flush if `captureOnlyOnError` is false.
205
204
  */
206
- conditionalFlush(lastActivity?: number): Promise<void> | undefined;
205
+ conditionalFlush(): Promise<void> | undefined;
207
206
  /**
208
207
  * Return and clear context
209
208
  */
@@ -216,7 +215,7 @@ export declare class SentryReplay implements Integration {
216
215
  * Performance events are only added right before flushing - this is probably
217
216
  * due to the buffered performance observer events.
218
217
  */
219
- flushUpdate(lastActivity?: number): Promise<void>;
218
+ flushUpdate(): Promise<void>;
220
219
  /**
221
220
  * Send replay attachment using `fetch()`
222
221
  */
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Deletes a session from storage
3
+ */
4
+ export declare function deleteSession(): void;
package/dist/index.es.js CHANGED
@@ -263,6 +263,22 @@ function getSpanHandler(type) {
263
263
  return handleHistory;
264
264
  }
265
265
 
266
+ /**
267
+ * Deletes a session from storage
268
+ */
269
+ function deleteSession() {
270
+ var hasSessionStorage = 'sessionStorage' in window;
271
+ if (!hasSessionStorage) {
272
+ return;
273
+ }
274
+ try {
275
+ window.sessionStorage.removeItem(REPLAY_SESSION_KEY);
276
+ }
277
+ catch (_a) {
278
+ // Ignore potential SecurityError exceptions
279
+ }
280
+ }
281
+
266
282
  /**
267
283
  * Given an initial timestamp and an expiry duration, checks to see if current
268
284
  * time should be considered as expired.
@@ -451,7 +467,8 @@ function fetchSession() {
451
467
  */
452
468
  function getSession(_a) {
453
469
  var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession, samplingRate = _a.samplingRate;
454
- var session = stickySession ? fetchSession() : currentSession;
470
+ // If session exists and is passed, use it instead of always hitting session storage
471
+ var session = currentSession || (stickySession && fetchSession());
455
472
  if (session) {
456
473
  // If there is a session, check if it is valid (e.g. "last activity" time should be within the "session idle time")
457
474
  // TODO: We should probably set a max age on this as well
@@ -787,9 +804,7 @@ var SentryReplay = /** @class */ (function () {
787
804
  function SentryReplay(_a) {
788
805
  if (_a === void 0) { _a = {}; }
789
806
  var _this = this;
790
- var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? false : _e, // TBD: Making this opt-in for now
791
- _f = _a.useCompression, // TBD: Making this opt-in for now
792
- useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
807
+ var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
793
808
  /**
794
809
  * @inheritDoc
795
810
  */
@@ -893,8 +908,7 @@ var SentryReplay = /** @class */ (function () {
893
908
  // a previous session ID. In this case, we want to buffer events
894
909
  // for a set amount of time before flushing. This can help avoid
895
910
  // capturing replays of users that immediately close the window.
896
- var now = new Date().getTime();
897
- setTimeout(function () { return _this.conditionalFlush(now); }, _this.options.initialFlushDelay);
911
+ setTimeout(function () { return _this.conditionalFlush(); }, _this.options.initialFlushDelay);
898
912
  return true;
899
913
  });
900
914
  };
@@ -984,11 +998,11 @@ var SentryReplay = /** @class */ (function () {
984
998
  /**
985
999
  * Keep a list of performance entries that will be sent with a replay
986
1000
  */
987
- this.handlePerformanceObserver = function (list
988
- // observer: PerformanceObserver
989
- ) {
990
- var newEntries = list.getEntries();
991
- _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), newEntries, true);
1001
+ this.handlePerformanceObserver = function (list) {
1002
+ // For whatever reason the observer was returning duplicate navigation
1003
+ // entries (the other entry types were not duplicated).
1004
+ var newEntries = new Set(list.getEntries());
1005
+ _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), Array.from(newEntries), true);
992
1006
  };
993
1007
  this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
994
1008
  this.options = {
@@ -1090,7 +1104,7 @@ var SentryReplay = /** @class */ (function () {
1090
1104
  // elapses.
1091
1105
  this.timeout = window.setTimeout(function () {
1092
1106
  logger.log('replay timeout exceeded, finishing replay event');
1093
- _this.flushUpdate(now);
1107
+ _this.flushUpdate();
1094
1108
  }, this.options.flushMinDelay);
1095
1109
  };
1096
1110
  /**
@@ -1101,6 +1115,7 @@ var SentryReplay = /** @class */ (function () {
1101
1115
  this.removeListeners();
1102
1116
  };
1103
1117
  SentryReplay.prototype.clearSession = function () {
1118
+ deleteSession();
1104
1119
  this.session = undefined;
1105
1120
  };
1106
1121
  /**
@@ -1176,10 +1191,16 @@ var SentryReplay = /** @class */ (function () {
1176
1191
  'resource',
1177
1192
  ].forEach(function (type) {
1178
1193
  var _a;
1179
- return (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
1180
- type: type,
1181
- buffered: true,
1182
- });
1194
+ try {
1195
+ (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
1196
+ type: type,
1197
+ buffered: true,
1198
+ });
1199
+ }
1200
+ catch (_b) {
1201
+ // This can throw if an entry type is not supported in the browser.
1202
+ // Ignore these errors.
1203
+ }
1183
1204
  });
1184
1205
  };
1185
1206
  /**
@@ -1355,11 +1376,11 @@ var SentryReplay = /** @class */ (function () {
1355
1376
  /**
1356
1377
  * Only flush if `captureOnlyOnError` is false.
1357
1378
  */
1358
- SentryReplay.prototype.conditionalFlush = function (lastActivity) {
1379
+ SentryReplay.prototype.conditionalFlush = function () {
1359
1380
  if (this.options.captureOnlyOnError) {
1360
1381
  return;
1361
1382
  }
1362
- return this.flushUpdate(lastActivity);
1383
+ return this.flushUpdate();
1363
1384
  };
1364
1385
  /**
1365
1386
  * Return and clear context
@@ -1393,7 +1414,7 @@ var SentryReplay = /** @class */ (function () {
1393
1414
  * Performance events are only added right before flushing - this is probably
1394
1415
  * due to the buffered performance observer events.
1395
1416
  */
1396
- SentryReplay.prototype.flushUpdate = function (lastActivity) {
1417
+ SentryReplay.prototype.flushUpdate = function () {
1397
1418
  var _a;
1398
1419
  return __awaiter(this, void 0, void 0, function () {
1399
1420
  var timestamp, recordingData, err_1;
@@ -1421,7 +1442,7 @@ var SentryReplay = /** @class */ (function () {
1421
1442
  case 2:
1422
1443
  // Only attach memory event if eventBuffer is not empty
1423
1444
  _b.sent();
1424
- timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
1445
+ timestamp = new Date().getTime();
1425
1446
  // Only want to create replay event if session is new
1426
1447
  if (this.needsCaptureReplay) {
1427
1448
  // This event needs to exist before calling `sendReplay`
package/dist/index.js CHANGED
@@ -267,6 +267,22 @@ function getSpanHandler(type) {
267
267
  return handleHistory;
268
268
  }
269
269
 
270
+ /**
271
+ * Deletes a session from storage
272
+ */
273
+ function deleteSession() {
274
+ var hasSessionStorage = 'sessionStorage' in window;
275
+ if (!hasSessionStorage) {
276
+ return;
277
+ }
278
+ try {
279
+ window.sessionStorage.removeItem(REPLAY_SESSION_KEY);
280
+ }
281
+ catch (_a) {
282
+ // Ignore potential SecurityError exceptions
283
+ }
284
+ }
285
+
270
286
  /**
271
287
  * Given an initial timestamp and an expiry duration, checks to see if current
272
288
  * time should be considered as expired.
@@ -455,7 +471,8 @@ function fetchSession() {
455
471
  */
456
472
  function getSession(_a) {
457
473
  var expiry = _a.expiry, currentSession = _a.currentSession, stickySession = _a.stickySession, samplingRate = _a.samplingRate;
458
- var session = stickySession ? fetchSession() : currentSession;
474
+ // If session exists and is passed, use it instead of always hitting session storage
475
+ var session = currentSession || (stickySession && fetchSession());
459
476
  if (session) {
460
477
  // If there is a session, check if it is valid (e.g. "last activity" time should be within the "session idle time")
461
478
  // TODO: We should probably set a max age on this as well
@@ -791,9 +808,7 @@ var SentryReplay = /** @class */ (function () {
791
808
  function SentryReplay(_a) {
792
809
  if (_a === void 0) { _a = {}; }
793
810
  var _this = this;
794
- var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? false : _e, // TBD: Making this opt-in for now
795
- _f = _a.useCompression, // TBD: Making this opt-in for now
796
- useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
811
+ var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
797
812
  /**
798
813
  * @inheritDoc
799
814
  */
@@ -897,8 +912,7 @@ var SentryReplay = /** @class */ (function () {
897
912
  // a previous session ID. In this case, we want to buffer events
898
913
  // for a set amount of time before flushing. This can help avoid
899
914
  // capturing replays of users that immediately close the window.
900
- var now = new Date().getTime();
901
- setTimeout(function () { return _this.conditionalFlush(now); }, _this.options.initialFlushDelay);
915
+ setTimeout(function () { return _this.conditionalFlush(); }, _this.options.initialFlushDelay);
902
916
  return true;
903
917
  });
904
918
  };
@@ -988,11 +1002,11 @@ var SentryReplay = /** @class */ (function () {
988
1002
  /**
989
1003
  * Keep a list of performance entries that will be sent with a replay
990
1004
  */
991
- this.handlePerformanceObserver = function (list
992
- // observer: PerformanceObserver
993
- ) {
994
- var newEntries = list.getEntries();
995
- _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), newEntries, true);
1005
+ this.handlePerformanceObserver = function (list) {
1006
+ // For whatever reason the observer was returning duplicate navigation
1007
+ // entries (the other entry types were not duplicated).
1008
+ var newEntries = new Set(list.getEntries());
1009
+ _this.performanceEvents = __spreadArray(__spreadArray([], _this.performanceEvents, true), Array.from(newEntries), true);
996
1010
  };
997
1011
  this.recordingOptions = __assign({ maskAllInputs: maskAllInputs, blockClass: blockClass, ignoreClass: ignoreClass, maskTextClass: maskTextClass }, recordingOptions);
998
1012
  this.options = {
@@ -1094,7 +1108,7 @@ var SentryReplay = /** @class */ (function () {
1094
1108
  // elapses.
1095
1109
  this.timeout = window.setTimeout(function () {
1096
1110
  logger.log('replay timeout exceeded, finishing replay event');
1097
- _this.flushUpdate(now);
1111
+ _this.flushUpdate();
1098
1112
  }, this.options.flushMinDelay);
1099
1113
  };
1100
1114
  /**
@@ -1105,6 +1119,7 @@ var SentryReplay = /** @class */ (function () {
1105
1119
  this.removeListeners();
1106
1120
  };
1107
1121
  SentryReplay.prototype.clearSession = function () {
1122
+ deleteSession();
1108
1123
  this.session = undefined;
1109
1124
  };
1110
1125
  /**
@@ -1180,10 +1195,16 @@ var SentryReplay = /** @class */ (function () {
1180
1195
  'resource',
1181
1196
  ].forEach(function (type) {
1182
1197
  var _a;
1183
- return (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
1184
- type: type,
1185
- buffered: true,
1186
- });
1198
+ try {
1199
+ (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
1200
+ type: type,
1201
+ buffered: true,
1202
+ });
1203
+ }
1204
+ catch (_b) {
1205
+ // This can throw if an entry type is not supported in the browser.
1206
+ // Ignore these errors.
1207
+ }
1187
1208
  });
1188
1209
  };
1189
1210
  /**
@@ -1359,11 +1380,11 @@ var SentryReplay = /** @class */ (function () {
1359
1380
  /**
1360
1381
  * Only flush if `captureOnlyOnError` is false.
1361
1382
  */
1362
- SentryReplay.prototype.conditionalFlush = function (lastActivity) {
1383
+ SentryReplay.prototype.conditionalFlush = function () {
1363
1384
  if (this.options.captureOnlyOnError) {
1364
1385
  return;
1365
1386
  }
1366
- return this.flushUpdate(lastActivity);
1387
+ return this.flushUpdate();
1367
1388
  };
1368
1389
  /**
1369
1390
  * Return and clear context
@@ -1397,7 +1418,7 @@ var SentryReplay = /** @class */ (function () {
1397
1418
  * Performance events are only added right before flushing - this is probably
1398
1419
  * due to the buffered performance observer events.
1399
1420
  */
1400
- SentryReplay.prototype.flushUpdate = function (lastActivity) {
1421
+ SentryReplay.prototype.flushUpdate = function () {
1401
1422
  var _a;
1402
1423
  return __awaiter(this, void 0, void 0, function () {
1403
1424
  var timestamp, recordingData, err_1;
@@ -1425,7 +1446,7 @@ var SentryReplay = /** @class */ (function () {
1425
1446
  case 2:
1426
1447
  // Only attach memory event if eventBuffer is not empty
1427
1448
  _b.sent();
1428
- timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
1449
+ timestamp = new Date().getTime();
1429
1450
  // Only want to create replay event if session is new
1430
1451
  if (this.needsCaptureReplay) {
1431
1452
  // This event needs to exist before calling `sendReplay`