Sentry for Express
Learn how to set up Sentry in your Express app on Node.js, Bun, or Deno.
Express doesn't need its own Sentry SDK. Set up Sentry for the runtime your app runs on, and the SDK instruments Express automatically: expressIntegration captures errors from your routes and middleware, and creates spans for incoming requests when tracing is enabled.
Errors with a 3xx or 4xx status code are skipped, since they're usually expected redirects or client errors. To change which errors are captured, pass a shouldHandleError callback to expressIntegration():
Copied
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.expressIntegration({
shouldHandleError(error) {
const status = Number(error.status ?? error.statusCode ?? 500);
// Capture 401/403 in addition to the default 5xx errors
return status === 401 || status === 403 || status >= 500;
},
}),
],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.expressIntegration({
shouldHandleError(error) {
const status = Number(error.status ?? error.statusCode ?? 500);
// Capture 401/403 in addition to the default 5xx errors
return status === 401 || status === 403 || status >= 500;
},
}),
],
});
If you capture errors yourself in your own error-handling middleware, set shouldHandleError: false to avoid duplicate events.
Was this helpful?
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").
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").