@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
@@ -1,4 +1,4 @@
1
- import { GLOBAL_OBJ, normalize, fill, browserPerformanceTimeOrigin, debug as debug$1, severityLevelFromString, captureException, addBreadcrumb, uuid4, getClient, spanIsSampled, getLocationHref, getCurrentScope, getActiveSpan, getDynamicSamplingContextFromSpan, isSentryRequestUrl, stringMatchesSomePattern, addEventProcessor, debounce as debounce$1, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, prepareEvent, getIsolationScope, updateRateLimits, isRateLimited, setContext, getRootSpan, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isBrowser, safeSetSpanJSONAttributes, parseSampleRate, consoleSandbox } from '@sentry/core';
1
+ import { GLOBAL_OBJ, normalize, isObjectLike, fill, browserPerformanceTimeOrigin, debug as debug$1, severityLevelFromString, captureException, addBreadcrumb, uuid4, getClient, getLocationHref, getCurrentScope, getActiveSpan, getDynamicSamplingContextFromSpan, isSentryRequestUrl, stringMatchesSomePattern, addEventProcessor, debounce as debounce$1, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, prepareEvent, getIsolationScope, updateRateLimits, isRateLimited, setContext, getRootSpan, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isBrowser, safeSetSpanJSONAttributes, parseSampleRate, consoleSandbox } from '@sentry/core';
2
2
  import { setTimeout as setTimeout$3, htmlTreeAsString, addPerformanceInstrumentationHandler, addLcpInstrumentationHandler, addClsInstrumentationHandler, addInpInstrumentationHandler, serializeFormData, getFetchRequestArgBody, getBodyString, SENTRY_XHR_DATA_KEY, parseXhrResponseHeaders, addClickKeypressInstrumentationHandler, addHistoryInstrumentationHandler } from '@sentry/browser-utils';
3
3
 
4
4
  const WINDOW = GLOBAL_OBJ;
@@ -4633,7 +4633,7 @@ function getTargetNode(event) {
4633
4633
  return event;
4634
4634
  }
4635
4635
  function isEventWithTarget(event) {
4636
- return typeof event === "object" && !!event && "target" in event;
4636
+ return isObjectLike(event) && "target" in event;
4637
4637
  }
4638
4638
 
4639
4639
  let handlers;
@@ -5825,6 +5825,10 @@ async function _addEvent(replay, event, isCheckout) {
5825
5825
  }
5826
5826
  return await eventBuffer.addEvent(eventAfterPossibleCallback);
5827
5827
  } catch (error) {
5828
+ if (!replay.isEnabled()) {
5829
+ replay.handleException(error);
5830
+ return null;
5831
+ }
5828
5832
  const isExceeded = error && error instanceof EventBufferSizeExceededError;
5829
5833
  const reason = isExceeded ? "eventBufferOverflow" : "eventBufferError";
5830
5834
  const client = getClient();
@@ -5867,23 +5871,23 @@ function maybeApplyCallback(event, callback) {
5867
5871
  return event;
5868
5872
  }
5869
5873
 
5870
- const MAX_TRACE_IDS = 100;
5871
- function addTraceIdToContext(replay, traceId) {
5874
+ const MAX_CONTEXT_VALUES = 100;
5875
+ function addSegmentDetailsToContext(replay, traceId, segmentName) {
5872
5876
  const replayContext = replay.getContext();
5873
- if (replayContext.traceIds.size < MAX_TRACE_IDS) {
5877
+ if (traceId && replayContext.traceIds.size < MAX_CONTEXT_VALUES) {
5874
5878
  replayContext.traceIds.add(traceId);
5875
5879
  }
5880
+ if (segmentName && replayContext.segmentNames.size < MAX_CONTEXT_VALUES) {
5881
+ replayContext.segmentNames.add(segmentName);
5882
+ }
5876
5883
  }
5877
5884
 
5878
- function handleAfterSegmentSpanEnd(replay) {
5879
- return (segmentSpan) => {
5880
- if (!replay.isEnabled() || !spanIsSampled(segmentSpan)) {
5885
+ function handleProcessSegmentSpan(replay) {
5886
+ return (spanJSON) => {
5887
+ if (!replay.isEnabled()) {
5881
5888
  return;
5882
5889
  }
5883
- const traceId = segmentSpan.spanContext().traceId;
5884
- if (traceId) {
5885
- addTraceIdToContext(replay, traceId);
5886
- }
5890
+ addSegmentDetailsToContext(replay, spanJSON.trace_id, spanJSON.name || void 0);
5887
5891
  };
5888
5892
  }
5889
5893
 
@@ -5917,10 +5921,7 @@ function handleAfterSendEvent(replay) {
5917
5921
  };
5918
5922
  }
5919
5923
  function handleTransactionEvent(replay, event) {
5920
- const traceId = event.contexts?.trace?.trace_id;
5921
- if (traceId) {
5922
- addTraceIdToContext(replay, traceId);
5923
- }
5924
+ addSegmentDetailsToContext(replay, event.contexts?.trace?.trace_id, event.transaction);
5924
5925
  }
5925
5926
  function handleErrorEvent(replay, event) {
5926
5927
  const replayContext = replay.getContext();
@@ -6683,7 +6684,7 @@ function _parseXhrResponse(body, responseType) {
6683
6684
  if (body instanceof Document) {
6684
6685
  return [body.body.outerHTML];
6685
6686
  }
6686
- if (responseType === "json" && body && typeof body === "object") {
6687
+ if (responseType === "json" && isObjectLike(body)) {
6687
6688
  return [JSON.stringify(body)];
6688
6689
  }
6689
6690
  if (!body) {
@@ -6698,7 +6699,7 @@ function _parseXhrResponse(body, responseType) {
6698
6699
  }
6699
6700
  function _getBodySize(body, responseType) {
6700
6701
  try {
6701
- const bodyStr = responseType === "json" && body && typeof body === "object" ? JSON.stringify(body) : body;
6702
+ const bodyStr = responseType === "json" && isObjectLike(body) ? JSON.stringify(body) : body;
6702
6703
  return getBodySize(bodyStr);
6703
6704
  } catch {
6704
6705
  return void 0;
@@ -6779,7 +6780,7 @@ function addGlobalListeners(replay) {
6779
6780
  }
6780
6781
  }
6781
6782
  });
6782
- client.on("afterSegmentSpanEnd", handleAfterSegmentSpanEnd(replay));
6783
+ client.on("processSegmentSpan", handleProcessSegmentSpan(replay));
6783
6784
  client.on("spanStart", (span) => {
6784
6785
  replay.lastActiveSpan = span;
6785
6786
  });
@@ -6854,46 +6855,50 @@ function getRecordingSamplingOptions() {
6854
6855
  function getHandleRecordingEmit(replay) {
6855
6856
  let hadFirstEvent = false;
6856
6857
  return (event, _isCheckout) => {
6857
- if (!replay.checkAndHandleExpiredSession()) {
6858
- DEBUG_BUILD && debug.warn("Received replay event after session expired.");
6859
- return;
6860
- }
6861
- const isCheckout = _isCheckout || !hadFirstEvent;
6862
- hadFirstEvent = true;
6863
- syncMirrorAttributesFromMutationEvent(event);
6864
- if (replay.clickDetector) {
6865
- updateClickDetectorForRecordingEvent(replay.clickDetector, event);
6866
- }
6867
- replay.addUpdate(() => {
6868
- if (replay.recordingMode === "buffer" && isCheckout) {
6869
- replay.setInitialState();
6870
- }
6871
- if (!addEventSync(replay, event, isCheckout)) {
6872
- return true;
6858
+ try {
6859
+ if (!replay.checkAndHandleExpiredSession()) {
6860
+ DEBUG_BUILD && debug.warn("Received replay event after session expired.");
6861
+ return;
6873
6862
  }
6874
- if (!isCheckout) {
6875
- return false;
6863
+ const isCheckout = _isCheckout || !hadFirstEvent;
6864
+ hadFirstEvent = true;
6865
+ syncMirrorAttributesFromMutationEvent(event);
6866
+ if (replay.clickDetector) {
6867
+ updateClickDetectorForRecordingEvent(replay.clickDetector, event);
6876
6868
  }
6877
- const session = replay.session;
6878
- addSettingsEvent(replay, isCheckout);
6879
- if (replay.recordingMode === "buffer" && session && replay.eventBuffer && !session.dirty) {
6880
- const earliestEvent = replay.eventBuffer.getEarliestTimestamp();
6881
- if (earliestEvent) {
6882
- DEBUG_BUILD && debug.log(`Updating session start time to earliest event in buffer to ${new Date(earliestEvent)}`);
6883
- session.started = earliestEvent;
6884
- if (replay.getOptions().stickySession) {
6885
- saveSession(session);
6869
+ replay.addUpdate(() => {
6870
+ if (replay.recordingMode === "buffer" && isCheckout) {
6871
+ replay.setInitialState();
6872
+ }
6873
+ if (!addEventSync(replay, event, isCheckout)) {
6874
+ return true;
6875
+ }
6876
+ if (!isCheckout) {
6877
+ return false;
6878
+ }
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);
6888
+ }
6886
6889
  }
6887
6890
  }
6888
- }
6889
- if (session?.previousSessionId) {
6891
+ if (session?.previousSessionId) {
6892
+ return true;
6893
+ }
6894
+ if (replay.recordingMode === "session") {
6895
+ void replay.flush();
6896
+ }
6890
6897
  return true;
6891
- }
6892
- if (replay.recordingMode === "session") {
6893
- void replay.flush();
6894
- }
6895
- return true;
6896
- });
6898
+ });
6899
+ } catch (error) {
6900
+ replay.handleException(error);
6901
+ }
6897
6902
  };
6898
6903
  }
6899
6904
  function syncMirrorAttributesFromMutationEvent(event) {
@@ -7044,7 +7049,7 @@ async function sendReplayRequest({
7044
7049
  segment_id
7045
7050
  }
7046
7051
  });
7047
- const { urls, errorIds, traceIds, initialTimestamp } = eventContext;
7052
+ const { urls, errorIds, traceIds, segmentNames, initialTimestamp } = eventContext;
7048
7053
  const client = getClient();
7049
7054
  const scope = getCurrentScope();
7050
7055
  const transport = client?.getTransport();
@@ -7058,6 +7063,7 @@ async function sendReplayRequest({
7058
7063
  timestamp: timestamp / 1e3,
7059
7064
  error_ids: errorIds,
7060
7065
  trace_ids: traceIds,
7066
+ segment_names: segmentNames,
7061
7067
  urls,
7062
7068
  replay_id: replayId,
7063
7069
  segment_id,
@@ -7203,6 +7209,7 @@ class ReplayContainer {
7203
7209
  this._context = {
7204
7210
  errorIds: /* @__PURE__ */ new Set(),
7205
7211
  traceIds: /* @__PURE__ */ new Set(),
7212
+ segmentNames: /* @__PURE__ */ new Set(),
7206
7213
  urls: [],
7207
7214
  initialTimestamp: Date.now(),
7208
7215
  initialUrl: ""
@@ -7875,6 +7882,7 @@ class ReplayContainer {
7875
7882
  _clearContext() {
7876
7883
  this._context.errorIds.clear();
7877
7884
  this._context.traceIds.clear();
7885
+ this._context.segmentNames.clear();
7878
7886
  this._context.urls = [];
7879
7887
  }
7880
7888
  /** Update the initial timestamp based on the buffer content. */
@@ -7900,6 +7908,7 @@ class ReplayContainer {
7900
7908
  initialUrl: this._context.initialUrl,
7901
7909
  errorIds: Array.from(this._context.errorIds),
7902
7910
  traceIds: Array.from(this._context.traceIds),
7911
+ segmentNames: Array.from(this._context.segmentNames),
7903
7912
  urls: this._context.urls
7904
7913
  };
7905
7914
  this._clearContext();