0.3.1 • Published 2 years ago

lit-fastify-bugsnag v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Fastify Bugsnag Plugin

Easily send your application errors to Bugsnag from your Fastify server.

Installation

npm install fastify-bugsnag --save

# OR

yarn add fastify-bugsnag

Usage

const fastify = require('fastify')();

fastify.register(require('fastify-bugsnag'), {
  key: 'Your-Bugsnag-API-Key', // Defaults to process.env.BUGSNAG_API_KEY
  enableReporting: process.env.NODE_ENV === 'production', // OR similar
  bugsnagOptions: {
    appType: 'web',
  }
});

fastify.get('/', async (request, reply) => {
  fastify.bugsnag.leaveBreadcrumb('Visited homepage'); // OR request.bugsnag.leaveBreadcrumb();
});

fastify.get('/error', async (request, reply) => {
  request.bugsnag.notify(new Error('This is a generic error'));
});

Description

The plugin will decorate fastify instance with bugsnag property and request as well. The value behind bugsnag, is a full BugsnagClient. Bugsnag documentation

Be aware that the plugin mimics the behaviour of official Bugsnag Express plugin with appending the request data to the error. That includes body, query and params which may include user data!

Options

ParameterDefault ValueDescription
keyprocess.env.BUGSNAG_API_KEYAPI Key obtained from Bugsnag dashboard project. REQUIRED
enableReportingundefinedSet to true on environments or under conditions you want to report the errors to Bugsnag.
bugsnagOptions{}Additional configuration options for Bugsnag Client.

License

Licensed under MIT.