@sentry/replay 10.63.0 → 10.65.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.
Files changed (27) hide show
  1. package/build/npm/cjs/index.js +63 -54
  2. package/build/npm/cjs/index.js.map +1 -1
  3. package/build/npm/esm/index.js +64 -55
  4. package/build/npm/esm/index.js.map +1 -1
  5. package/build/npm/esm/package.json +1 -1
  6. package/build/npm/types/coreHandlers/handleProcessSegmentSpan.d.ts +6 -0
  7. package/build/npm/types/coreHandlers/handleProcessSegmentSpan.d.ts.map +1 -0
  8. package/build/npm/types/coreHandlers/util/addSegmentDetailsToContext.d.ts +3 -0
  9. package/build/npm/types/coreHandlers/util/addSegmentDetailsToContext.d.ts.map +1 -0
  10. package/build/npm/types/coreHandlers/util/domUtils.d.ts.map +1 -1
  11. package/build/npm/types/coreHandlers/util/xhrUtils.d.ts.map +1 -1
  12. package/build/npm/types/replay.d.ts.map +1 -1
  13. package/build/npm/types/types/replay.d.ts +8 -0
  14. package/build/npm/types/types/replay.d.ts.map +1 -1
  15. package/build/npm/types/util/addEvent.d.ts.map +1 -1
  16. package/build/npm/types/util/handleRecordingEmit.d.ts.map +1 -1
  17. package/build/npm/types/util/sendReplayRequest.d.ts.map +1 -1
  18. package/build/npm/types-ts3.8/coreHandlers/handleProcessSegmentSpan.d.ts +6 -0
  19. package/build/npm/types-ts3.8/coreHandlers/util/addSegmentDetailsToContext.d.ts +3 -0
  20. package/build/npm/types-ts3.8/types/replay.d.ts +8 -0
  21. package/package.json +4 -4
  22. package/build/npm/types/coreHandlers/handleAfterSegmentSpanEnd.d.ts +0 -6
  23. package/build/npm/types/coreHandlers/handleAfterSegmentSpanEnd.d.ts.map +0 -1
  24. package/build/npm/types/coreHandlers/util/addTraceIdToContext.d.ts +0 -3
  25. package/build/npm/types/coreHandlers/util/addTraceIdToContext.d.ts.map +0 -1
  26. package/build/npm/types-ts3.8/coreHandlers/handleAfterSegmentSpanEnd.d.ts +0 -6
  27. package/build/npm/types-ts3.8/coreHandlers/util/addTraceIdToContext.d.ts +0 -3
@@ -4635,7 +4635,7 @@ function getTargetNode(event) {
4635
4635
  return event;
4636
4636
  }
4637
4637
  function isEventWithTarget(event) {
4638
- return typeof event === "object" && !!event && "target" in event;
4638
+ return core.isObjectLike(event) && "target" in event;
4639
4639
  }
4640
4640
 
4641
4641
  let handlers;
@@ -5827,6 +5827,10 @@ async function _addEvent(replay, event, isCheckout) {
5827
5827
  }
5828
5828
  return await eventBuffer.addEvent(eventAfterPossibleCallback);
5829
5829
  } catch (error) {
5830
+ if (!replay.isEnabled()) {
5831
+ replay.handleException(error);
5832
+ return null;
5833
+ }
5830
5834
  const isExceeded = error && error instanceof EventBufferSizeExceededError;
5831
5835
  const reason = isExceeded ? "eventBufferOverflow" : "eventBufferError";
5832
5836
  const client = core.getClient();
@@ -5869,23 +5873,23 @@ function maybeApplyCallback(event, callback) {
5869
5873
  return event;
5870
5874
  }
5871
5875
 
5872
- const MAX_TRACE_IDS = 100;
5873
- function addTraceIdToContext(replay, traceId) {
5876
+ const MAX_CONTEXT_VALUES = 100;
5877
+ function addSegmentDetailsToContext(replay, traceId, segmentName) {
5874
5878
  const replayContext = replay.getContext();
5875
- if (replayContext.traceIds.size < MAX_TRACE_IDS) {
5879
+ if (traceId && replayContext.traceIds.size < MAX_CONTEXT_VALUES) {
5876
5880
  replayContext.traceIds.add(traceId);
5877
5881
  }
5882
+ if (segmentName && replayContext.segmentNames.size < MAX_CONTEXT_VALUES) {
5883
+ replayContext.segmentNames.add(segmentName);
5884
+ }
5878
5885
  }
5879
5886
 
5880
- function handleAfterSegmentSpanEnd(replay) {
5881
- return (segmentSpan) => {
5882
- if (!replay.isEnabled() || !core.spanIsSampled(segmentSpan)) {
5887
+ function handleProcessSegmentSpan(replay) {
5888
+ return (spanJSON) => {
5889
+ if (!replay.isEnabled()) {
5883
5890
  return;
5884
5891
  }
5885
- const traceId = segmentSpan.spanContext().traceId;
5886
- if (traceId) {
5887
- addTraceIdToContext(replay, traceId);
5888
- }
5892
+ addSegmentDetailsToContext(replay, spanJSON.trace_id, spanJSON.name || void 0);
5889
5893
  };
5890
5894
  }
5891
5895
 
@@ -5919,10 +5923,7 @@ function handleAfterSendEvent(replay) {
5919
5923
  };
5920
5924
  }
5921
5925
  function handleTransactionEvent(replay, event) {
5922
- const traceId = event.contexts?.trace?.trace_id;
5923
- if (traceId) {
5924
- addTraceIdToContext(replay, traceId);
5925
- }
5926
+ addSegmentDetailsToContext(replay, event.contexts?.trace?.trace_id, event.transaction);
5926
5927
  }
5927
5928
  function handleErrorEvent(replay, event) {
5928
5929
  const replayContext = replay.getContext();
@@ -6685,7 +6686,7 @@ function _parseXhrResponse(body, responseType) {
6685
6686
  if (body instanceof Document) {
6686
6687
  return [body.body.outerHTML];
6687
6688
  }
6688
- if (responseType === "json" && body && typeof body === "object") {
6689
+ if (responseType === "json" && core.isObjectLike(body)) {
6689
6690
  return [JSON.stringify(body)];
6690
6691
  }
6691
6692
  if (!body) {
@@ -6700,7 +6701,7 @@ function _parseXhrResponse(body, responseType) {
6700
6701
  }
6701
6702
  function _getBodySize(body, responseType) {
6702
6703
  try {
6703
- const bodyStr = responseType === "json" && body && typeof body === "object" ? JSON.stringify(body) : body;
6704
+ const bodyStr = responseType === "json" && core.isObjectLike(body) ? JSON.stringify(body) : body;
6704
6705
  return getBodySize(bodyStr);
6705
6706
  } catch {
6706
6707
  return void 0;
@@ -6781,7 +6782,7 @@ function addGlobalListeners(replay) {
6781
6782
  }
6782
6783
  }
6783
6784
  });
6784
- client.on("afterSegmentSpanEnd", handleAfterSegmentSpanEnd(replay));
6785
+ client.on("processSegmentSpan", handleProcessSegmentSpan(replay));
6785
6786
  client.on("spanStart", (span) => {
6786
6787
  replay.lastActiveSpan = span;
6787
6788
  });
@@ -6856,46 +6857,50 @@ function getRecordingSamplingOptions() {
6856
6857
  function getHandleRecordingEmit(replay) {
6857
6858
  let hadFirstEvent = false;
6858
6859
  return (event, _isCheckout) => {
6859
- if (!replay.checkAndHandleExpiredSession()) {
6860
- DEBUG_BUILD && debug.warn("Received replay event after session expired.");
6861
- return;
6862
- }
6863
- const isCheckout = _isCheckout || !hadFirstEvent;
6864
- hadFirstEvent = true;
6865
- syncMirrorAttributesFromMutationEvent(event);
6866
- if (replay.clickDetector) {
6867
- updateClickDetectorForRecordingEvent(replay.clickDetector, event);
6868
- }
6869
- replay.addUpdate(() => {
6870
- if (replay.recordingMode === "buffer" && isCheckout) {
6871
- replay.setInitialState();
6872
- }
6873
- if (!addEventSync(replay, event, isCheckout)) {
6874
- return true;
6860
+ try {
6861
+ if (!replay.checkAndHandleExpiredSession()) {
6862
+ DEBUG_BUILD && debug.warn("Received replay event after session expired.");
6863
+ return;
6875
6864
  }
6876
- if (!isCheckout) {
6877
- return false;
6865
+ const isCheckout = _isCheckout || !hadFirstEvent;
6866
+ hadFirstEvent = true;
6867
+ syncMirrorAttributesFromMutationEvent(event);
6868
+ if (replay.clickDetector) {
6869
+ updateClickDetectorForRecordingEvent(replay.clickDetector, event);
6878
6870
  }
6879
- const session = replay.session;
6880
- addSettingsEvent(replay, isCheckout);
6881
- if (replay.recordingMode === "buffer" && session && replay.eventBuffer && !session.dirty) {
6882
- const earliestEvent = replay.eventBuffer.getEarliestTimestamp();
6883
- if (earliestEvent) {
6884
- DEBUG_BUILD && debug.log(`Updating session start time to earliest event in buffer to ${new Date(earliestEvent)}`);
6885
- session.started = earliestEvent;
6886
- if (replay.getOptions().stickySession) {
6887
- saveSession(session);
6871
+ replay.addUpdate(() => {
6872
+ if (replay.recordingMode === "buffer" && isCheckout) {
6873
+ replay.setInitialState();
6874
+ }
6875
+ if (!addEventSync(replay, event, isCheckout)) {
6876
+ return true;
6877
+ }
6878
+ if (!isCheckout) {
6879
+ return false;
6880
+ }
6881
+ const session = replay.session;
6882
+ addSettingsEvent(replay, isCheckout);
6883
+ if (replay.recordingMode === "buffer" && session && replay.eventBuffer && !session.dirty) {
6884
+ const earliestEvent = replay.eventBuffer.getEarliestTimestamp();
6885
+ if (earliestEvent) {
6886
+ DEBUG_BUILD && debug.log(`Updating session start time to earliest event in buffer to ${new Date(earliestEvent)}`);
6887
+ session.started = earliestEvent;
6888
+ if (replay.getOptions().stickySession) {
6889
+ saveSession(session);
6890
+ }
6888
6891
  }
6889
6892
  }
6890
- }
6891
- if (session?.previousSessionId) {
6893
+ if (session?.previousSessionId) {
6894
+ return true;
6895
+ }
6896
+ if (replay.recordingMode === "session") {
6897
+ void replay.flush();
6898
+ }
6892
6899
  return true;
6893
- }
6894
- if (replay.recordingMode === "session") {
6895
- void replay.flush();
6896
- }
6897
- return true;
6898
- });
6900
+ });
6901
+ } catch (error) {
6902
+ replay.handleException(error);
6903
+ }
6899
6904
  };
6900
6905
  }
6901
6906
  function syncMirrorAttributesFromMutationEvent(event) {
@@ -7046,7 +7051,7 @@ async function sendReplayRequest({
7046
7051
  segment_id
7047
7052
  }
7048
7053
  });
7049
- const { urls, errorIds, traceIds, initialTimestamp } = eventContext;
7054
+ const { urls, errorIds, traceIds, segmentNames, initialTimestamp } = eventContext;
7050
7055
  const client = core.getClient();
7051
7056
  const scope = core.getCurrentScope();
7052
7057
  const transport = client?.getTransport();
@@ -7060,6 +7065,7 @@ async function sendReplayRequest({
7060
7065
  timestamp: timestamp / 1e3,
7061
7066
  error_ids: errorIds,
7062
7067
  trace_ids: traceIds,
7068
+ segment_names: segmentNames,
7063
7069
  urls,
7064
7070
  replay_id: replayId,
7065
7071
  segment_id,
@@ -7205,6 +7211,7 @@ class ReplayContainer {
7205
7211
  this._context = {
7206
7212
  errorIds: /* @__PURE__ */ new Set(),
7207
7213
  traceIds: /* @__PURE__ */ new Set(),
7214
+ segmentNames: /* @__PURE__ */ new Set(),
7208
7215
  urls: [],
7209
7216
  initialTimestamp: Date.now(),
7210
7217
  initialUrl: ""
@@ -7877,6 +7884,7 @@ class ReplayContainer {
7877
7884
  _clearContext() {
7878
7885
  this._context.errorIds.clear();
7879
7886
  this._context.traceIds.clear();
7887
+ this._context.segmentNames.clear();
7880
7888
  this._context.urls = [];
7881
7889
  }
7882
7890
  /** Update the initial timestamp based on the buffer content. */
@@ -7902,6 +7910,7 @@ class ReplayContainer {
7902
7910
  initialUrl: this._context.initialUrl,
7903
7911
  errorIds: Array.from(this._context.errorIds),
7904
7912
  traceIds: Array.from(this._context.traceIds),
7913
+ segmentNames: Array.from(this._context.segmentNames),
7905
7914
  urls: this._context.urls
7906
7915
  };
7907
7916
  this._clearContext();