From 3baf5598db941b628026b67dee7ce3f0497d7ac0 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 5 Feb 2024 13:15:11 -0500 Subject: [PATCH 1/4] feat(replay): Add docs for scrubbing URLs on the replay event Adds an example for scrubbing URLS from the replay event using `addEventProcessor` Closes https://github.com/getsentry/sentry-javascript/issues/9871 --- .../common/session-replay/privacy.mdx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/platforms/javascript/common/session-replay/privacy.mdx b/docs/platforms/javascript/common/session-replay/privacy.mdx index c93c9e068972b..f6ad2c272f5c2 100644 --- a/docs/platforms/javascript/common/session-replay/privacy.mdx +++ b/docs/platforms/javascript/common/session-replay/privacy.mdx @@ -110,6 +110,30 @@ Sentry.replayIntegration({ We also have [server-side PII scrubbing](/product/data-management-settings/scrubbing/server-side-scrubbing/) for this data. It looks for certain patterns such as American social security numbers, credit cards, and private keys. +### Example: Scrubbing URLs + +URLs can be stored in the recording event (which you can use the above `beforeAddRecordingEvent` to scrub), but they can also be stored in a replay event as well. In order to scrub the latter case, you must use `addEventProcessor`: + +```javascript +Sentry.addEventProcessor((event: Sentry.Event) => { + // Ensure that we specifically look at replay events + if (event.type !== 'replay_event') { + // Return the event, otherwise the event will be dropped + return event; + } + + // Your URL scrubbing function + function urlScrubber(url: string) { + return url.replace(/([a-z0-9]{3}\.[a-z]{5}\.[a-z]{7})/, '[Filtered]'); + } + + // Scrub all URLs with your scrubbing function + event.urls = event.urls.map(urlScrubber); + + return event; +}); +``` + ### Deprecated Options Note that the privacy API prior to version 7.35.0 has been deprecated and replaced with the options above. Please see the [Replay migration guide](https://github.com/getsentry/sentry-javascript/blob/master/packages/replay/MIGRATION.md#upgrading-replay-from-7340-to-7350---6645) for further information. From fbcd06fc49c83237da41c5d14ddea02033ad9381 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 5 Feb 2024 13:15:37 -0500 Subject: [PATCH 2/4] javascript --- docs/platforms/javascript/common/session-replay/privacy.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/javascript/common/session-replay/privacy.mdx b/docs/platforms/javascript/common/session-replay/privacy.mdx index f6ad2c272f5c2..9727307fac955 100644 --- a/docs/platforms/javascript/common/session-replay/privacy.mdx +++ b/docs/platforms/javascript/common/session-replay/privacy.mdx @@ -115,7 +115,7 @@ We also have [server-side PII scrubbing](/product/data-management-settings/scrub URLs can be stored in the recording event (which you can use the above `beforeAddRecordingEvent` to scrub), but they can also be stored in a replay event as well. In order to scrub the latter case, you must use `addEventProcessor`: ```javascript -Sentry.addEventProcessor((event: Sentry.Event) => { +Sentry.addEventProcessor(event) => { // Ensure that we specifically look at replay events if (event.type !== 'replay_event') { // Return the event, otherwise the event will be dropped From 49809e82d425393bb7eeb982ec7d82ba1948a300 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 5 Feb 2024 14:59:11 -0500 Subject: [PATCH 3/4] Update docs/platforms/javascript/common/session-replay/privacy.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/javascript/common/session-replay/privacy.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/platforms/javascript/common/session-replay/privacy.mdx b/docs/platforms/javascript/common/session-replay/privacy.mdx index 9727307fac955..03ec78baa397f 100644 --- a/docs/platforms/javascript/common/session-replay/privacy.mdx +++ b/docs/platforms/javascript/common/session-replay/privacy.mdx @@ -112,7 +112,11 @@ We also have [server-side PII scrubbing](/product/data-management-settings/scrub ### Example: Scrubbing URLs -URLs can be stored in the recording event (which you can use the above `beforeAddRecordingEvent` to scrub), but they can also be stored in a replay event as well. In order to scrub the latter case, you must use `addEventProcessor`: +By default, URLs are stored in both the recording event and the replay event. + +To scrub the URL in the recording event, you can use the above `beforeAddRecordingEvent`. + +To scrub the URL in replay events, you must use `addEventProcessor`: ```javascript Sentry.addEventProcessor(event) => { From 5e416c2d7c2924c0372a6e7f392d1dee82e3ae8a Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 6 Feb 2024 16:46:14 -0500 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Liza Mock --- docs/platforms/javascript/common/session-replay/privacy.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/javascript/common/session-replay/privacy.mdx b/docs/platforms/javascript/common/session-replay/privacy.mdx index 03ec78baa397f..8babcb9bb88b9 100644 --- a/docs/platforms/javascript/common/session-replay/privacy.mdx +++ b/docs/platforms/javascript/common/session-replay/privacy.mdx @@ -112,11 +112,11 @@ We also have [server-side PII scrubbing](/product/data-management-settings/scrub ### Example: Scrubbing URLs -By default, URLs are stored in both the recording event and the replay event. +By default, URLs are stored in both recording and replay events. -To scrub the URL in the recording event, you can use the above `beforeAddRecordingEvent`. +To scrub the URL in a recording event, use the above `beforeAddRecordingEvent`. -To scrub the URL in replay events, you must use `addEventProcessor`: +To scrub the URL in a replay event, use `addEventProcessor`: ```javascript Sentry.addEventProcessor(event) => {