getsentry / sentry-docs

Sentry's documentation (and tools to build it)
https://docs.sentry.io
Other
326 stars 1.43k forks source link

"Scrubbing URLs" Example code will not pass type check #11090

Closed ndmason1 closed 1 week ago

ndmason1 commented 1 month ago

Core or SDK?

Platform/SDK

Which part? Which one?

React SDK

Description

Context: Using latest react SDK (8.26.0 at time of writing) in a React 18 with Typescript app.

I am trying to use Sentry.addEventProcessor to scrub PII from URLs (specifically query params) following the example from this page. The example provided has a line that looks like:

event.urls = event.urls.map(urlScrubber);

This will not work as written, because the Sentry.Event type does not have a urls property. I don't see a more specific type for the replay events (there is just the type field, but I can't use that to narrow the type if there isn't a TS type with more properties).

Additionally, the code snippet on that page is tagged as javascript, but it includes a TS type annotation here:

function urlScrubber(url: string) {

so it isn't valid JS.

So I am (a) reporting the incorrect doc here and (b) looking for support on the proper way to do this, if it exists (or confirmation that the SDK needs an update to support this)

Suggested Solution

Suggest adding the urls property to the Event type definition since that was probably the intention?

getsantry[bot] commented 1 month ago

Assigning to @getsentry/support for routing ⏲️

mydea commented 1 week ago

Hey, so the snippet is indeed incorrect, I will fix it - it should be proper JS!

This will still complain in TS, though. I will update the example to also include a TS-compatible way!