@sentry/replay 0.6.11-0 → 0.6.12-0

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
@@ -1,6 +1,6 @@
1
1
  # sentry-replay
2
2
 
3
- Note: Session Replay is currently in alpha.
3
+ Note: Session Replay is currently in beta.
4
4
 
5
5
  ## Pre-requisites
6
6
 
@@ -1,5 +1,6 @@
1
1
  import { SampleRates, SessionOptions } from '../types';
2
2
  declare type StickyOption = Required<Pick<SessionOptions, 'stickySession'>>;
3
+ declare type Sampled = false | 'session' | 'error';
3
4
  interface SessionObject {
4
5
  id: string;
5
6
  /**
@@ -15,9 +16,9 @@ interface SessionObject {
15
16
  */
16
17
  segmentId: number;
17
18
  /**
18
- * Is the session sampled?
19
+ * Is the session sampled? `null` if the sampled, otherwise, `session` or `error`
19
20
  */
20
- sampled: boolean;
21
+ sampled: Sampled;
21
22
  }
22
23
  export declare class Session {
23
24
  /**
@@ -54,8 +55,8 @@ export declare class Session {
54
55
  set segmentId(id: number);
55
56
  get previousSessionId(): string | undefined;
56
57
  set previousSessionId(id: string | undefined);
57
- get sampled(): boolean;
58
- set sampled(_isSampled: boolean);
58
+ get sampled(): Sampled;
59
+ set sampled(_isSampled: Sampled);
59
60
  toJSON(): SessionObject;
60
61
  }
61
62
  export {};
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentHub, captureException, addBreadcrumb, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
1
+ import { getCurrentHub, addBreadcrumb, captureException, 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';
@@ -353,7 +353,11 @@ var Session = /** @class */ (function () {
353
353
  this._lastActivity = (_c = session.lastActivity) !== null && _c !== void 0 ? _c : now;
354
354
  this._segmentId = (_d = session.segmentId) !== null && _d !== void 0 ? _d : 0;
355
355
  this._sampled =
356
- (_e = session.sampled) !== null && _e !== void 0 ? _e : (isSampled(sessionSampleRate) || isSampled(errorSampleRate));
356
+ (_e = session.sampled) !== null && _e !== void 0 ? _e : (isSampled(sessionSampleRate)
357
+ ? 'session'
358
+ : isSampled(errorSampleRate)
359
+ ? 'error'
360
+ : false);
357
361
  this.options = {
358
362
  stickySession: stickySession,
359
363
  };
@@ -449,16 +453,6 @@ function createSession(_a) {
449
453
  return session;
450
454
  }
451
455
 
452
- /**
453
- * Captures exceptions to Sentry only when it occurs on sentry.io
454
- */
455
- function captureInternalException(err) {
456
- if (!isInternal()) {
457
- return;
458
- }
459
- captureException(err);
460
- }
461
-
462
456
  /**
463
457
  * Fetches a session from storage
464
458
  */
@@ -474,10 +468,7 @@ function fetchSession(_a) {
474
468
  }
475
469
  try {
476
470
  var sessionObj = JSON.parse(sessionStringFromStorage);
477
- // NOTE: This shouldn't happen
478
- if (sessionObj.segmentId === 0) {
479
- captureInternalException(new Error('Session storage object with segmentId = 0'));
480
- }
471
+ // TODO: It's unexpected, but people seem to encounter `sessionObj.segmentId === 0`
481
472
  return new Session(sessionObj,
482
473
  // We are assuming that if there is a saved item, then the session is sticky,
483
474
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
@@ -528,6 +519,16 @@ function addInternalBreadcrumb(arg) {
528
519
  addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
529
520
  }
530
521
 
522
+ /**
523
+ * Captures exceptions to Sentry only when it occurs on sentry.io
524
+ */
525
+ function captureInternalException(err) {
526
+ if (!isInternal()) {
527
+ return;
528
+ }
529
+ captureException(err);
530
+ }
531
+
531
532
  function createPayload(_a) {
532
533
  var events = _a.events, headers = _a.headers;
533
534
  var payloadWithSequence;
@@ -1255,14 +1256,6 @@ var Replay = /** @class */ (function () {
1255
1256
  maskAllText: maskAllText,
1256
1257
  blockAllMedia: blockAllMedia,
1257
1258
  };
1258
- // Modify recording options to checkoutEveryNthSecond if this is defined, as we
1259
- // don't know when an error will occur, so we need to keep a buffer of replay events.
1260
- if (this.options.errorSampleRate > 0 &&
1261
- this.options.sessionSampleRate < 1.0) {
1262
- // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1263
- this.recordingOptions.checkoutEveryNms = 60000;
1264
- this.waitForError = true;
1265
- }
1266
1259
  // TODO(deprecated): Maintain backwards compatibility for alpha users
1267
1260
  if (usingDeprecatedCaptureOnlyOnError) {
1268
1261
  console.warn('[@sentry/replay]: The `captureOnlyOnError` option is deprecated! Please configure `errorSampleRate` instead.');
@@ -1329,6 +1322,15 @@ var Replay = /** @class */ (function () {
1329
1322
  // If session was not sampled, then we do not initialize the integration at all.
1330
1323
  return;
1331
1324
  }
1325
+ // Modify recording options to checkoutEveryNthSecond if
1326
+ // sampling for error replay. This is because we don't know
1327
+ // when an error will occur, so we need to keep a buffer of
1328
+ // replay events.
1329
+ if (this.session.sampled === 'error') {
1330
+ // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1331
+ this.recordingOptions.checkoutEveryNms = 60000;
1332
+ this.waitForError = true;
1333
+ }
1332
1334
  // setup() is generally called on page load or manually - in both cases we
1333
1335
  // should treat it as an activity
1334
1336
  this.updateSessionActivity();
@@ -1862,7 +1864,7 @@ var Replay = /** @class */ (function () {
1862
1864
  timestamp = new Date().getTime();
1863
1865
  sdkInfo = {
1864
1866
  name: 'sentry.javascript.integration.replay',
1865
- version: "0.6.11-0",
1867
+ version: "0.6.12-0",
1866
1868
  };
1867
1869
  return [4 /*yield*/, new Promise(function (resolve) {
1868
1870
  var _a;
package/dist/index.js CHANGED
@@ -361,7 +361,11 @@ var Session = /** @class */ (function () {
361
361
  this._lastActivity = (_c = session.lastActivity) !== null && _c !== void 0 ? _c : now;
362
362
  this._segmentId = (_d = session.segmentId) !== null && _d !== void 0 ? _d : 0;
363
363
  this._sampled =
364
- (_e = session.sampled) !== null && _e !== void 0 ? _e : (isSampled(sessionSampleRate) || isSampled(errorSampleRate));
364
+ (_e = session.sampled) !== null && _e !== void 0 ? _e : (isSampled(sessionSampleRate)
365
+ ? 'session'
366
+ : isSampled(errorSampleRate)
367
+ ? 'error'
368
+ : false);
365
369
  this.options = {
366
370
  stickySession: stickySession,
367
371
  };
@@ -457,16 +461,6 @@ function createSession(_a) {
457
461
  return session;
458
462
  }
459
463
 
460
- /**
461
- * Captures exceptions to Sentry only when it occurs on sentry.io
462
- */
463
- function captureInternalException(err) {
464
- if (!isInternal()) {
465
- return;
466
- }
467
- core.captureException(err);
468
- }
469
-
470
464
  /**
471
465
  * Fetches a session from storage
472
466
  */
@@ -482,10 +476,7 @@ function fetchSession(_a) {
482
476
  }
483
477
  try {
484
478
  var sessionObj = JSON.parse(sessionStringFromStorage);
485
- // NOTE: This shouldn't happen
486
- if (sessionObj.segmentId === 0) {
487
- captureInternalException(new Error('Session storage object with segmentId = 0'));
488
- }
479
+ // TODO: It's unexpected, but people seem to encounter `sessionObj.segmentId === 0`
489
480
  return new Session(sessionObj,
490
481
  // We are assuming that if there is a saved item, then the session is sticky,
491
482
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
@@ -536,6 +527,16 @@ function addInternalBreadcrumb(arg) {
536
527
  core.addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
537
528
  }
538
529
 
530
+ /**
531
+ * Captures exceptions to Sentry only when it occurs on sentry.io
532
+ */
533
+ function captureInternalException(err) {
534
+ if (!isInternal()) {
535
+ return;
536
+ }
537
+ core.captureException(err);
538
+ }
539
+
539
540
  function createPayload(_a) {
540
541
  var events = _a.events, headers = _a.headers;
541
542
  var payloadWithSequence;
@@ -1263,14 +1264,6 @@ var Replay = /** @class */ (function () {
1263
1264
  maskAllText: maskAllText,
1264
1265
  blockAllMedia: blockAllMedia,
1265
1266
  };
1266
- // Modify recording options to checkoutEveryNthSecond if this is defined, as we
1267
- // don't know when an error will occur, so we need to keep a buffer of replay events.
1268
- if (this.options.errorSampleRate > 0 &&
1269
- this.options.sessionSampleRate < 1.0) {
1270
- // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1271
- this.recordingOptions.checkoutEveryNms = 60000;
1272
- this.waitForError = true;
1273
- }
1274
1267
  // TODO(deprecated): Maintain backwards compatibility for alpha users
1275
1268
  if (usingDeprecatedCaptureOnlyOnError) {
1276
1269
  console.warn('[@sentry/replay]: The `captureOnlyOnError` option is deprecated! Please configure `errorSampleRate` instead.');
@@ -1337,6 +1330,15 @@ var Replay = /** @class */ (function () {
1337
1330
  // If session was not sampled, then we do not initialize the integration at all.
1338
1331
  return;
1339
1332
  }
1333
+ // Modify recording options to checkoutEveryNthSecond if
1334
+ // sampling for error replay. This is because we don't know
1335
+ // when an error will occur, so we need to keep a buffer of
1336
+ // replay events.
1337
+ if (this.session.sampled === 'error') {
1338
+ // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1339
+ this.recordingOptions.checkoutEveryNms = 60000;
1340
+ this.waitForError = true;
1341
+ }
1340
1342
  // setup() is generally called on page load or manually - in both cases we
1341
1343
  // should treat it as an activity
1342
1344
  this.updateSessionActivity();
@@ -1870,7 +1872,7 @@ var Replay = /** @class */ (function () {
1870
1872
  timestamp = new Date().getTime();
1871
1873
  sdkInfo = {
1872
1874
  name: 'sentry.javascript.integration.replay',
1873
- version: "0.6.11-0",
1875
+ version: "0.6.12-0",
1874
1876
  };
1875
1877
  return [4 /*yield*/, new Promise(function (resolve) {
1876
1878
  var _a;