@sentry/replay 0.2.0-15 → 0.2.0-18

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 (79) hide show
  1. package/dist/{jest.config.d.ts → config/dist/jest.config.d.ts} +0 -0
  2. package/dist/{jest.setup.d.ts → config/dist/jest.setup.d.ts} +2 -2
  3. package/dist/config/dist/src/api/captureReplay.d.ts +2 -0
  4. package/dist/config/dist/src/api/captureReplayUpdate.d.ts +2 -0
  5. package/dist/{src → config/dist/src}/coreHandlers/handleDom.d.ts +0 -0
  6. package/dist/{src → config/dist/src}/coreHandlers/handleFetch.d.ts +0 -0
  7. package/dist/{src/eventBuffer.test.d.ts → config/dist/src/coreHandlers/handleScope-unit.test.d.ts} +0 -0
  8. package/dist/config/dist/src/coreHandlers/handleScope.d.ts +3 -0
  9. package/dist/{src/index.test.d.ts → config/dist/src/coreHandlers/handleScope.test.d.ts} +0 -0
  10. package/dist/{src → config/dist/src}/coreHandlers/handleXhr.d.ts +0 -0
  11. package/dist/{src → config/dist/src}/coreHandlers/index.d.ts +0 -0
  12. package/dist/{src → config/dist/src}/createPerformanceEntry.d.ts +0 -0
  13. package/dist/{src → config/dist/src}/eventBuffer.d.ts +1 -6
  14. package/dist/{src/session/createSession.test.d.ts → config/dist/src/eventBuffer.test.d.ts} +0 -0
  15. package/dist/{src → config/dist/src}/flags.d.ts +0 -0
  16. package/dist/{src/session/fetchSession.test.d.ts → config/dist/src/index-noSticky.test.d.ts} +0 -0
  17. package/dist/{src → config/dist/src}/index.d.ts +5 -32
  18. package/dist/{src/session/getSession.test.d.ts → config/dist/src/index.test.d.ts} +0 -0
  19. package/dist/config/dist/src/session/Session.d.ts +46 -0
  20. package/dist/{src/session/saveSession.test.d.ts → config/dist/src/session/Session.test.d.ts} +0 -0
  21. package/dist/{src → config/dist/src}/session/constants.d.ts +1 -1
  22. package/dist/{src → config/dist/src}/session/createSession.d.ts +2 -2
  23. package/dist/{src/session/updateSessionActivity.test.d.ts → config/dist/src/session/createSession.test.d.ts} +0 -0
  24. package/dist/config/dist/src/session/fetchSession.d.ts +2 -0
  25. package/dist/{src/util/isExpired.test.d.ts → config/dist/src/session/fetchSession.test.d.ts} +0 -0
  26. package/dist/{src → config/dist/src}/session/getSession.d.ts +3 -3
  27. package/dist/{src/util/isSessionExpired.test.d.ts → config/dist/src/session/getSession.test.d.ts} +0 -0
  28. package/dist/{src → config/dist/src}/session/index.d.ts +0 -1
  29. package/dist/config/dist/src/session/saveSession.d.ts +2 -0
  30. package/dist/config/dist/src/session/saveSession.test.d.ts +1 -0
  31. package/dist/{src → config/dist/src}/types.d.ts +26 -0
  32. package/dist/{src → config/dist/src}/util/createBreadcrumb.d.ts +0 -0
  33. package/dist/{src → config/dist/src}/util/isExpired.d.ts +0 -0
  34. package/dist/config/dist/src/util/isExpired.test.d.ts +1 -0
  35. package/dist/config/dist/src/util/isIngestHost.d.ts +4 -0
  36. package/dist/config/dist/src/util/isSessionExpired.d.ts +5 -0
  37. package/dist/config/dist/src/util/isSessionExpired.test.d.ts +1 -0
  38. package/dist/config/dist/src/util/logger.d.ts +11 -0
  39. package/dist/config/dist/test/index.d.ts +3 -0
  40. package/dist/config/dist/test/mocks/mockRrweb.d.ts +15 -0
  41. package/dist/config/dist/test/mocks/mockSdk.d.ts +11 -0
  42. package/dist/dist/coreHandlers/handleDom.d.ts +1 -0
  43. package/dist/dist/coreHandlers/handleFetch.d.ts +2 -0
  44. package/dist/dist/coreHandlers/handleScope.d.ts +3 -0
  45. package/dist/dist/coreHandlers/handleXhr.d.ts +2 -0
  46. package/dist/dist/coreHandlers/index.d.ts +4 -0
  47. package/dist/dist/createPerformanceEntry.d.ts +42 -0
  48. package/dist/dist/eventBuffer.d.ts +31 -0
  49. package/dist/dist/flags.d.ts +2 -0
  50. package/dist/dist/index.d.ts +122 -0
  51. package/dist/dist/session/Session.d.ts +46 -0
  52. package/dist/dist/session/constants.d.ts +5 -0
  53. package/dist/dist/session/createSession.d.ts +14 -0
  54. package/dist/dist/session/fetchSession.d.ts +2 -0
  55. package/dist/dist/session/getSession.d.ts +20 -0
  56. package/dist/dist/session/index.d.ts +1 -0
  57. package/dist/dist/session/saveSession.d.ts +2 -0
  58. package/dist/dist/types.d.ts +57 -0
  59. package/dist/dist/util/createBreadcrumb.d.ts +4 -0
  60. package/dist/dist/util/isExpired.d.ts +5 -0
  61. package/dist/dist/util/isIngestHost.d.ts +4 -0
  62. package/dist/dist/util/isSessionExpired.d.ts +5 -0
  63. package/dist/{src → dist}/util/logger.d.ts +0 -0
  64. package/dist/index.es.js +85 -39
  65. package/dist/index.js +85 -39
  66. package/dist/index.js.map +1 -1
  67. package/package.json +12 -9
  68. package/dist/rollup.config.d.ts +0 -3
  69. package/dist/src/coreHandlers/handleScope.d.ts +0 -2
  70. package/dist/src/createMemoryEntry.d.ts +0 -19
  71. package/dist/src/session/fetchSession.d.ts +0 -2
  72. package/dist/src/session/saveSession.d.ts +0 -2
  73. package/dist/src/session/types.d.ts +0 -6
  74. package/dist/src/session/updateSessionActivity.d.ts +0 -3
  75. package/dist/src/util/isSessionExpired.d.ts +0 -5
  76. package/dist/test/index.d.ts +0 -1
  77. package/dist/worker-9d2d4d71.js +0 -7
  78. package/dist/worker-9d2d4d71.js.map +0 -1
  79. package/dist/worker-c801dc28.js +0 -4
@@ -0,0 +1,2 @@
1
+ import { Session } from './Session';
2
+ export declare function fetchSession(): Session | null;
@@ -0,0 +1,20 @@
1
+ import { Session } from './Session';
2
+ interface GetSessionParams {
3
+ /**
4
+ * The length of time (in ms) which we will consider the session to be expired.
5
+ */
6
+ expiry: number;
7
+ /**
8
+ * Should save session to sessionStorage?
9
+ */
10
+ stickySession: boolean;
11
+ /**
12
+ * The current session (e.g. if stickySession is off)
13
+ */
14
+ currentSession?: Session;
15
+ }
16
+ /**
17
+ * Get or create a session
18
+ */
19
+ export declare function getSession({ expiry, currentSession, stickySession, }: GetSessionParams): Session;
20
+ export {};
@@ -0,0 +1 @@
1
+ export * from './createSession';
@@ -0,0 +1,2 @@
1
+ import { Session } from './Session';
2
+ export declare function saveSession(session: Session): void;
@@ -0,0 +1,57 @@
1
+ import type { eventWithTime } from 'rrweb/typings/types';
2
+ import { record } from 'rrweb';
3
+ export declare type RRWebEvent = eventWithTime;
4
+ export declare type RRWebOptions = Parameters<typeof record>[0];
5
+ export interface ReplaySpan {
6
+ description: string;
7
+ op: string;
8
+ startTimestamp: number;
9
+ endTimestamp: number;
10
+ data?: Record<string, unknown>;
11
+ }
12
+ export interface ReplayRequest {
13
+ endpoint: string;
14
+ events: Uint8Array | string;
15
+ }
16
+ export declare type InstrumentationType = 'scope' | 'dom' | 'fetch' | 'xhr';
17
+ /**
18
+ * The request payload to worker
19
+ */
20
+ export interface WorkerRequest {
21
+ method: string;
22
+ args: any[];
23
+ }
24
+ /**
25
+ * The response from the worker
26
+ */
27
+ export interface WorkerResponse {
28
+ method: string;
29
+ success: boolean;
30
+ response: string | Uint8Array;
31
+ }
32
+ export interface SentryReplayPluginOptions {
33
+ /**
34
+ * The amount of time to wait before sending a replay
35
+ */
36
+ uploadMinDelay?: number;
37
+ /**
38
+ * The max amount of time to wait before sending a replay
39
+ */
40
+ uploadMaxDelay?: number;
41
+ /**
42
+ * If false, will create a new session per pageload
43
+ */
44
+ stickySession?: boolean;
45
+ /**
46
+ * Attempt to use compression when web workers are available
47
+ *
48
+ * (default is true)
49
+ */
50
+ useCompression?: boolean;
51
+ }
52
+ export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
53
+ /**
54
+ * Options for `rrweb.recordsetup
55
+ */
56
+ rrwebConfig?: RRWebOptions;
57
+ }
@@ -0,0 +1,4 @@
1
+ import type { Breadcrumb } from '@sentry/types';
2
+ declare type RequiredProperties = 'category' | 'message';
3
+ export default function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
4
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Given an initial timestamp and an expiry duration, checks to see if current
3
+ * time should be considered as expired.
4
+ */
5
+ export declare function isExpired(initialTime: number, expiry: number, targetTime?: number): boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Checks is `targetHost` is a Sentry ingestion host
3
+ */
4
+ export declare function isIngestHost(targetHost: string): boolean;
@@ -0,0 +1,5 @@
1
+ import { Session } from '@/session/Session';
2
+ /**
3
+ * Checks to see if session is expired
4
+ */
5
+ export declare function isSessionExpired(session: Session, expiry: number, targetTime?: number): boolean;
File without changes
package/dist/index.es.js CHANGED
@@ -89,6 +89,14 @@ function __spreadArray(to, from, pack) {
89
89
  return to.concat(ar || Array.prototype.slice.call(from));
90
90
  }
91
91
 
92
+ /**
93
+ * Checks is `targetHost` is a Sentry ingestion host
94
+ */
95
+ function isIngestHost(targetHost) {
96
+ var _a = getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
97
+ return targetHost.startsWith("".concat(protocol, "://").concat(host));
98
+ }
99
+
92
100
  var _a;
93
101
  // Map entryType -> function to normalize data for event
94
102
  var ENTRY_TYPES = (_a = {
@@ -134,11 +142,9 @@ function createNavigationEntry(entry) {
134
142
  };
135
143
  }
136
144
  function createResourceEntry(entry) {
137
- var _a, _b;
138
145
  var entryType = entry.entryType, initiatorType = entry.initiatorType, name = entry.name, responseEnd = entry.responseEnd, startTime = entry.startTime, transferSize = entry.transferSize;
139
146
  // Do not capture fetches to Sentry ingestion endpoint
140
- var _c = ((_b = (_a = getCurrentHub()) === null || _a === void 0 ? void 0 : _a.getClient()) === null || _b === void 0 ? void 0 : _b.getDsn()) || {}, host = _c.host, protocol = _c.protocol;
141
- if (name.startsWith("".concat(protocol, "://").concat(host))) {
147
+ if (isIngestHost(name)) {
142
148
  return null;
143
149
  }
144
150
  return {
@@ -330,10 +336,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
330
336
  var REPLAY_SESSION_KEY = 'sentryReplaySession';
331
337
  var ROOT_REPLAY_NAME = 'sentry-replay';
332
338
  var REPLAY_EVENT_NAME = 'sentry-replay-event';
333
- // Grace period to keep a session when a user changes tabs or hides window
334
- var VISIBILITY_CHANGE_TIMEOUT = 60000; // 1 minute
335
339
  // The idle limit for a session
336
340
  var SESSION_IDLE_DURATION = 900000; // 15 minutes
341
+ // Grace period to keep a session when a user changes tabs or hides window
342
+ var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
337
343
 
338
344
  /**
339
345
  * Given an initial timestamp and an expiry duration, checks to see if current
@@ -373,6 +379,71 @@ function saveSession(session) {
373
379
  }
374
380
  }
375
381
 
382
+ var Session = /** @class */ (function () {
383
+ function Session(session, _a) {
384
+ if (session === void 0) { session = {}; }
385
+ var _b = _a === void 0 ? {} : _a, _c = _b.stickySession, stickySession = _c === void 0 ? false : _c;
386
+ var _d, _e, _f;
387
+ var now = new Date().getTime();
388
+ this._id = session.id || uuid4();
389
+ this._started = (_d = session.started) !== null && _d !== void 0 ? _d : now;
390
+ this._lastActivity = (_e = session.lastActivity) !== null && _e !== void 0 ? _e : now;
391
+ this._sequenceId = (_f = session.sequenceId) !== null && _f !== void 0 ? _f : 0;
392
+ this.options = {
393
+ stickySession: stickySession,
394
+ };
395
+ }
396
+ Object.defineProperty(Session.prototype, "id", {
397
+ get: function () {
398
+ return this._id;
399
+ },
400
+ enumerable: false,
401
+ configurable: true
402
+ });
403
+ Object.defineProperty(Session.prototype, "started", {
404
+ get: function () {
405
+ return this._started;
406
+ },
407
+ enumerable: false,
408
+ configurable: true
409
+ });
410
+ Object.defineProperty(Session.prototype, "lastActivity", {
411
+ get: function () {
412
+ return this._lastActivity;
413
+ },
414
+ set: function (newDate) {
415
+ this._lastActivity = newDate;
416
+ if (this.options.stickySession) {
417
+ saveSession(this);
418
+ }
419
+ },
420
+ enumerable: false,
421
+ configurable: true
422
+ });
423
+ Object.defineProperty(Session.prototype, "sequenceId", {
424
+ get: function () {
425
+ return this._sequenceId;
426
+ },
427
+ set: function (id) {
428
+ this._sequenceId = id;
429
+ if (this.options.stickySession) {
430
+ saveSession(this);
431
+ }
432
+ },
433
+ enumerable: false,
434
+ configurable: true
435
+ });
436
+ Session.prototype.toJSON = function () {
437
+ return {
438
+ id: this.id,
439
+ started: this.started,
440
+ lastActivity: this.lastActivity,
441
+ sequenceId: this._sequenceId,
442
+ };
443
+ };
444
+ return Session;
445
+ }());
446
+
376
447
  /**
377
448
  * Create a new session, which in its current implementation is a Sentry event
378
449
  * that all replays will be saved to as attachments. Currently, we only expect
@@ -380,14 +451,8 @@ function saveSession(session) {
380
451
  */
381
452
  function createSession(_a) {
382
453
  var _b = _a.stickySession, stickySession = _b === void 0 ? false : _b;
383
- var currentDate = new Date().getTime();
384
454
  var hub = getCurrentHub();
385
- var session = {
386
- id: uuid4(),
387
- started: currentDate,
388
- lastActivity: currentDate,
389
- sequenceId: 0,
390
- };
455
+ var session = new Session(undefined, { stickySession: stickySession });
391
456
  hub.captureEvent({
392
457
  message: ROOT_REPLAY_NAME,
393
458
  tags: { sequenceId: session.sequenceId },
@@ -405,7 +470,10 @@ function fetchSession() {
405
470
  return null;
406
471
  }
407
472
  try {
408
- return JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY));
473
+ return new Session(JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
474
+ // We are assuming that if there is a saved item, then the session is sticky,
475
+ // however this could break down if we used a different storage mechanism (e.g. localstorage)
476
+ { stickySession: true });
409
477
  }
410
478
  catch (_a) {
411
479
  return null;
@@ -435,24 +503,6 @@ function getSession(_a) {
435
503
  return newSession;
436
504
  }
437
505
 
438
- function updateSessionActivity(_a) {
439
- var stickySession = _a.stickySession;
440
- // Nothing to do if there are no sticky sessions
441
- if (!stickySession) {
442
- return;
443
- }
444
- var existingSession = fetchSession();
445
- // If user manually deleted from session storage, create a new session
446
- if (!existingSession) {
447
- // TBD: There was an issue here where sessions weren't saving and this
448
- // caused lots of transactions to be created
449
- return createSession({ stickySession: stickySession });
450
- }
451
- var newSession = __assign(__assign({}, existingSession), { lastActivity: new Date().getTime() });
452
- saveSession(newSession);
453
- return newSession;
454
- }
455
-
456
506
  function createBreadcrumb(breadcrumb) {
457
507
  return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
458
508
  }
@@ -522,9 +572,10 @@ function handleXhr(handlerData) {
522
572
  if (!handlerData.endTimestamp) {
523
573
  return null;
524
574
  }
575
+ var _a = handlerData.args, op = _a[0], description = _a[1];
525
576
  return {
526
- description: handlerData.args[1],
527
- op: handlerData.args[0],
577
+ description: description,
578
+ op: op,
528
579
  startTimestamp: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
529
580
  handlerData.endTimestamp / 1000.0,
530
581
  endTimestamp: handlerData.endTimestamp / 1000.0,
@@ -593,9 +644,7 @@ var SentryReplay = /** @class */ (function () {
593
644
  // Update with current timestamp as the last session activity
594
645
  // Only updating session on visibility change to be conservative about
595
646
  // writing to session storage. This could be changed in the future.
596
- _this.updateSession(updateSessionActivity({
597
- stickySession: _this.options.stickySession,
598
- }));
647
+ _this.session.lastActivity = new Date().getTime();
599
648
  // Send replay when the page/tab becomes hidden. There is no reason to send
600
649
  // replay if it becomes visible, since no actions we care about were done
601
650
  // while it was hidden
@@ -784,9 +833,6 @@ var SentryReplay = /** @class */ (function () {
784
833
  currentSession: this.session,
785
834
  });
786
835
  };
787
- SentryReplay.prototype.updateSession = function (session) {
788
- this.session = __assign(__assign({}, this.session), session);
789
- };
790
836
  SentryReplay.prototype.addListeners = function () {
791
837
  var _this = this;
792
838
  document.addEventListener('visibilitychange', this.handleVisibilityChange);
package/dist/index.js CHANGED
@@ -112,6 +112,14 @@ function __spreadArray(to, from, pack) {
112
112
  return to.concat(ar || Array.prototype.slice.call(from));
113
113
  }
114
114
 
115
+ /**
116
+ * Checks is `targetHost` is a Sentry ingestion host
117
+ */
118
+ function isIngestHost(targetHost) {
119
+ var _a = Sentry.getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
120
+ return targetHost.startsWith("".concat(protocol, "://").concat(host));
121
+ }
122
+
115
123
  var _a;
116
124
  // Map entryType -> function to normalize data for event
117
125
  var ENTRY_TYPES = (_a = {
@@ -157,11 +165,9 @@ function createNavigationEntry(entry) {
157
165
  };
158
166
  }
159
167
  function createResourceEntry(entry) {
160
- var _a, _b;
161
168
  var entryType = entry.entryType, initiatorType = entry.initiatorType, name = entry.name, responseEnd = entry.responseEnd, startTime = entry.startTime, transferSize = entry.transferSize;
162
169
  // Do not capture fetches to Sentry ingestion endpoint
163
- var _c = ((_b = (_a = Sentry.getCurrentHub()) === null || _a === void 0 ? void 0 : _a.getClient()) === null || _b === void 0 ? void 0 : _b.getDsn()) || {}, host = _c.host, protocol = _c.protocol;
164
- if (name.startsWith("".concat(protocol, "://").concat(host))) {
170
+ if (isIngestHost(name)) {
165
171
  return null;
166
172
  }
167
173
  return {
@@ -353,10 +359,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
353
359
  var REPLAY_SESSION_KEY = 'sentryReplaySession';
354
360
  var ROOT_REPLAY_NAME = 'sentry-replay';
355
361
  var REPLAY_EVENT_NAME = 'sentry-replay-event';
356
- // Grace period to keep a session when a user changes tabs or hides window
357
- var VISIBILITY_CHANGE_TIMEOUT = 60000; // 1 minute
358
362
  // The idle limit for a session
359
363
  var SESSION_IDLE_DURATION = 900000; // 15 minutes
364
+ // Grace period to keep a session when a user changes tabs or hides window
365
+ var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
360
366
 
361
367
  /**
362
368
  * Given an initial timestamp and an expiry duration, checks to see if current
@@ -396,6 +402,71 @@ function saveSession(session) {
396
402
  }
397
403
  }
398
404
 
405
+ var Session = /** @class */ (function () {
406
+ function Session(session, _a) {
407
+ if (session === void 0) { session = {}; }
408
+ var _b = _a === void 0 ? {} : _a, _c = _b.stickySession, stickySession = _c === void 0 ? false : _c;
409
+ var _d, _e, _f;
410
+ var now = new Date().getTime();
411
+ this._id = session.id || utils.uuid4();
412
+ this._started = (_d = session.started) !== null && _d !== void 0 ? _d : now;
413
+ this._lastActivity = (_e = session.lastActivity) !== null && _e !== void 0 ? _e : now;
414
+ this._sequenceId = (_f = session.sequenceId) !== null && _f !== void 0 ? _f : 0;
415
+ this.options = {
416
+ stickySession: stickySession,
417
+ };
418
+ }
419
+ Object.defineProperty(Session.prototype, "id", {
420
+ get: function () {
421
+ return this._id;
422
+ },
423
+ enumerable: false,
424
+ configurable: true
425
+ });
426
+ Object.defineProperty(Session.prototype, "started", {
427
+ get: function () {
428
+ return this._started;
429
+ },
430
+ enumerable: false,
431
+ configurable: true
432
+ });
433
+ Object.defineProperty(Session.prototype, "lastActivity", {
434
+ get: function () {
435
+ return this._lastActivity;
436
+ },
437
+ set: function (newDate) {
438
+ this._lastActivity = newDate;
439
+ if (this.options.stickySession) {
440
+ saveSession(this);
441
+ }
442
+ },
443
+ enumerable: false,
444
+ configurable: true
445
+ });
446
+ Object.defineProperty(Session.prototype, "sequenceId", {
447
+ get: function () {
448
+ return this._sequenceId;
449
+ },
450
+ set: function (id) {
451
+ this._sequenceId = id;
452
+ if (this.options.stickySession) {
453
+ saveSession(this);
454
+ }
455
+ },
456
+ enumerable: false,
457
+ configurable: true
458
+ });
459
+ Session.prototype.toJSON = function () {
460
+ return {
461
+ id: this.id,
462
+ started: this.started,
463
+ lastActivity: this.lastActivity,
464
+ sequenceId: this._sequenceId,
465
+ };
466
+ };
467
+ return Session;
468
+ }());
469
+
399
470
  /**
400
471
  * Create a new session, which in its current implementation is a Sentry event
401
472
  * that all replays will be saved to as attachments. Currently, we only expect
@@ -403,14 +474,8 @@ function saveSession(session) {
403
474
  */
404
475
  function createSession(_a) {
405
476
  var _b = _a.stickySession, stickySession = _b === void 0 ? false : _b;
406
- var currentDate = new Date().getTime();
407
477
  var hub = Sentry.getCurrentHub();
408
- var session = {
409
- id: utils.uuid4(),
410
- started: currentDate,
411
- lastActivity: currentDate,
412
- sequenceId: 0,
413
- };
478
+ var session = new Session(undefined, { stickySession: stickySession });
414
479
  hub.captureEvent({
415
480
  message: ROOT_REPLAY_NAME,
416
481
  tags: { sequenceId: session.sequenceId },
@@ -428,7 +493,10 @@ function fetchSession() {
428
493
  return null;
429
494
  }
430
495
  try {
431
- return JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY));
496
+ return new Session(JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
497
+ // We are assuming that if there is a saved item, then the session is sticky,
498
+ // however this could break down if we used a different storage mechanism (e.g. localstorage)
499
+ { stickySession: true });
432
500
  }
433
501
  catch (_a) {
434
502
  return null;
@@ -458,24 +526,6 @@ function getSession(_a) {
458
526
  return newSession;
459
527
  }
460
528
 
461
- function updateSessionActivity(_a) {
462
- var stickySession = _a.stickySession;
463
- // Nothing to do if there are no sticky sessions
464
- if (!stickySession) {
465
- return;
466
- }
467
- var existingSession = fetchSession();
468
- // If user manually deleted from session storage, create a new session
469
- if (!existingSession) {
470
- // TBD: There was an issue here where sessions weren't saving and this
471
- // caused lots of transactions to be created
472
- return createSession({ stickySession: stickySession });
473
- }
474
- var newSession = __assign(__assign({}, existingSession), { lastActivity: new Date().getTime() });
475
- saveSession(newSession);
476
- return newSession;
477
- }
478
-
479
529
  function createBreadcrumb(breadcrumb) {
480
530
  return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
481
531
  }
@@ -545,9 +595,10 @@ function handleXhr(handlerData) {
545
595
  if (!handlerData.endTimestamp) {
546
596
  return null;
547
597
  }
598
+ var _a = handlerData.args, op = _a[0], description = _a[1];
548
599
  return {
549
- description: handlerData.args[1],
550
- op: handlerData.args[0],
600
+ description: description,
601
+ op: op,
551
602
  startTimestamp: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
552
603
  handlerData.endTimestamp / 1000.0,
553
604
  endTimestamp: handlerData.endTimestamp / 1000.0,
@@ -616,9 +667,7 @@ var SentryReplay = /** @class */ (function () {
616
667
  // Update with current timestamp as the last session activity
617
668
  // Only updating session on visibility change to be conservative about
618
669
  // writing to session storage. This could be changed in the future.
619
- _this.updateSession(updateSessionActivity({
620
- stickySession: _this.options.stickySession,
621
- }));
670
+ _this.session.lastActivity = new Date().getTime();
622
671
  // Send replay when the page/tab becomes hidden. There is no reason to send
623
672
  // replay if it becomes visible, since no actions we care about were done
624
673
  // while it was hidden
@@ -807,9 +856,6 @@ var SentryReplay = /** @class */ (function () {
807
856
  currentSession: this.session,
808
857
  });
809
858
  };
810
- SentryReplay.prototype.updateSession = function (session) {
811
- this.session = __assign(__assign({}, this.session), session);
812
- };
813
859
  SentryReplay.prototype.addListeners = function () {
814
860
  var _this = this;
815
861
  document.addEventListener('visibilitychange', this.handleVisibilityChange);