项目作者: kuzzleio

项目描述 :
A Kuzzle plugin to send errors to Sentry
高级语言: JavaScript
项目地址: git://github.com/kuzzleio/kuzzle-plugin-sentry.git
创建时间: 2020-02-20T07:53:21Z
项目社区:https://github.com/kuzzleio/kuzzle-plugin-sentry

开源协议:Apache License 2.0

下载


Kuzzle Plugin Sentry

This plugin allows to send the errors encountered by Kuzzle to Sentry for further detailed analysis.

Installation

First, you have to get the Sentry DSN URL associated with the project you want to monitor.
Please refer to Sentry documentation to create a new Node.js project and get your DSN.

One you have it, you have to provide the DSN to the plugin using one of the following method.

  • SENTRY_DSN environment variable
  • plugins.sentry.dsn key in Kuzzle configuration file

Usage

This plugin adds a hook on the request:onError event triggered by Kuzzle each time a request fail.

Each error will be enriched with the authenticated user to allow Sentry to compute the number of user affected by an issue. (See Sentry documentation)

It will send the error to Sentry alongside with other useful informations like:

  • input payload
  • request context

Finally, is adds a Sentry tag containing the controller and action name to quickly identify related events.

Configuration

You can configure the plugin by using Kuzzle configuration file.

Sentry environment

It’s possible to define the Sentry environment to bring even more context to catched errors.

You can either provide the KUZZLE_ENV environment variable or add the following key to the configuration:

  1. {
  2. // kuzzle configuration file
  3. "plugins": {
  4. "sentry": {
  5. "environment": "staging"
  6. }
  7. }
  8. }

Ignore errors

You can define errors that will be ignored and thus not send to Sentry.

By default the plugin will only send the PluginImplementationError.

If you add filters manually, then it will send every errors except those matching the filters.

You can filter errors either by status or by id.

Theses filters can be defined in the configuration file:

  1. {
  2. // kuzzle configuration file
  3. "plugins": {
  4. "sentry": {
  5. "ignore": {
  6. "ids": [
  7. "security.token.verification_error",
  8. "security.token.expired"
  9. ],
  10. "statuses": [ 401, 403 ]
  11. }
  12. }
  13. }
  14. }

Filter sensitive values

Any sensitive information will be filtered in the Sentry report. This include password and authentication tokens.

By default, those values are:

  • context.token._id: contain the authentication token
  • context.token.jwt: authentication token
  • input.jwt: authentication token
  • input.body.password: password of the local strategy

You can add other value to be filtered automatically in the sensitiveValues array:

  1. {
  2. // kuzzle configuration file
  3. "plugins": {
  4. "sentry": {
  5. "sensitiveValues": [
  6. "input.body.fbkeyid"
  7. ]
  8. }
  9. }
  10. }

Exclude Sentry integrations

You can exclude default Sentry integration by providing their name in the configuration.

  1. {
  2. // kuzzle configuration file
  3. "plugins": {
  4. "sentry": {
  5. "excludeIntegrations": [
  6. "Http",
  7. "Console"
  8. ]
  9. }
  10. }
  11. }

Configuration example

  1. {
  2. // kuzzle configuration file
  3. "plugins": {
  4. "sentry": {
  5. // DSN
  6. "dsn": "https://214284...@sentry.io/214284..."
  7. // Sentry environment
  8. "environment": "staging",
  9. // ignore specific errors
  10. "ignore": {
  11. "ids": [
  12. "security.token.verification_error",
  13. "security.token.expired"
  14. ],
  15. "statuses": [ 401, 403 ]
  16. },
  17. // Exclude Sentry default integrations
  18. "excludeIntegrations": [
  19. "Http",
  20. "Console"
  21. ],
  22. // Additional sensitives values to filter before sending the error
  23. "sensitiveValues": [
  24. "input.body.fbkeyid"
  25. ]
  26. }
  27. }
  28. }

Extended API

admin:switch

This plugin also expose an API method in order to enable or disable sending events to Sentry.

JSON payload:

  1. {
  2. "controller": "sentry/admin",
  3. "action": "switch",
  4. "state": "on"
  5. }

HTTP route:

  1. # enable plugin
  2. curl localhost:7512/_plugin/sentry/switch/on
  3. # disable plugin
  4. curl localhost:7512/_plugin/sentry/switch/off

send:generic

Sends an error to sentry.

  1. // Example usage in another plugin
  2. this.context.accessors.sdk.query({
  3. controller: 'sentry/send',
  4. action: 'request',
  5. body: {
  6. error: new Error('failure'),
  7. tags: {
  8. tag1: 'gordon',
  9. tag2: 'alyx'
  10. },
  11. extras: {
  12. some: 'extra data',
  13. whatever: 'you want'
  14. },
  15. request: // Optional errored request
  16. }
  17. })

Example of Sentry report

sentry kuzzle