@sentry/replay 7.66.0 → 7.67.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/esm/index.js CHANGED
@@ -17,9 +17,6 @@ const SESSION_IDLE_PAUSE_DURATION = 300000; // 5 minutes in ms
17
17
  // The idle limit for a session after which the session expires.
18
18
  const SESSION_IDLE_EXPIRE_DURATION = 900000; // 15 minutes in ms
19
19
 
20
- // The maximum length of a session
21
- const MAX_SESSION_LIFE = 3600000; // 60 minutes in ms
22
-
23
20
  /** Default flush delays */
24
21
  const DEFAULT_FLUSH_MIN_DELAY = 5000;
25
22
  // XXX: Temp fix for our debounce logic where `maxWait` would never occur if it
@@ -51,6 +48,9 @@ const MIN_REPLAY_DURATION = 4999;
51
48
  /* The max. allowed value that the minReplayDuration can be set to. */
52
49
  const MIN_REPLAY_DURATION_LIMIT = 15000;
53
50
 
51
+ /** The max. length of a replay. */
52
+ const MAX_REPLAY_DURATION = 3600000; // 60 minutes in ms;
53
+
54
54
  var NodeType$1;
55
55
  (function (NodeType) {
56
56
  NodeType[NodeType["Document"] = 0] = "Document";
@@ -4654,13 +4654,20 @@ function isExpired(
4654
4654
  /**
4655
4655
  * Checks to see if session is expired
4656
4656
  */
4657
- function isSessionExpired(session, timeouts, targetTime = +new Date()) {
4657
+ function isSessionExpired(
4658
+ session,
4659
+ {
4660
+ maxReplayDuration,
4661
+ sessionIdleExpire,
4662
+ targetTime = Date.now(),
4663
+ },
4664
+ ) {
4658
4665
  return (
4659
4666
  // First, check that maximum session length has not been exceeded
4660
- isExpired(session.started, timeouts.maxSessionLife, targetTime) ||
4667
+ isExpired(session.started, maxReplayDuration, targetTime) ||
4661
4668
  // check that the idle timeout has not been exceeded (i.e. user has
4662
4669
  // performed an action within the last `sessionIdleExpire` ms)
4663
- isExpired(session.lastActivity, timeouts.sessionIdleExpire, targetTime)
4670
+ isExpired(session.lastActivity, sessionIdleExpire, targetTime)
4664
4671
  );
4665
4672
  }
4666
4673
 
@@ -4672,15 +4679,16 @@ function isSessionExpired(session, timeouts, targetTime = +new Date()) {
4672
4679
  function maybeRefreshSession(
4673
4680
  session,
4674
4681
  {
4675
- timeouts,
4676
4682
  traceInternals,
4683
+ maxReplayDuration,
4684
+ sessionIdleExpire,
4677
4685
  }
4678
4686
 
4679
4687
  ,
4680
4688
  sessionOptions,
4681
4689
  ) {
4682
4690
  // If not expired, all good, just keep the session
4683
- if (!isSessionExpired(session, timeouts)) {
4691
+ if (!isSessionExpired(session, { sessionIdleExpire, maxReplayDuration })) {
4684
4692
  return session;
4685
4693
  }
4686
4694
 
@@ -4713,8 +4721,9 @@ function maybeRefreshSession(
4713
4721
  function loadOrCreateSession(
4714
4722
  currentSession,
4715
4723
  {
4716
- timeouts,
4717
4724
  traceInternals,
4725
+ sessionIdleExpire,
4726
+ maxReplayDuration,
4718
4727
  }
4719
4728
 
4720
4729
  ,
@@ -4729,9 +4738,11 @@ function loadOrCreateSession(
4729
4738
  return createSession(sessionOptions);
4730
4739
  }
4731
4740
 
4732
- return maybeRefreshSession(existingSession, { timeouts, traceInternals }, sessionOptions);
4741
+ return maybeRefreshSession(existingSession, { sessionIdleExpire, traceInternals, maxReplayDuration }, sessionOptions);
4733
4742
  }
4734
4743
 
4744
+ const ReplayEventTypeCustom = 5;
4745
+
4735
4746
  function isCustomEvent(event) {
4736
4747
  return event.type === EventType.Custom;
4737
4748
  }
@@ -4766,9 +4777,9 @@ async function addEvent(
4766
4777
  }
4767
4778
 
4768
4779
  // Throw out events that are +60min from the initial timestamp
4769
- if (timestampInMs > replay.getContext().initialTimestamp + replay.timeouts.maxSessionLife) {
4780
+ if (timestampInMs > replay.getContext().initialTimestamp + replay.getOptions().maxReplayDuration) {
4770
4781
  logInfo(
4771
- `[Replay] Skipping event with timestamp ${timestampInMs} because it is after maxSessionLife`,
4782
+ `[Replay] Skipping event with timestamp ${timestampInMs} because it is after maxReplayDuration`,
4772
4783
  replay.getOptions()._experiments.traceInternals,
4773
4784
  );
4774
4785
  return null;
@@ -7254,7 +7265,6 @@ class ReplayContainer {
7254
7265
  this.timeouts = {
7255
7266
  sessionIdlePause: SESSION_IDLE_PAUSE_DURATION,
7256
7267
  sessionIdleExpire: SESSION_IDLE_EXPIRE_DURATION,
7257
- maxSessionLife: MAX_SESSION_LIFE,
7258
7268
  } ;
7259
7269
  this._lastActivity = Date.now();
7260
7270
  this._isEnabled = false;
@@ -7381,7 +7391,8 @@ class ReplayContainer {
7381
7391
  const session = loadOrCreateSession(
7382
7392
  this.session,
7383
7393
  {
7384
- timeouts: this.timeouts,
7394
+ maxReplayDuration: this._options.maxReplayDuration,
7395
+ sessionIdleExpire: this.timeouts.sessionIdleExpire,
7385
7396
  traceInternals: this._options._experiments.traceInternals,
7386
7397
  },
7387
7398
  {
@@ -7411,7 +7422,8 @@ class ReplayContainer {
7411
7422
  const session = loadOrCreateSession(
7412
7423
  this.session,
7413
7424
  {
7414
- timeouts: this.timeouts,
7425
+ sessionIdleExpire: this.timeouts.sessionIdleExpire,
7426
+ maxReplayDuration: this._options.maxReplayDuration,
7415
7427
  traceInternals: this._options._experiments.traceInternals,
7416
7428
  },
7417
7429
  {
@@ -7587,7 +7599,7 @@ class ReplayContainer {
7587
7599
  // `shouldRefresh`, the session could be considered expired due to
7588
7600
  // lifespan, which is not what we want. Update session start date to be
7589
7601
  // the current timestamp, so that session is not considered to be
7590
- // expired. This means that max replay duration can be MAX_SESSION_LIFE +
7602
+ // expired. This means that max replay duration can be MAX_REPLAY_DURATION +
7591
7603
  // (length of buffer), which we are ok with.
7592
7604
  this._updateUserActivity(activityTime);
7593
7605
  this._updateSessionActivity(activityTime);
@@ -7750,7 +7762,11 @@ class ReplayContainer {
7750
7762
  }
7751
7763
 
7752
7764
  // Session is expired, trigger a full snapshot (which will create a new session)
7753
- this._triggerFullSnapshot();
7765
+ if (this.isPaused()) {
7766
+ this.resume();
7767
+ } else {
7768
+ this._triggerFullSnapshot();
7769
+ }
7754
7770
 
7755
7771
  return false;
7756
7772
  }
@@ -7793,7 +7809,7 @@ class ReplayContainer {
7793
7809
 
7794
7810
  this.addUpdate(() => {
7795
7811
  void addEvent(this, {
7796
- type: EventType.Custom,
7812
+ type: ReplayEventTypeCustom,
7797
7813
  timestamp: breadcrumb.timestamp || 0,
7798
7814
  data: {
7799
7815
  tag: 'breadcrumb',
@@ -7864,7 +7880,8 @@ class ReplayContainer {
7864
7880
  const session = loadOrCreateSession(
7865
7881
  this.session,
7866
7882
  {
7867
- timeouts: this.timeouts,
7883
+ sessionIdleExpire: this.timeouts.sessionIdleExpire,
7884
+ maxReplayDuration: this._options.maxReplayDuration,
7868
7885
  traceInternals: this._options._experiments.traceInternals,
7869
7886
  },
7870
7887
  {
@@ -7893,8 +7910,9 @@ class ReplayContainer {
7893
7910
  const newSession = maybeRefreshSession(
7894
7911
  currentSession,
7895
7912
  {
7896
- timeouts: this.timeouts,
7913
+ sessionIdleExpire: this.timeouts.sessionIdleExpire,
7897
7914
  traceInternals: this._options._experiments.traceInternals,
7915
+ maxReplayDuration: this._options.maxReplayDuration,
7898
7916
  },
7899
7917
  {
7900
7918
  stickySession: Boolean(this._options.stickySession),
@@ -8029,7 +8047,10 @@ class ReplayContainer {
8029
8047
  return;
8030
8048
  }
8031
8049
 
8032
- const expired = isSessionExpired(this.session, this.timeouts);
8050
+ const expired = isSessionExpired(this.session, {
8051
+ maxReplayDuration: this._options.maxReplayDuration,
8052
+ ...this.timeouts,
8053
+ });
8033
8054
 
8034
8055
  if (breadcrumb && !expired) {
8035
8056
  this._createCustomBreadcrumb(breadcrumb);
@@ -8208,7 +8229,7 @@ class ReplayContainer {
8208
8229
  // Check total duration again, to avoid sending outdated stuff
8209
8230
  // We leave 30s wiggle room to accomodate late flushing etc.
8210
8231
  // This _could_ happen when the browser is suspended during flushing, in which case we just want to stop
8211
- if (timestamp - this._context.initialTimestamp > this.timeouts.maxSessionLife + 30000) {
8232
+ if (timestamp - this._context.initialTimestamp > this._options.maxReplayDuration + 30000) {
8212
8233
  throw new Error('Session is too long, not sending replay');
8213
8234
  }
8214
8235
 
@@ -8276,10 +8297,10 @@ class ReplayContainer {
8276
8297
  // A flush is about to happen, cancel any queued flushes
8277
8298
  this._debouncedFlush.cancel();
8278
8299
 
8279
- // If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
8300
+ // If session is too short, or too long (allow some wiggle room over maxReplayDuration), do not send it
8280
8301
  // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
8281
8302
  const tooShort = duration < this._options.minReplayDuration;
8282
- const tooLong = duration > this.timeouts.maxSessionLife + 5000;
8303
+ const tooLong = duration > this._options.maxReplayDuration + 5000;
8283
8304
  if (tooShort || tooLong) {
8284
8305
  logInfo(
8285
8306
  `[Replay] Session duration (${Math.floor(duration / 1000)}s) is too ${
@@ -8499,6 +8520,7 @@ class Replay {
8499
8520
  flushMinDelay = DEFAULT_FLUSH_MIN_DELAY,
8500
8521
  flushMaxDelay = DEFAULT_FLUSH_MAX_DELAY,
8501
8522
  minReplayDuration = MIN_REPLAY_DURATION,
8523
+ maxReplayDuration = MAX_REPLAY_DURATION,
8502
8524
  stickySession = true,
8503
8525
  useCompression = true,
8504
8526
  _experiments = {},
@@ -8578,6 +8600,7 @@ class Replay {
8578
8600
  flushMinDelay,
8579
8601
  flushMaxDelay,
8580
8602
  minReplayDuration: Math.min(minReplayDuration, MIN_REPLAY_DURATION_LIMIT),
8603
+ maxReplayDuration: Math.min(maxReplayDuration, MAX_REPLAY_DURATION),
8581
8604
  stickySession,
8582
8605
  sessionSampleRate,
8583
8606
  errorSampleRate,