Skip to content

Commit

Permalink
feat: sentry.io error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusgerdin committed Aug 18, 2020
1 parent db4608f commit 9253b36
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/events/rtbyteCommandError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
const Sentry = require('@sentry/node');

module.exports = class extends Event {

Expand All @@ -8,6 +9,14 @@ module.exports = class extends Event {
}

async run(message, command, params, error) {
Sentry.withScope(scope => {
scope.setTag('error-type', 'command');
scope.setLevel(this.client.options.production ? 'error' : 'debug');
scope.setContext('Message', message);

Sentry.captureException(error);
});

if (this.client.settings.get('logs.commandError')) await this.commandErrorLog(message, command, params, error);
return message.reject(message.language.get('COMMAND_ERROR'));
}
Expand Down
8 changes: 8 additions & 0 deletions src/events/rtbyteEventError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
const Sentry = require('@sentry/node');
const errorEvents = ['rtbyteCommandError', 'rtbyteEventError', 'rtbyteFinalizerError', 'rtbyteMonitorError', 'rtbyteTaskError'];

module.exports = class extends Event {
Expand All @@ -9,6 +10,13 @@ module.exports = class extends Event {
}

async run(event, args, error) {
Sentry.withScope(scope => {
scope.setTag('error-type', 'event');
scope.setLevel(this.client.options.production ? 'error' : 'debug');

Sentry.captureException(error);
});

const guild = args[0].guild ? args[0].guild : args[0].message ? args[0].message.guild : args[0];
if (this.client.settings.get('logs.eventError') && !errorEvents.includes(event.name)) await this.eventErrorLog(event, args, error, guild);
}
Expand Down
9 changes: 9 additions & 0 deletions src/events/rtbyteFinalizerError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
const Sentry = require('@sentry/node');

module.exports = class extends Event {

Expand All @@ -8,6 +9,14 @@ module.exports = class extends Event {
}

async run(message, command, response, timer, finalizer, error) {
Sentry.withScope(scope => {
scope.setTag('error-type', 'finalizer');
scope.setLevel(this.client.options.production ? 'error' : 'debug');
scope.setContext('Message', message);

Sentry.captureException(error);
});

if (this.client.settings.get('logs.finalizerError')) await this.finalizerErrorLog(message, command, response, timer, finalizer, error);
}

Expand Down
9 changes: 9 additions & 0 deletions src/events/rtbyteMonitorError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
const Sentry = require('@sentry/node');

module.exports = class extends Event {

Expand All @@ -8,6 +9,14 @@ module.exports = class extends Event {
}

async run(message, monitor, error) {
Sentry.withScope(scope => {
scope.setTag('error-type', 'monitor');
scope.setLevel(this.client.options.production ? 'error' : 'debug');
scope.setContext('Message', message);

Sentry.captureException(error);
});

if (this.client.settings.get('logs.monitorError')) await this.monitorErrorLog(message, monitor, error);
}

Expand Down
9 changes: 9 additions & 0 deletions src/events/rtbyteTaskError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
const Sentry = require('@sentry/node');

module.exports = class extends Event {

Expand All @@ -8,6 +9,14 @@ module.exports = class extends Event {
}

async run(scheduledTask, task, error) {
Sentry.withScope(scope => {
scope.setTag('error-type', 'task');
scope.setLevel(this.client.options.production ? 'error' : 'debug');
scope.setContext(scheduledTask);

Sentry.captureException(error);
});

if (this.client.settings.get('logs.taskError')) await this.eventErrorLog(scheduledTask, task, error);
}

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
Client: require('./lib/RTByteClient'),
RTByteClient: require('./lib/RTByteClient'),
RTByteSentry: require('./lib/RTByteSentry'),
ModCase: require('./lib/structures/ModCase'),
ModEmbed: require('./lib/structures/ModEmbed'),
Util: require('./lib/util/Util')
Expand Down
21 changes: 21 additions & 0 deletions src/lib/RTByteSentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { version: klasaVersion } = require('klasa');
const { version: discordVersion } = require('discord.js');
const { sentryIngestURL } = require('../config');
const Sentry = require('@sentry/node');
const os = require('os');

Sentry.init({
dsn: sentryIngestURL,
// eslint-disable-next-line no-process-env
release: `rtbyte@${process.env.npm_package_version}`
});

Sentry.configureScope(scope => {
scope.setTags({
host: `${os.hostname}`,
'klasa-version': klasaVersion,
'd.js-version': discordVersion
});
});

if (sentryIngestURL) console.log('Sentry.io error reporting is active.');

0 comments on commit 9253b36

Please sign in to comment.