@sentry/replay 0.4.7 → 0.4.8-2

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 (111) hide show
  1. package/dist/dist/api/captureReplay.d.ts +6 -1
  2. package/dist/dist/api/captureReplayUpdate.d.ts +9 -1
  3. package/dist/dist/eventBuffer.d.ts +1 -1
  4. package/dist/index.es.js +33 -22
  5. package/dist/index.js +32 -21
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/dist/esm/index.js +0 -1454
  9. package/dist/esm/worker-aa3eb59a.js +0 -4
  10. package/dist/jest.config.d.ts +0 -3
  11. package/dist/jest.setup.d.ts +0 -10
  12. package/dist/src/api/captureReplay.d.ts +0 -3
  13. package/dist/src/api/captureReplayUpdate.d.ts +0 -2
  14. package/dist/src/coreHandlers/handleDom.d.ts +0 -1
  15. package/dist/src/coreHandlers/handleFetch.d.ts +0 -2
  16. package/dist/src/coreHandlers/handleFetch.test.d.ts +0 -1
  17. package/dist/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  18. package/dist/src/coreHandlers/handleScope.d.ts +0 -2
  19. package/dist/src/coreHandlers/handleScope.test.d.ts +0 -1
  20. package/dist/src/coreHandlers/handleXhr.d.ts +0 -2
  21. package/dist/src/coreHandlers/index.d.ts +0 -4
  22. package/dist/src/createPerformanceEntry.d.ts +0 -42
  23. package/dist/src/createPerformanceEntry.test.d.ts +0 -1
  24. package/dist/src/eventBuffer.d.ts +0 -31
  25. package/dist/src/eventBuffer.test.d.ts +0 -1
  26. package/dist/src/flags.d.ts +0 -2
  27. package/dist/src/index-captureOnlyOnError.test.d.ts +0 -1
  28. package/dist/src/index-noSticky.test.d.ts +0 -1
  29. package/dist/src/index-sampling.test.d.ts +0 -1
  30. package/dist/src/index.d.ts +0 -213
  31. package/dist/src/index.test.d.ts +0 -1
  32. package/dist/src/session/Session.d.ts +0 -63
  33. package/dist/src/session/Session.test.d.ts +0 -1
  34. package/dist/src/session/constants.d.ts +0 -5
  35. package/dist/src/session/createSession.d.ts +0 -19
  36. package/dist/src/session/createSession.test.d.ts +0 -1
  37. package/dist/src/session/fetchSession.d.ts +0 -5
  38. package/dist/src/session/fetchSession.test.d.ts +0 -1
  39. package/dist/src/session/getSession.d.ts +0 -28
  40. package/dist/src/session/getSession.test.d.ts +0 -1
  41. package/dist/src/session/index.d.ts +0 -1
  42. package/dist/src/session/saveSession.d.ts +0 -2
  43. package/dist/src/session/saveSession.test.d.ts +0 -1
  44. package/dist/src/types.d.ts +0 -76
  45. package/dist/src/util/createBreadcrumb.d.ts +0 -4
  46. package/dist/src/util/isExpired.d.ts +0 -5
  47. package/dist/src/util/isExpired.test.d.ts +0 -1
  48. package/dist/src/util/isIngestHost.d.ts +0 -4
  49. package/dist/src/util/isSampled.d.ts +0 -7
  50. package/dist/src/util/isSampled.test.d.ts +0 -1
  51. package/dist/src/util/isSessionExpired.d.ts +0 -5
  52. package/dist/src/util/isSessionExpired.test.d.ts +0 -1
  53. package/dist/src/util/logger.d.ts +0 -12
  54. package/dist/src/util/supportsSendBeacon.d.ts +0 -4
  55. package/dist/test/index.d.ts +0 -3
  56. package/dist/test/mocks/mockRrweb.d.ts +0 -15
  57. package/dist/test/mocks/mockSdk.d.ts +0 -11
  58. package/dist/types/jest.config.d.ts +0 -3
  59. package/dist/types/jest.setup.d.ts +0 -10
  60. package/dist/types/src/api/captureReplay.d.ts +0 -3
  61. package/dist/types/src/api/captureReplayUpdate.d.ts +0 -2
  62. package/dist/types/src/coreHandlers/handleDom.d.ts +0 -1
  63. package/dist/types/src/coreHandlers/handleFetch.d.ts +0 -2
  64. package/dist/types/src/coreHandlers/handleFetch.test.d.ts +0 -1
  65. package/dist/types/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  66. package/dist/types/src/coreHandlers/handleScope.d.ts +0 -2
  67. package/dist/types/src/coreHandlers/handleScope.test.d.ts +0 -1
  68. package/dist/types/src/coreHandlers/handleXhr.d.ts +0 -2
  69. package/dist/types/src/coreHandlers/index.d.ts +0 -4
  70. package/dist/types/src/createPerformanceEntry.d.ts +0 -42
  71. package/dist/types/src/createPerformanceEntry.test.d.ts +0 -1
  72. package/dist/types/src/eventBuffer.d.ts +0 -31
  73. package/dist/types/src/eventBuffer.test.d.ts +0 -1
  74. package/dist/types/src/flags.d.ts +0 -2
  75. package/dist/types/src/index-captureOnlyOnError.test.d.ts +0 -1
  76. package/dist/types/src/index-noSticky.test.d.ts +0 -1
  77. package/dist/types/src/index-sampling.test.d.ts +0 -1
  78. package/dist/types/src/index.d.ts +0 -209
  79. package/dist/types/src/index.test.d.ts +0 -1
  80. package/dist/types/src/session/Session.d.ts +0 -63
  81. package/dist/types/src/session/Session.test.d.ts +0 -1
  82. package/dist/types/src/session/constants.d.ts +0 -5
  83. package/dist/types/src/session/createSession.d.ts +0 -19
  84. package/dist/types/src/session/createSession.test.d.ts +0 -1
  85. package/dist/types/src/session/fetchSession.d.ts +0 -5
  86. package/dist/types/src/session/fetchSession.test.d.ts +0 -1
  87. package/dist/types/src/session/getSession.d.ts +0 -28
  88. package/dist/types/src/session/getSession.test.d.ts +0 -1
  89. package/dist/types/src/session/index.d.ts +0 -1
  90. package/dist/types/src/session/saveSession.d.ts +0 -2
  91. package/dist/types/src/session/saveSession.test.d.ts +0 -1
  92. package/dist/types/src/session/types.d.ts +0 -0
  93. package/dist/types/src/types.d.ts +0 -76
  94. package/dist/types/src/util/createBreadcrumb.d.ts +0 -4
  95. package/dist/types/src/util/isExpired.d.ts +0 -5
  96. package/dist/types/src/util/isExpired.test.d.ts +0 -1
  97. package/dist/types/src/util/isIngestHost.d.ts +0 -4
  98. package/dist/types/src/util/isSampled.d.ts +0 -7
  99. package/dist/types/src/util/isSampled.test.d.ts +0 -1
  100. package/dist/types/src/util/isSessionExpired.d.ts +0 -5
  101. package/dist/types/src/util/isSessionExpired.test.d.ts +0 -1
  102. package/dist/types/src/util/logger.d.ts +0 -12
  103. package/dist/types/src/util/supportsSendBeacon.d.ts +0 -4
  104. package/dist/types/test/index.d.ts +0 -3
  105. package/dist/types/test/mocks/mockRrweb.d.ts +0 -15
  106. package/dist/types/test/mocks/mockSdk.d.ts +0 -11
  107. package/dist/types/worker/src/Compressor.d.ts +0 -15
  108. package/dist/types/worker/src/handleMessage.d.ts +0 -2
  109. package/dist/worker-aa3eb59a.js +0 -4
  110. package/dist/worker-f4750cfb.js +0 -7
  111. package/dist/worker-f4750cfb.js.map +0 -1
@@ -1,3 +1,8 @@
1
1
  import type { Session } from '@/session/Session';
2
2
  import { InitialState } from '@/types';
3
- export declare function captureReplay(session: Session, initialState: InitialState): void;
3
+ interface CaptureReplayParams {
4
+ session: Session;
5
+ initialState: InitialState;
6
+ }
7
+ export declare function captureReplay({ session, initialState }: CaptureReplayParams): void;
8
+ export {};
@@ -1,2 +1,10 @@
1
1
  import type { Session } from '@/session/Session';
2
- export declare function captureReplayUpdate(session: Session, timestamp: number): void;
2
+ interface CaptureReplayUpdateParams {
3
+ session: Session;
4
+ /**
5
+ * Timestamp of the event in milliseconds
6
+ */
7
+ timestamp: number;
8
+ }
9
+ export declare function captureReplayUpdate({ session, timestamp, }: CaptureReplayUpdateParams): void;
10
+ export {};
@@ -31,7 +31,7 @@ export declare class EventBufferCompressionWorker implements IEventBuffer {
31
31
  destroy(): void;
32
32
  get length(): number;
33
33
  addEvent(event: RecordingEvent, isCheckout?: boolean): void;
34
- sendEventToWorker(event: RecordingEvent): void;
34
+ sendEventToWorker: (event: RecordingEvent) => void;
35
35
  finishRequest: (id: number) => Promise<Uint8Array>;
36
36
  finish(): Promise<Uint8Array>;
37
37
  }
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { captureEvent, getCurrentHub, addGlobalEventProcessor } from '@sentry/core';
1
+ import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor } from '@sentry/core';
2
2
  import { uuid4, logger as logger$1, htmlTreeAsString, addInstrumentationHandler } from '@sentry/utils';
3
3
  import { record, EventType } from 'rrweb';
4
4
 
@@ -96,7 +96,8 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
96
96
  // Grace period to keep a session when a user changes tabs or hides window
97
97
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
98
98
 
99
- function captureReplay(session, initialState) {
99
+ function captureReplay(_a) {
100
+ var session = _a.session, initialState = _a.initialState;
100
101
  captureEvent({
101
102
  message: ROOT_REPLAY_NAME,
102
103
  tags: { segmentId: session.segmentId, url: initialState.url },
@@ -104,7 +105,8 @@ function captureReplay(session, initialState) {
104
105
  }, { event_id: session.id });
105
106
  }
106
107
 
107
- function captureReplayUpdate(session, timestamp) {
108
+ function captureReplayUpdate(_a) {
109
+ var session = _a.session, timestamp = _a.timestamp;
108
110
  captureEvent({
109
111
  timestamp: timestamp / 1000,
110
112
  message: "".concat(REPLAY_EVENT_NAME, "-").concat(uuid4().substring(16)),
@@ -518,14 +520,22 @@ function createEventBuffer(_a) {
518
520
  var workerBlob = new Blob([workerString]);
519
521
  var workerUrl = URL.createObjectURL(workerBlob);
520
522
  try {
521
- logger.log('using compression worker');
522
- return new EventBufferCompressionWorker(new Worker(workerUrl));
523
+ logger.log('Using compression worker');
524
+ var worker = new Worker(workerUrl);
525
+ if (worker) {
526
+ return new EventBufferCompressionWorker(worker);
527
+ }
528
+ else {
529
+ // TODO: Debugging
530
+ captureException(new Error('Unable to create compression worker'));
531
+ }
523
532
  }
524
533
  catch (_b) {
525
534
  // catch and ignore, fallback to simple event buffer
526
535
  }
536
+ logger.log('Falling back to simple event buffer');
527
537
  }
528
- logger.log('falling back to simple event buffer');
538
+ logger.log('Using simple buffer');
529
539
  return new EventBufferArray();
530
540
  }
531
541
  var EventBufferArray = /** @class */ (function () {
@@ -568,6 +578,15 @@ var EventBufferCompressionWorker = /** @class */ (function () {
568
578
  var _this = this;
569
579
  this.eventBufferItemLength = 0;
570
580
  this._id = 0;
581
+ this.sendEventToWorker = function (event) {
582
+ _this.postMessage({
583
+ id: _this.id,
584
+ method: 'addEvent',
585
+ args: [event],
586
+ });
587
+ logger.log('Message posted to compression worker');
588
+ _this.eventBufferItemLength++;
589
+ };
571
590
  this.finishRequest = function (id) {
572
591
  return new Promise(function (resolve, reject) {
573
592
  var finishListener = function (_a) {
@@ -581,17 +600,16 @@ var EventBufferCompressionWorker = /** @class */ (function () {
581
600
  if (!data.success) {
582
601
  // TODO: Do some error handling, not sure what
583
602
  logger.error(data.response);
584
- reject(new Error('Error in compression WebWorker'));
603
+ reject(new Error('Error in compression worker'));
585
604
  return;
586
605
  }
587
- logger.log('sending compressed');
588
606
  resolve(data.response);
607
+ logger.log('Worker responded with compressed payload');
589
608
  _this.eventBufferItemLength = 0;
590
609
  _this.worker.removeEventListener('message', finishListener);
591
610
  };
592
611
  _this.worker.addEventListener('message', finishListener);
593
612
  _this.postMessage({ id: id, method: 'finish', args: [] });
594
- logger.log('Message posted to worker');
595
613
  });
596
614
  };
597
615
  this.worker = worker;
@@ -611,9 +629,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
611
629
  };
612
630
  EventBufferCompressionWorker.prototype.init = function () {
613
631
  this.postMessage({ id: this.id, method: 'init', args: [] });
614
- logger.log('Message posted to worker');
632
+ logger.log('Initialized compression worker');
615
633
  };
616
634
  EventBufferCompressionWorker.prototype.destroy = function () {
635
+ logger.log('Destroying compression worker');
617
636
  this.worker.terminate();
618
637
  this.worker = null;
619
638
  };
@@ -648,15 +667,6 @@ var EventBufferCompressionWorker = /** @class */ (function () {
648
667
  this.worker.addEventListener('message', initListener);
649
668
  this.postMessage({ id: this.id, method: 'init', args: [] });
650
669
  };
651
- EventBufferCompressionWorker.prototype.sendEventToWorker = function (event) {
652
- this.postMessage({
653
- id: this.id,
654
- method: 'addEvent',
655
- args: [event],
656
- });
657
- logger.log('Message posted to worker');
658
- this.eventBufferItemLength++;
659
- };
660
670
  EventBufferCompressionWorker.prototype.finish = function () {
661
671
  return __awaiter(this, void 0, void 0, function () {
662
672
  return __generator(this, function (_a) {
@@ -977,8 +987,9 @@ var SentryReplay = /** @class */ (function () {
977
987
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
978
988
  */
979
989
  SentryReplay.prototype.destroy = function () {
990
+ logger.log('Destroying instance');
980
991
  this.removeListeners();
981
- this.eventBuffer.destroy();
992
+ // this.eventBuffer.clear();
982
993
  };
983
994
  SentryReplay.prototype.clearSession = function () {
984
995
  this.session = null;
@@ -1228,7 +1239,7 @@ var SentryReplay = /** @class */ (function () {
1228
1239
  // Only want to create replay event if session is new
1229
1240
  if (this.needsCaptureReplay) {
1230
1241
  // This event needs to exist before calling `sendReplay`
1231
- captureReplay(this.session, this.initialState);
1242
+ captureReplay({ session: this.session, initialState: this.initialState });
1232
1243
  this.needsCaptureReplay = false;
1233
1244
  }
1234
1245
  // Reset this to null regardless of `sendReplay` result so that future
@@ -1250,7 +1261,7 @@ var SentryReplay = /** @class */ (function () {
1250
1261
  // of the event is passed as an argument in the case where a timeout
1251
1262
  // occurs.
1252
1263
  this.updateLastActivity(timestamp);
1253
- captureReplayUpdate(this.session, timestamp);
1264
+ captureReplayUpdate({ session: this.session, timestamp: timestamp });
1254
1265
  return [3 /*break*/, 5];
1255
1266
  case 4:
1256
1267
  err_1 = _a.sent();
package/dist/index.js CHANGED
@@ -100,7 +100,8 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
100
100
  // Grace period to keep a session when a user changes tabs or hides window
101
101
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
102
102
 
103
- function captureReplay(session, initialState) {
103
+ function captureReplay(_a) {
104
+ var session = _a.session, initialState = _a.initialState;
104
105
  core.captureEvent({
105
106
  message: ROOT_REPLAY_NAME,
106
107
  tags: { segmentId: session.segmentId, url: initialState.url },
@@ -108,7 +109,8 @@ function captureReplay(session, initialState) {
108
109
  }, { event_id: session.id });
109
110
  }
110
111
 
111
- function captureReplayUpdate(session, timestamp) {
112
+ function captureReplayUpdate(_a) {
113
+ var session = _a.session, timestamp = _a.timestamp;
112
114
  core.captureEvent({
113
115
  timestamp: timestamp / 1000,
114
116
  message: "".concat(REPLAY_EVENT_NAME, "-").concat(utils.uuid4().substring(16)),
@@ -522,14 +524,22 @@ function createEventBuffer(_a) {
522
524
  var workerBlob = new Blob([workerString]);
523
525
  var workerUrl = URL.createObjectURL(workerBlob);
524
526
  try {
525
- logger.log('using compression worker');
526
- return new EventBufferCompressionWorker(new Worker(workerUrl));
527
+ logger.log('Using compression worker');
528
+ var worker = new Worker(workerUrl);
529
+ if (worker) {
530
+ return new EventBufferCompressionWorker(worker);
531
+ }
532
+ else {
533
+ // TODO: Debugging
534
+ core.captureException(new Error('Unable to create compression worker'));
535
+ }
527
536
  }
528
537
  catch (_b) {
529
538
  // catch and ignore, fallback to simple event buffer
530
539
  }
540
+ logger.log('Falling back to simple event buffer');
531
541
  }
532
- logger.log('falling back to simple event buffer');
542
+ logger.log('Using simple buffer');
533
543
  return new EventBufferArray();
534
544
  }
535
545
  var EventBufferArray = /** @class */ (function () {
@@ -572,6 +582,15 @@ var EventBufferCompressionWorker = /** @class */ (function () {
572
582
  var _this = this;
573
583
  this.eventBufferItemLength = 0;
574
584
  this._id = 0;
585
+ this.sendEventToWorker = function (event) {
586
+ _this.postMessage({
587
+ id: _this.id,
588
+ method: 'addEvent',
589
+ args: [event],
590
+ });
591
+ logger.log('Message posted to compression worker');
592
+ _this.eventBufferItemLength++;
593
+ };
575
594
  this.finishRequest = function (id) {
576
595
  return new Promise(function (resolve, reject) {
577
596
  var finishListener = function (_a) {
@@ -585,17 +604,16 @@ var EventBufferCompressionWorker = /** @class */ (function () {
585
604
  if (!data.success) {
586
605
  // TODO: Do some error handling, not sure what
587
606
  logger.error(data.response);
588
- reject(new Error('Error in compression WebWorker'));
607
+ reject(new Error('Error in compression worker'));
589
608
  return;
590
609
  }
591
- logger.log('sending compressed');
592
610
  resolve(data.response);
611
+ logger.log('Worker responded with compressed payload');
593
612
  _this.eventBufferItemLength = 0;
594
613
  _this.worker.removeEventListener('message', finishListener);
595
614
  };
596
615
  _this.worker.addEventListener('message', finishListener);
597
616
  _this.postMessage({ id: id, method: 'finish', args: [] });
598
- logger.log('Message posted to worker');
599
617
  });
600
618
  };
601
619
  this.worker = worker;
@@ -615,9 +633,10 @@ var EventBufferCompressionWorker = /** @class */ (function () {
615
633
  };
616
634
  EventBufferCompressionWorker.prototype.init = function () {
617
635
  this.postMessage({ id: this.id, method: 'init', args: [] });
618
- logger.log('Message posted to worker');
636
+ logger.log('Initialized compression worker');
619
637
  };
620
638
  EventBufferCompressionWorker.prototype.destroy = function () {
639
+ logger.log('Destroying compression worker');
621
640
  this.worker.terminate();
622
641
  this.worker = null;
623
642
  };
@@ -652,15 +671,6 @@ var EventBufferCompressionWorker = /** @class */ (function () {
652
671
  this.worker.addEventListener('message', initListener);
653
672
  this.postMessage({ id: this.id, method: 'init', args: [] });
654
673
  };
655
- EventBufferCompressionWorker.prototype.sendEventToWorker = function (event) {
656
- this.postMessage({
657
- id: this.id,
658
- method: 'addEvent',
659
- args: [event],
660
- });
661
- logger.log('Message posted to worker');
662
- this.eventBufferItemLength++;
663
- };
664
674
  EventBufferCompressionWorker.prototype.finish = function () {
665
675
  return __awaiter(this, void 0, void 0, function () {
666
676
  return __generator(this, function (_a) {
@@ -981,8 +991,9 @@ var SentryReplay = /** @class */ (function () {
981
991
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
982
992
  */
983
993
  SentryReplay.prototype.destroy = function () {
994
+ logger.log('Destroying instance');
984
995
  this.removeListeners();
985
- this.eventBuffer.destroy();
996
+ // this.eventBuffer.clear();
986
997
  };
987
998
  SentryReplay.prototype.clearSession = function () {
988
999
  this.session = null;
@@ -1232,7 +1243,7 @@ var SentryReplay = /** @class */ (function () {
1232
1243
  // Only want to create replay event if session is new
1233
1244
  if (this.needsCaptureReplay) {
1234
1245
  // This event needs to exist before calling `sendReplay`
1235
- captureReplay(this.session, this.initialState);
1246
+ captureReplay({ session: this.session, initialState: this.initialState });
1236
1247
  this.needsCaptureReplay = false;
1237
1248
  }
1238
1249
  // Reset this to null regardless of `sendReplay` result so that future
@@ -1254,7 +1265,7 @@ var SentryReplay = /** @class */ (function () {
1254
1265
  // of the event is passed as an argument in the case where a timeout
1255
1266
  // occurs.
1256
1267
  this.updateLastActivity(timestamp);
1257
- captureReplayUpdate(this.session, timestamp);
1268
+ captureReplayUpdate({ session: this.session, timestamp: timestamp });
1258
1269
  return [3 /*break*/, 5];
1259
1270
  case 4:
1260
1271
  err_1 = _a.sent();