Add option to avoid sending error metadata

This commit is contained in:
Rémi de Juvigny 2020-12-14 16:15:35 +01:00
parent 4c88a4d447
commit c43e9b21bb
4 changed files with 16 additions and 12 deletions

View File

@ -19,6 +19,8 @@ module.exports = async () => {
// Parse Koa context to add error metadata // Parse Koa context to add error metadata
return sentryInstance.Handlers.parseRequest(event, ctx.request); return sentryInstance.Handlers.parseRequest(event, ctx.request);
}); });
// Manually add Strapi version
scope.setTag('strapi_version', strapi.config.info.strapi);
}); });
} }
throw error; throw error;

View File

@ -1,6 +1,4 @@
{ {
"disabled": false, "dsn": null,
"config": { "sendMetadata": true
"dsn": null
}
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "strapi-plugin-sentry", "name": "strapi-plugin-sentry",
"version": "0.0.0", "version": "3.3.4",
"description": "This is the description of the plugin.", "description": "Send Strapi error events to Sentry",
"strapi": { "strapi": {
"name": "sentry", "name": "sentry",
"icon": "plug", "icon": "plug",

View File

@ -6,6 +6,7 @@ const defaultSettings = require('../config/settings.json');
module.exports = { module.exports = {
isReady: false, isReady: false,
_instance: null, _instance: null,
settings: {},
/** /**
* Initialize Sentry service * Initialize Sentry service
@ -18,22 +19,23 @@ module.exports = {
} }
// Retrieve user settings and merge them with the default ones // Retrieve user settings and merge them with the default ones
const settings = { this.settings = {
...defaultSettings, ...defaultSettings,
...strapi.plugins.sentry.config, ...strapi.plugins.sentry.config,
}; };
// Try to initialize Sentry using the config's DSN
try { try {
// Don't init Sentry if the user has disabled it // Don't init Sentry if no DSN was provided
if (!settings.disabled) { if (this.settings.dsn) {
Sentry.init({ Sentry.init({
dsn: settings.config.dsn, dsn: this.settings.dsn,
environment: strapi.config.environment, environment: strapi.config.environment,
}); });
// Store the successfully initialized Sentry instance // Store the successfully initialized Sentry instance
this._instance = Sentry; this._instance = Sentry;
this.isReady = true; this.isReady = true;
} else {
strapi.log.info('strapi-plugin-sentry is disabled because no Sentry DSN was provided');
} }
} catch (error) { } catch (error) {
strapi.log.warn('Could not set up Sentry, make sure you entered a valid DSN'); strapi.log.warn('Could not set up Sentry, make sure you entered a valid DSN');
@ -69,7 +71,9 @@ module.exports = {
this._instance.withScope(scope => { this._instance.withScope(scope => {
// Configure the Sentry scope using the provided callback // Configure the Sentry scope using the provided callback
configureScope(scope, this._instance); if (this.settings.sendMetadata) {
configureScope(scope, this._instance);
}
// Actually send the Error to Sentry // Actually send the Error to Sentry
this._instance.captureException(error); this._instance.captureException(error);
}); });