kuzzle-plugin-sentry
v1.0.0
Published
Kuzzle plugin reporting the errors of failed API requests to Sentry
Readme
Kuzzle Plugin Sentry
This plugin allows to send the errors encountered by Kuzzle to Sentry for further detailed analysis.
Requirements
- Kuzzle 2
- Node.js >= 20.19.0 (required by
@sentry/node11)
Installation
Install the plugin in your Kuzzle application with npm install kuzzle-plugin-sentry, then enable it as any other Kuzzle plugin.
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_DSNenvironment variableplugins.sentry.dsnkey 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:
{
// kuzzle configuration file
"plugins": {
"sentry": {
"environment": "staging"
}
}
}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:
{
// kuzzle configuration file
"plugins": {
"sentry": {
"ignore": {
"ids": [
"security.token.verification_error",
"security.token.expired"
],
"statuses": [ 401, 403 ]
}
}
}
}Filter sensitive values
The request reported to Sentry never contains the authentication token nor the request headers.
The input.body.password value (password of the local strategy) is always replaced by [Filtered].
You can add other values to be filtered automatically in the sensitiveValues array. Each entry is a path in the reported request, which has the following shape:
{
requestId: '...',
context: { user: { _id: '...' }, connection: { protocol: 'http' } },
input: { controller, action, args, body, volatile }
}{
// kuzzle configuration file
"plugins": {
"sentry": {
"sensitiveValues": [
"input.body.fbkeyid"
]
}
}
}Exclude Sentry integrations
You can exclude default Sentry integration by providing their name in the configuration.
{
// kuzzle configuration file
"plugins": {
"sentry": {
"excludeIntegrations": [
"Http",
"Console"
]
}
}
}Configuration example
{
// kuzzle configuration file
"plugins": {
"sentry": {
// DSN
"dsn": "https://[email protected]/214284..."
// Sentry environment
"environment": "staging",
// ignore specific errors
"ignore": {
"ids": [
"security.token.verification_error",
"security.token.expired"
],
"statuses": [ 401, 403 ]
},
// Exclude Sentry default integrations
"excludeIntegrations": [
"Http",
"Console"
],
// Additional sensitives values to filter before sending the error
"sensitiveValues": [
"input.body.fbkeyid"
]
}
}
}Extended API
admin:switch
This plugin also expose an API method in order to enable or disable sending events to Sentry.
JSON payload:
{
"controller": "sentry/admin",
"action": "switch",
"state": "on"
}HTTP route:
# enable plugin
curl localhost:7512/_plugin/sentry/switch/on
# disable plugin
curl localhost:7512/_plugin/sentry/switch/offsend:generic
Sends an error to Sentry. The ignore filters do not apply to it.
The error can be an error message, or an object with message and optional name and stack properties. The action returns { sent: true, eventId }, or { sent: false } when the plugin is disabled or has no DSN.
// Example usage in another plugin
this.context.accessors.sdk.query({
controller: 'sentry/send',
action: 'generic',
body: {
error: { message: 'failure', name: 'MyPluginError' },
tags: {
tag1: 'gordon',
tag2: 'alyx'
},
extras: {
some: 'extra data',
whatever: 'you want'
},
request: { input: { controller: 'document', action: 'create' } } // Optional errored request
}
})Example of Sentry report

