Egg-Sentry
Sentry Plugin for Eggjs
About
This module is to helper developers setup sentry with least work.
Getting Started
Install egg-sentry as an npm module and save it to your package.json file as a development dependency:
npm install --save egg-sentry
Add sentry configuration:
// config/config.default.js exportssentry = dsn: 'https://819e74a6e948468b9740680cfa87986b:38aaa0c0d51e463597493c250ff11f83@sentry.io/246025';
Replace the dsn
with your own one, get details at Sentry.
From now on, expections are able to submit to sentry. What if we wanna more custom information, such as logined user?
To get a rich context, implemet Egg Service in app/service/sentry.js
file and there are four member properties or methods are supported.
// app/service/sentry.js 'use strict'; const Service = Service; /** * filter errors need to be submitted to sentry * * @param * @return * @memberof SentryService */ { // ignore HTTP Error return !errstatus && errstatus > 500; } // user information { return thisctxsessionuser; } { return ip: thisctxip payload: thisctxrequestbody ; } { return url: thisctxrequesturl ; } moduleexports = SentryService;
These infomation would be automaticlly injected into error context.
Bootstrap
Replace the dsn
in test/fixtures/apps/sentry-test/config/config.unittest.js
and then run npm start
to see what would happend.