Filtering

Learn more about how to configure your SDK to filter events reported to Sentry.

When you add Sentry to your app, you get a lot of valuable information about errors and performance. And lots of information is good -- as long as it's the right information, at a reasonable volume.

The Sentry SDKs have several configuration options to help you filter out events.

We also offer Inbound Filters to filter events in sentry.io. We recommend filtering at the client level though, because it removes the overhead of sending events you don't actually want. Learn more about the fields available in an event.

Configure your SDK to filter error events by using the beforeSend callback method and configuring, enabling, or disabling integrations.

All Sentry SDKs support the beforeSend callback method. Because it's called immediately before the event is sent to the server, this is your last chance to decide not to send data or to edit it. beforeSend receives the event object as a parameter, which you can use to either modify the event’s data or drop it completely by returning null, based on custom logic and the data available on the event.

Copied
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.beforeSend = { event in
        // modify event here or return nil to discard the event
        return event
    }
}

Note also that breadcrumbs can be filtered, as discussed in our Breadcrumbs documentation.

To prevent certain spans from being reported to Sentry, use the beforeSendSpan configuration option, which allows you to provide a function to evaluate the current span and drop it if it's not one you want.

Copied
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.beforeSendSpan = { span in
        // Modify or drop the span here
        if (span.description == "unimportant span") {
            // Don't send the span to Sentry
            return nil
        }
        return span
    }
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").