Skip to content

feat(replay): Add _experiments.ignoreMutations option - #16816

Merged
mydea merged 3 commits into
developfrom
fn/replay-ignoreMutations
Jul 7, 2025
Merged

mydea merged 3 commits into
developfrom
fn/replay-ignoreMutations

Conversation

@mydea

@mydea mydea commented Jul 4, 2025 •

Copy link
Copy Markdown
Member

This option allows to configure a selector list of elements to not capture mutation for.

This is under _experiments for now:

Sentry.replayIntegration({
  _experiments: {
    ignoreMutations: ['.dragging']
  }
});

Fixes #16797

@mydea
mydea requested a review from chargome July 4, 2025 12:24
@mydea mydea self-assigned this Jul 4, 2025
@github-actions

github-actions Bot commented Jul 4, 2025 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.99 kB - -
@sentry/browser - with treeshaking flags 23.76 kB - -
@sentry/browser (incl. Tracing) 39.59 kB - -
@sentry/browser (incl. Tracing, Replay) 77.77 kB +0.11% +80 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.85 kB +0.11% +76 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 82.49 kB +0.05% +33 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 94.65 kB +0.09% +83 B 🔺
@sentry/browser (incl. Feedback) 40.75 kB - -
@sentry/browser (incl. sendFeedback) 28.7 kB - -
@sentry/browser (incl. FeedbackAsync) 33.59 kB - -
@sentry/react 25.76 kB - -
@sentry/react (incl. Tracing) 41.58 kB - -
@sentry/vue 28.37 kB - -
@sentry/vue (incl. Tracing) 41.37 kB - -
@sentry/svelte 24.01 kB - -
CDN Bundle 25.5 kB - -
CDN Bundle (incl. Tracing) 39.6 kB - -
CDN Bundle (incl. Tracing, Replay) 75.58 kB +0.12% +86 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 81.05 kB +0.11% +87 B 🔺
CDN Bundle - uncompressed 74.5 kB - -
CDN Bundle (incl. Tracing) - uncompressed 117.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.92 kB +0.11% +247 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.75 kB +0.11% +247 B 🔺
@sentry/nextjs (client) 43.22 kB - -
@sentry/sveltekit (client) 40.04 kB - -
@sentry/node 162.02 kB - -
@sentry/node - without tracing 98.64 kB - -
@sentry/aws-serverless 124.4 kB - -

View base workflow run

Comment thread packages/replay-internal/src/replay.ts Resolved
mydea added 2 commits July 7, 2025 14:27
This option allows to configure a selector list of elements to not capture mutation for.
@mydea mydea changed the title feat(replay): Add ignoreMutations option feat(replay): Add _experiments.ignoreMutations option Jul 7, 2025
@mydea
mydea force-pushed the fn/replay-ignoreMutations branch from 912ed5c to 10752f4 Compare July 7, 2025 12:38
@mydea
mydea marked this pull request as ready for review July 7, 2025 12:38
@mydea
mydea requested a review from a team as a code owner July 7, 2025 12:38
Comment on lines +13 to +14
const el: HTMLElement | null = node.nodeType === node.ELEMENT_NODE ? (node as HTMLElement) : node.parentElement;
return el;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of declaring the el constant here?
Is it to make debugging easier? 🙂

Suggested change
const el: HTMLElement | null = node.nodeType === node.ELEMENT_NODE ? (node as HTMLElement) : node.parentElement;
return el;
return node.nodeType === node.ELEMENT_NODE ? (node as HTMLElement) : node.parentElement;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just vendored in from the rrweb implementation!

@mydea
mydea merged commit f52ab47 into develop Jul 7, 2025
@mydea
mydea deleted the fn/replay-ignoreMutations branch July 7, 2025 14:40
mydea added a commit to getsentry/rrweb that referenced this pull request Oct 27, 2026
…341)

`onMutation` can currently only accept or drop a whole mutation batch.
The Replay SDK needs per-mutation control for two cases:

- **getsentry/sentry-javascript#16831**: mutations inside blocked
elements still count toward `mutationLimit`, because `onMutation` runs
before rrweb's block checks. Heavy SVG/D3 widgets can stop replays even
when they are blocked.
- **`_experiments.ignoreMutations`**
(getsentry/sentry-javascript#16816): it currently drops the whole batch
if any one mutation matches, which also drops unrelated mutations.

This PR adds two things:

- `onMutation` may return a `MutationRecord[]`. rrweb then processes
only that subset. Returning `false` still skips the batch. Returning
`true` or nothing still processes everything.
- `onMutation` gets a second `helpers` argument with `isBlocked(node)`.
It uses the recorder's own
`blockClass`/`blockSelector`/`unblockSelector` rules, checking ancestors
too, so callers don't have to re-implement them.

Overhead is kept to a minimum. The helpers object is created once per
observer, not per batch. `isBlocked` only runs when the caller invokes
it, so the SDK can limit it to batches that exceed the mutation limit.
The only new per-batch work is one `Array.isArray` check. This also
drops the per-batch `.bind()` on `processMutations`, which is already an
arrow-function property. Existing callers that return booleans behave
the same.

<!-- junior-request-attribution:start -->
via **Francesco Gringl-Novy**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0CA8FXFXAS%3A1792739987.100699 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0CA8FXFXAS%3A1792739987.100699)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0CA8FXFXAS%3A1792739987.100699/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Francesco Gringl-Novy <francesco.novy@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High resource usage when using replay

3 participants