Implement Sentry Logging Into Node.js App

Sentry Logging For Nodejs App In Express

Sentry Logging For Nodejs App In Express

ade great use of Sentry for it’s unhandled error tracking as well as it’s capabilities for capturing custom messages. Here is a simple implementation to get Sentry up and running in a Node.js app running on Express.

const { sentry } = config;
if (sentry) {
  if (sentry.dsn) {
    // Configure Raven
    // The request handler must be the first middleware on the app
    // The error handler must be before any other error middleware

We opt to store our dsn values in a config file specific to environment.

An example of a config file might look like (Values found in your Sentry Account):

module.exports = {
  env: 'dev',
  http: 8080,
  sentry: {
    clientDsn: '',
    dsn: ''

This should be done as early in the process as possible, essentially as soon as you initialize


you should be initializing Sentry to ensure you capture exceptions at all levels.

Reference: Sentry Implementation Notes

StackOverflow Profile