Filtering for Cordova
Learn more about how to configure your JavaScript SDK to set up filtering for 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.
Sentry offers Inbound Filters that you can enable per project to filter out various events in sentry.io. You can use our pre-defined inbound filters (e.g. filtering known browser extensions), as well as add your own message-based filters.
However, we recommend filtering at the client-level, because it removes the overhead of sending events you don't actually want. The Sentry SDKs have several configuration options, which are described in this document, to help you filter out events. To learn more about the event fields you can use for filtering, see Event Payloads.
Configure your SDK to filter error events by using the beforeSend callback method and configuring, enabling, or disabling integrations.
You can use the ignoreErrors option to filter out errors that match a certain pattern. This option receives a list of strings and regular expressions to match against the error message. When using strings, partial matches will be filtered out. If you need to filter by exact match, use regex patterns instead.
Sentry.init({
dsn: "___PUBLIC_DSN___",
ignoreErrors: ["fb_xd_fragment", /^Exact Match Message$/],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
ignoreErrors: ["fb_xd_fragment", /^Exact Match Message$/],
});
See ignoreErrors for details.
You can configure a beforeSend callback method to filter error events. 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 and, based on custom logic and the data available on the event, you can either modify the event’s data or drop it completely by returning null. This hook is called for both error and message events.
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSend(event) {
if (event.user) {
// Don't send user's email address
delete event.user.email;
}
return event;
},
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSend(event) {
if (event.user) {
// Don't send user's email address
delete event.user.email;
}
return event;
},
});
See beforeSend for details, and Using Hints for details on the hint object.
You can configure the SDK to avoid sending errors that originate in scripts from certain domains. For example, if your scripts are loaded from cdn.example.com and your site is example.com, you can can configure allowUrls as follows to avoid capturing errors from other domains:
Sentry.init({
allowUrls: [/https?:\/\/((cdn|www)\.)?example\.com/],
});
Sentry.init({
allowUrls: [/https?:\/\/((cdn|www)\.)?example\.com/],
});
Note that this filters errors based on their stack frames, not the URL of the page where the error occurred.
You can also use denyUrls if you want to block errors created on specific URLs from being sent to Sentry.
Use ignoreTransactions to drop transactions whose names match a string or regular expression. Strings match part of the name. Use an anchored regular expression for an exact match. Matching transactions and their child spans are dropped.
Sentry.init({
dsn: "___PUBLIC_DSN___",
ignoreTransactions: ["partial/match", /^Exact Transaction Name$/],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
ignoreTransactions: ["partial/match", /^Exact Transaction Name$/],
});
See ignoreTransactions for details.
Use beforeSendTransaction to modify or drop a completed transaction before it is sent. Return the transaction event to send it, or null to drop it and its child spans.
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSendTransaction(event) {
// Don't send transactions for unimportant routes
if (event.transaction === "/unimportant/route") {
return null;
}
return event;
},
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSendTransaction(event) {
// Don't send transactions for unimportant routes
if (event.transaction === "/unimportant/route") {
return null;
}
return event;
},
});
See beforeSendTransaction for details and Using Hints for the hint argument.
You can filter breadcrumbs by using the beforeBreadcrumb configuration option:
Sentry.init({
// ...
beforeBreadcrumb(breadcrumb, hint) {
return breadcrumb.category === "ui.click" ? null : breadcrumb;
},
});
Sentry.init({
// ...
beforeBreadcrumb(breadcrumb, hint) {
return breadcrumb.category === "ui.click" ? null : breadcrumb;
},
});
See beforeBreadcrumb for details.
Hints are available in two places:
beforeSend/beforeBreadcrumb- Event processors added via
Sentry.addEventProcessor()
Event and breadcrumb hints are objects containing various types of information used to put together an event or a breadcrumb. Typically hints hold the original exception so that additional data can be extracted or grouping can be affected.
For events, hints contain properties such as event_id, originalException, syntheticException (used internally to generate cleaner stack trace), and any other arbitrary data that you attach.
For breadcrumbs, the use of hints is implementation dependent. For XHR requests, the hint contains the xhr object itself; for user interactions the hint contains the DOM element and event name and so forth.
Sentry.init({
// ...
beforeSend(event, hint) {
const error = hint.originalException;
if (
error &&
error.message &&
error.message.match(/database unavailable/i)
) {
event.fingerprint = ["database-unavailable"];
}
return event;
},
});
Sentry.init({
// ...
beforeSend(event, hint) {
const error = hint.originalException;
if (
error &&
error.message &&
error.message.match(/database unavailable/i)
) {
event.fingerprint = ["database-unavailable"];
}
return event;
},
});
originalException
The original exception that caused the Sentry SDK to create the event. This is useful for changing how the Sentry SDK groups events or to extract additional information.
syntheticException
When a string or a non-error object is raised, Sentry creates a synthetic exception so you can get a basic stack trace. This exception is stored here for further data extraction.
event
For breadcrumbs created from browser events, the Sentry SDK often supplies the event to the breadcrumb as a hint. This can be used to extract data from the target DOM element into a breadcrumb, for example.
level / input
For breadcrumbs created from console log interceptions. This holds the original console log level and the original input data to the log function.
response / input
For breadcrumbs created from HTTP requests. This holds the response object (from the fetch API) and the input parameters to the fetch function.
request / response / event
For breadcrumbs created from HTTP requests. This holds the request and response object (from the node HTTP API) as well as the node event (response or error).
xhr
For breadcrumbs created from HTTP requests made using the legacy XMLHttpRequest API. This holds the original xhr object.
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").