/egg-raven

A sentry/raven plugin to egg

Primary LanguageJavaScriptMIT LicenseMIT

egg-raven

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-raven --save

Usage

// {app_root}/config/plugin.js
exports.raven = {
  enable: true,
  package: 'egg-raven',
}

Configuration

// {app_root}/config/config.default.js
exports.raven = {
  dsn: 'https://your:very_secure@sentry.server/app_id',
  options: {
    // refer to https://docs.sentry.io/clients/node/config/#optional-settings for more options detail.
    autoBreadcrumbs: {
      http: true
    },
    release: '721e41770371db95eee98ca2707686226b993eda'
  }
}

see config/config.default.js for more detail.

Example

// app/controller/home.js
const { Controller } = require('egg')

class HomeController extends Controller {

  async index () {
    this.ctx.raven.captureBreadcrumb({
      message: 'Received payment confirmation',
      category: 'payment',
      data: {
        amount: 312
      }
    })
    this.ctx.runInBackground(async function backgroundJob () {
      throw new Error('will be recorded into sentry with breadcrumbs')
    })
  }

  async update() {
    throw new Error('will be recorded into sentry with detailed context')
  }

}

module.exports = HomeController

Questions & Suggestions

Please open an issue here.

License

MIT