Skip to content

fix: Fix replay privacy code example #11244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions docs/platforms/javascript/common/session-replay/privacy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,51 @@ To scrub the URL in a recording event, use the above `beforeAddRecordingEvent`.
To scrub the URL in a replay event, use `addEventProcessor`:

```javascript
Sentry.addEventProcessor(event) => {
Copy link
Member

Choose a reason for hiding this comment

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

🙈

Sentry.addEventProcessor((event) => {
// Ensure that we specifically look at replay events
if (event.type !== 'replay_event') {
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]');
function urlScrubber(url) {
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);
event.urls = event.urls && event.urls.map(urlScrubber);

return event;
});
```

```typescript
import { Event, ReplayEvent } from "@sentry/types";

Sentry.addEventProcessor((event) => {
// Ensure that we specifically look at replay events
if (!isReplayEvent(event)) {
// Return the event, otherwise the event will be dropped
return event;
}

// Your URL scrubbing function
function urlScrubber(url: string): 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 && event.urls.map(urlScrubber);

return event;
});

function isReplayEvent(event: Event): event is ReplayEvent {
return event.type === "replay_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.
Loading