Code Monkey home page Code Monkey logo

egg-sentry's Introduction

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

exports.sentry = {
  dsn: 'https://819e74a6e948468b9740680cfa87986b:[email protected]/246025',
};

// config/plugin.js

exports.sentry = {
  enable: true,
  package: 'egg-sentry',
};

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 = require('egg').Service;

class SentryService extends Service {
  /**
   * filter errors need to be submitted to sentry
   *
   * @param {any} err error
   * @return {boolean} true for submit, default true
   * @memberof SentryService
   */
  judgeError(err) {
    // ignore HTTP Error
    return !(err.status && err.status > 500);
  }
  
  // user information
  get user() {
    return this.ctx.session.user;
  }

  get extra() {
    return {
      ip: this.ctx.ip,
      payload: this.ctx.request.body,
    };
  }

  get tags() {
    return {
      url: this.ctx.request.url,
    };
  }
}

module.exports = 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.