feat(replay): Add beforeAddRecordingEvent Replay option#8124
feat(replay): Add beforeAddRecordingEvent Replay option#8124
beforeAddRecordingEvent Replay option#8124Conversation
Allows you to modify/filter recording events for replays. Note this is only a recording event, not the replay event.
f6ab9a2 to
f8cfe73
Compare
size-limit report 📦
|
| ({ replay, integration } = await mockSdk({ | ||
| replayOptions: { | ||
| beforeAddRecordingEvent: event => { | ||
| const eventData = event.data as Record<string, any>; |
There was a problem hiding this comment.
Types are not ideal here :/
I'll work on a follow-up to see how we can improve them.
|
|
||
| ## Unreleased | ||
|
|
||
| - feat(replay): Add `beforeAddRecordingEvent` Replay option |
There was a problem hiding this comment.
No action required, just as a side note: You don't have to add this entry to the unreleased section. We always create a changelog PR when we release which is when we add all entries.
There was a problem hiding this comment.
Yeah thought it would make it easier for whoever is publishing
| /** | ||
| * Callback before adding a recording event | ||
| */ |
There was a problem hiding this comment.
l: Let's add a sentence about what to use this function for and what to return(i.e. returning null will drop the event). Just to make it a little clearer to users
There was a problem hiding this comment.
Also, we should probably point out that dropping one event here won't result in the entire replay being dropped, wdyt?
There was a problem hiding this comment.
I've also added the condition that we only call this callback for custom events, e.g. only when event.type == 5 (otherwise we risk user error breaking the replay), thoughts on that @Lms24?
There was a problem hiding this comment.
Yes that sounds good to me 👍 less chances for folks to screw things up with the actual replay! Let's just make sure we point this out in the JSDoc
|
@Lms24 One question I forgot to ask... does this option belong in the Replay integration instanciation, or root Sentry SDK |
I thought about this a little and I'd prefer it to be a Replay integration option, especially given that it's now only called for custom events. I know that his option is in a way similar to e.g. |
Agreed 👍 |
|
@billyvg @Lms24 Thank you so much for adding this, we'll try it out soon. ✌️ Regarding whether options are better placed in
|
|
@jcfrancisco We recently added some documentation for this. FWIW this is also how we do it at Sentry. |

Allows you to modify/filter custom recording events for replays. Note this is only a recording event, not the replay event. Custom means that the events do not relate or affect the DOM recording, but rather they are additional events that the Replay integration adds for additional features.
This adds an option for the Replay integration
beforeAddRecordingEventto process a recording (rrweb) event before it is added to the event buffer. Example:Closes #8127