Skip to content

A Fastify plugin for attaching Sentry to the framework

License

Notifications You must be signed in to change notification settings

zentered/fastify-sentry

 
 

Repository files navigation

Fastify Sentry Plugin using the Sentry SDK

Test Semantic Release Conventional Commits

Installation

npm i @zentered/fastify-sentry

or

yarn add @zentered/fastify-sentry

Usage

const fastifySentry = require('@zentered/fastify-sentry')

const errorHandler = (err, req, reply) => {
  reply.status(req.body.error).send({
    message: req.body.message,
    e: err.message
  })
}

app.register(fastifySentry, {
  dsn: process.env.SENTRY_DSN,
  environment: 'development',
  tracing: true,
  tracesSampleRate: 1.0,
  errorHandler
})

fastify.get('/', async (request, reply) => {
  // Errors in async functions are automatically caught
  throw new Error('Oops')
})

Description

This plugin adds the Sentry SDK error handler by using setErrorHandler. It also adds certain metadata, namely the path and the ip parameters of the request, to both the User context and Tag context of Sentry. If you use jwt authentication, the user id is also added to Sentry.

Options

Option Required Description
dsn required The DSN specified by Sentry.io to properly log errors to.
tracing optional Default false, enable Sentry tracing.
errorHandler optional Custom error handler for errors.
errorFilter optional Error filter to selectively disable Sentry reporting.

You can find further options in the Node.js Guide on Sentry.io

Author

Alex Papageorgiou

License

Licensed under GPLv3.

About

A Fastify plugin for attaching Sentry to the framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.9%
  • Shell 1.1%