@sentry/replay 11.0.0-alpha.0 → 11.0.0-alpha.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.
@@ -1,5 +1,5 @@
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
- import { setTimeout as setTimeout$3, htmlTreeAsString, addPerformanceInstrumentationHandler, addLcpInstrumentationHandler, addClsInstrumentationHandler, addInpInstrumentationHandler, serializeFormData, getFetchRequestArgBody, getBodyString, SENTRY_XHR_DATA_KEY, parseXhrResponseHeaders, addClickKeypressInstrumentationHandler, addHistoryInstrumentationHandler } from '@sentry/browser-utils';
1
+ import { GLOBAL_OBJ, normalize, isObjectLike, fill, browserPerformanceTimeOrigin, debug as debug$1, severityLevelFromString, captureException, addBreadcrumb, uuid4, getClient, getCurrentScope, getActiveSpan, getDynamicSamplingContextFromSpan, isSentryRequestUrl, stringMatchesSomePattern, addEventProcessor, debounce as debounce$1, createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader, prepareEvent, getIsolationScope, updateRateLimits, isRateLimited, setContext, getRootSpan, spanToJSON, isBrowser, safeSetSpanJSONAttributes, parseSampleRate, consoleSandbox } from '@sentry/core';
2
+ import { setTimeout as setTimeout$3, htmlTreeAsString, addPerformanceInstrumentationHandler, addLcpInstrumentationHandler, addClsInstrumentationHandler, addInpInstrumentationHandler, getLocationHref, serializeFormData, getFetchRequestArgBody, getBodyString, SENTRY_XHR_DATA_KEY, parseXhrResponseHeaders, addClickKeypressInstrumentationHandler, addHistoryInstrumentationHandler } from '@sentry/browser-utils';
3
3
 
4
4
  const WINDOW = GLOBAL_OBJ;
5
5
  const REPLAY_SESSION_KEY = "sentryReplaySession";
@@ -21,6 +21,8 @@ const MIN_REPLAY_DURATION = 4999;
21
21
  const MIN_REPLAY_DURATION_LIMIT = 5e4;
22
22
  const MAX_REPLAY_DURATION = 36e5;
23
23
 
24
+ const jd="sentry.segment.name.source";
25
+
24
26
  var __defProp = Object.defineProperty;
25
27
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
28
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -4915,11 +4917,9 @@ const ATTRIBUTES_TO_RECORD = /* @__PURE__ */ new Set([
4915
4917
  "aria-disabled",
4916
4918
  "data-sentry-component"
4917
4919
  ]);
4920
+ const BREADCRUMB_RELEVANT_ATTRIBUTES = /* @__PURE__ */ new Set([...ATTRIBUTES_TO_RECORD, "data-sentry-element"]);
4918
4921
  function getAttributesToRecord(attributes) {
4919
4922
  const obj = {};
4920
- if (!attributes["data-sentry-component"] && attributes["data-sentry-element"]) {
4921
- attributes["data-sentry-component"] = attributes["data-sentry-element"];
4922
- }
4923
4923
  for (const key in attributes) {
4924
4924
  if (ATTRIBUTES_TO_RECORD.has(key)) {
4925
4925
  let normalizedKey = key;
@@ -4929,6 +4929,9 @@ function getAttributesToRecord(attributes) {
4929
4929
  obj[normalizedKey] = attributes[key];
4930
4930
  }
4931
4931
  }
4932
+ if (!obj["data-sentry-component"] && attributes["data-sentry-element"]) {
4933
+ obj["data-sentry-component"] = attributes["data-sentry-element"];
4934
+ }
4932
4935
  return obj;
4933
4936
  }
4934
4937
 
@@ -5289,6 +5292,11 @@ class EventBufferSizeExceededError extends Error {
5289
5292
  super(`Event buffer exceeded maximum size of ${REPLAY_MAX_EVENT_BUFFER_SIZE}.`);
5290
5293
  }
5291
5294
  }
5295
+ class WorkerDestroyedError extends Error {
5296
+ constructor() {
5297
+ super("Worker destroyed");
5298
+ }
5299
+ }
5292
5300
 
5293
5301
  class EventBufferArray {
5294
5302
  constructor() {
@@ -5408,7 +5416,7 @@ class WorkerHandler {
5408
5416
  destroy() {
5409
5417
  DEBUG_BUILD && debug.log("Destroying compression worker");
5410
5418
  this._worker.removeEventListener("message", this._onMessage);
5411
- this._pending.forEach((pending) => pending.reject(new Error("Worker destroyed")));
5419
+ this._pending.forEach((pending) => pending.reject(new WorkerDestroyedError()));
5412
5420
  this._pending.clear();
5413
5421
  this._worker.terminate();
5414
5422
  }
@@ -5605,6 +5613,9 @@ class EventBufferProxy {
5605
5613
  await Promise.all(addEventPromises);
5606
5614
  this._fallback.clear();
5607
5615
  } catch (error) {
5616
+ if (error instanceof WorkerDestroyedError) {
5617
+ return;
5618
+ }
5608
5619
  DEBUG_BUILD && debug.exception(error, "Failed to add events when switching buffers.");
5609
5620
  }
5610
5621
  }
@@ -6906,15 +6917,24 @@ function syncMirrorAttributesFromMutationEvent(event) {
6906
6917
  for (const mutation of data.attributes) {
6907
6918
  const node = record.mirror.getNode(mutation.id);
6908
6919
  const meta = node && record.mirror.getMeta(node);
6909
- if (meta?.type !== NodeType.Element) {
6920
+ if (!node || meta?.type !== NodeType.Element) {
6910
6921
  continue;
6911
6922
  }
6923
+ const attributes = { ...meta.attributes };
6924
+ let changed = false;
6912
6925
  for (const [attributeName, value] of Object.entries(mutation.attributes)) {
6926
+ if (!BREADCRUMB_RELEVANT_ATTRIBUTES.has(attributeName)) {
6927
+ continue;
6928
+ }
6913
6929
  if (value === null) {
6914
- delete meta.attributes[attributeName];
6930
+ delete attributes[attributeName];
6915
6931
  } else {
6916
- meta.attributes[attributeName] = value;
6932
+ attributes[attributeName] = value;
6917
6933
  }
6934
+ changed = true;
6935
+ }
6936
+ if (changed) {
6937
+ record.mirror.add(node, { ...meta, attributes });
6918
6938
  }
6919
6939
  }
6920
6940
  }
@@ -7671,12 +7691,15 @@ class ReplayContainer {
7671
7691
  getCurrentRoute() {
7672
7692
  const lastActiveSpan = this.lastActiveSpan || getActiveSpan();
7673
7693
  const lastRootSpan = lastActiveSpan && getRootSpan(lastActiveSpan);
7674
- const attributes = lastRootSpan && spanToJSON(lastRootSpan).data || {};
7675
- const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
7676
- if (!lastRootSpan || !source || !["route", "custom"].includes(source)) {
7694
+ if (!lastRootSpan) {
7695
+ return void 0;
7696
+ }
7697
+ const spanJson = spanToJSON(lastRootSpan);
7698
+ const source = spanJson.attributes[jd];
7699
+ if (!source || !["route", "custom"].includes(source)) {
7677
7700
  return void 0;
7678
7701
  }
7679
- return spanToJSON(lastRootSpan).description;
7702
+ return spanJson.name;
7680
7703
  }
7681
7704
  /**
7682
7705
  * Initialize and start all listeners to varying events (DOM,