All Projects → hydra-newmedia → hapi-sentry

hydra-newmedia / hapi-sentry

Licence: MIT license
A hapi plugin for request error logging to Sentry

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hapi-sentry

good-sentry
Sentry broadcasting for good process monitor
Stars: ✭ 15 (-37.5%)
Mutual labels:  hapi, sentry, hapi-sentry
hapi-sequelizejs
A hapi.js plugin to connect with Sequelize ORM
Stars: ✭ 56 (+133.33%)
Mutual labels:  hapi, hapi-plugin
hapi-now-auth
Hapi token auth for bearer and jwt
Stars: ✭ 43 (+79.17%)
Mutual labels:  hapi, hapi-plugin
hapi-dev-errors
A hapi plugin to return better error details and skip the look at command line to catch the issue.
Stars: ✭ 58 (+141.67%)
Mutual labels:  hapi, hapi-plugin
hapi-statsd
A hapi plugin for sending request round trip metrics to statsd
Stars: ✭ 29 (+20.83%)
Mutual labels:  hapi, hapi-plugin
hapi-plugin-mysql
Hapi plugin for MySQL
Stars: ✭ 17 (-29.17%)
Mutual labels:  hapi, hapi-plugin
hapi-docs
Beautiful API documentation generator for Hapi using Vue
Stars: ✭ 64 (+166.67%)
Mutual labels:  hapi, hapi-plugin
hapi-good-winston
A good reporter to send and log events with winston
Stars: ✭ 21 (-12.5%)
Mutual labels:  hapi, hapi-plugin
hapi-mongo-models
📦 A hapi plugin for `mongo-models`
Stars: ✭ 101 (+320.83%)
Mutual labels:  hapi, hapi-plugin
hapi-auth-bearer-simple
Hapi authentication plugin for bearer token validation
Stars: ✭ 16 (-33.33%)
Mutual labels:  hapi
react-native-multi-toggle-switch
MultiToggle Switch for React-Native
Stars: ✭ 17 (-29.17%)
Mutual labels:  npm-package
NodeJS Mongo BoilerPlate
CRUD Blog using NodeJS,Express, MongoDB
Stars: ✭ 18 (-25%)
Mutual labels:  sentry
odoc
Next.js based Static 📓 Documentation Site Generator
Stars: ✭ 17 (-29.17%)
Mutual labels:  npm-package
sentry-horn
Swift based sentry iOS application
Stars: ✭ 15 (-37.5%)
Mutual labels:  sentry
img2gcode
convert jpg, png,gif to gcode with nodejs and jimp
Stars: ✭ 31 (+29.17%)
Mutual labels:  npm-package
raven-python-lambda
Sentry/Raven SDK Integration For AWS Lambda (python) and Serverless
Stars: ✭ 48 (+100%)
Mutual labels:  sentry
sentry-prometheus
Export hosted sentry statsd metrics to prometheus
Stars: ✭ 22 (-8.33%)
Mutual labels:  sentry
js-id-number
JavaScript ID Number Toolkit | A collection of identification number validators with uniform interfaces for JavaScript.
Stars: ✭ 22 (-8.33%)
Mutual labels:  npm-package
check-disk-space
Light multi-platform disk space checker without third-party for Node.js
Stars: ✭ 55 (+129.17%)
Mutual labels:  npm-package
docker-google-lighthouse-puppeteer
Google Lighthouse + Puppeteer / Docker Image
Stars: ✭ 29 (+20.83%)
Mutual labels:  npm-package

hapi-sentry

package on npm David GitHub Workflow Status node 12+ required GitHub license

A hapi plugin for request error logging to Sentry.

Usage

Use the hapi plugin like this:

const server = hapi.server();
await server.register({
  plugin: require('hapi-sentry'),
  options: {
    client: { dsn: 'dsn-here' },
  },
});

This setup will:

  • Initialize Sentry regularly, which should capture all global errors and unhandled promise rejects
  • Capture all unhandled exceptions thrown or returned in routes
  • Use request data and request.auth.credentials to enhance errors from routes

You can use the following options to customize this behavior further.

Options

The plugin options, you can pass in while registering are the following:

property type description
baseUri string uri to be used as base for captured urls
scope.tags object An array of tags to be sent with every event
scope.tags.name string The name of a tag
scope.tags.value any The value of a tag
scope.extra object An object of arbitrary format to be sent as extra data on every event
client object required A @sentry/node instance which was already initialized (using Sentry.init) OR an options object to be passed to an internally initialized @sentry/node (client.dsn is only required in the latter case)
client.dsn string/false required The Dsn used to connect to Sentry and identify the project. If false, the SDK will not send any data to Sentry.
client.debug boolean Turn debug mode on/off
client.release string Tag events with the version/release identifier of your application
client.environment string The current environment of your application (e.g. 'production')
client.sampleRate number A global sample rate to apply to all events (0 - 1)
client.maxBreadcrumbs number The maximum number of breadcrumbs sent with events. Default: 100
client.attachStacktrace any Attaches stacktraces to pure capture message / log integrations
client.sendDefaultPii boolean If this flag is enabled, certain personally identifiable information is added by active integrations
client.serverName string Overwrite the server name (device name)
client.beforeSend func A callback invoked during event submission, allowing to optionally modify the event before it is sent to Sentry
client.beforeBreadcrumb func A callback invoked when adding a breadcrumb, allowing to optionally modify it before adding it to future events.
trackUser boolean Whether or not to track the user via the per-request scope. Default: true
catchLogErrors boolean/array Handles capturing server.log and request.log events. Default: false
useDomainPerRequest boolean Whether or not to use Domains for seperating request processing. Only activate this feature, if you really need to seperate breadcrumbs, etc. of requests. It utilizes a deprecated Node.js feature which reduces performance. Default: false

The baseUri option is used internally to get a correct URL in sentry issues. The scope option is used to set up a global Scope for all events and the client option is used as a Sentry instance or to initialize an internally used Sentry instance.

The internally used client (initialized in either way) is accessible through server.plugins['hapi-sentry'].client.

Using your own Sentry instance

You can pass a Sentry instance to the client option if you already initialized your own like this:

const server = hapi.server();
const Sentry = require('sentry');
Sentry.init({ dsn: 'dsn-here' });
await server.register({ plugin: require('hapi-sentry'), options: { client: Sentry } });

Scope

You can alter the scope of an event in every hapi route handler by accessing request.sentryScope. Just use some of the Scopes methods to add breadcrumbs, set extra, fingerprint or level information, etc. like this:

server.route({
  method: 'GET',
  path: '/your/route',
  handler(request) {
    try {
      // ... some logic here
    } catch (error) {
      request.sentryScope.setExtra('someErrorSpecificInfo', 'yourInformation');
      throw error;
    }
  },
});

Capturing server.log and request.log events

You can enable capturing of request.log and server.log events using the catchLogErrors option. All events which are Error objects and are tagged by one of ['error', 'fatal', 'fail'] are automatically being tracked when catchLogErrors is set to true, e.g.:

request.log(['error', 'foo'], new Error('Oh no!'));
server.log(['error', 'foo'], new Error('No no!'));

The considered tags can be changed by setting catchLogErrors to a custom array of tags like ['error', 'warn', 'failure'].

Capturing the request body

hapi-sentry currently does not capture the body for performance reasons. You can use the following snippet to capture the body in all sentry errors:

server.ext({
  type: 'onPostAuth',
  method(request, h) {
    request.payload && request.sentryScope.setExtra('payload', request.payload);
    return h.continue;
  },
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].