Skip to content

Commit

Permalink
Final log update, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Jan 28, 2024
1 parent 9ea427c commit f60e398
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
71 changes: 37 additions & 34 deletions src/discord/events/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MessageContextMenuCommandInteraction,
UserContextMenuCommandInteraction,
} from 'discord.js';
// import * as Sentry from '@sentry/node';
import * as Sentry from '@sentry/node';
import { ErrorEvent } from '../@types/eventDef';

const F = f(__filename);
Expand Down Expand Up @@ -51,41 +51,40 @@ export default async function handleError(
const embed = new EmbedBuilder()
.setColor(Colors.Red);

// if (interaction) {
// // log.debug(F, 'Interaction found, sending error to GlitchTip');
// Sentry.captureException(errorData, {
// tags: {
// command: commandName,
// context: await commandContext(interaction),
// },
// user: {
// id: interaction.user.id,
// username: interaction.user.username,
// },
// });
// } else {
// // log.debug(F, 'No interaction, sending error to GlitchTip');
// Sentry.captureException(errorData);
// }

// If this is production, send a message to the channel and alert the developers
if (env.NODE_ENV === 'production') {
// if (interaction) {
// // log.debug(F, 'Interaction found, sending error to rollbar');
// global.rollbar.error(errorStack, {
// tags: {
// command: commandName,
// context: await commandContext(interaction),
// },
// user: {
// id: interaction.user.id,
// username: interaction.user.username,
// },
// });
// } else {
// // log.debug(F, 'No interaction, sending error to rollbar');
// global.rollbar.error(errorStack);
// }
if (interaction) {
log.debug(F, 'Interaction found, sending error to GlitchTip');
Sentry.captureException(errorData, {
tags: {
command: commandName,
context: await commandContext(interaction),
},
user: {
id: interaction.user.id,
username: interaction.user.username,
},
});
} else {
log.debug(F, 'No interaction, sending error to GlitchTip');
Sentry.captureException(errorData);
}
if (interaction) {
// log.debug(F, 'Interaction found, sending error to rollbar');
global.rollbar.error(errorStack, {
tags: {
command: commandName,
context: await commandContext(interaction),
},
user: {
id: interaction.user.id,
username: interaction.user.username,
},
});
} else {
// log.debug(F, 'No interaction, sending error to rollbar');
global.rollbar.error(errorStack);
}

// Get channel we send errors to
const channel = await discordClient.channels.fetch(env.CHANNEL_BOTERRORS) as TextChannel;
Expand Down Expand Up @@ -150,3 +149,7 @@ export const error: ErrorEvent = {
process.on('unhandledRejection', async (errorData: Error) => {
await handleError(errorData);
});

process.on('uncaughtException', async (errorData: Error) => {
await handleError(errorData);
});
25 changes: 13 additions & 12 deletions src/global/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ import Rollbar, { Level } from 'rollbar';
import * as Sentry from '@sentry/node';
import { env } from './env.config';

const RollbarTransport = require('winston-transport-rollbar-3');

// Setup Rollbar
const rollbarConfig = {
accessToken: env.ROLLBAR_TOKEN,
captureUncaught: true,
captureUnhandledRejections: true,
logLevel: 'error' as Level,
};

global.rollbar = new Rollbar(rollbarConfig);
// const RollbarTransport = require('winston-transport-rollbar-3');

const {
combine,
Expand Down Expand Up @@ -124,7 +114,18 @@ const transportOptions = [
// We only want rollbar logs in production
// let transportOptions = [];
if (env.NODE_ENV === 'production') {
transportOptions.push(new RollbarTransport({ rollbarConfig }));
const rollbarConfig = {
accessToken: env.ROLLBAR_TOKEN,
// captureUncaught: true,
// captureUnhandledRejections: true,
logLevel: 'error' as Level,
};

// transportOptions.push(new RollbarTransport({ rollbarConfig }));
// Setup Rollbar

global.rollbar = new Rollbar(rollbarConfig);

// Setup glitchTip
Sentry.init({
dsn: env.GLITCHTIP_DSN,
Expand Down

0 comments on commit f60e398

Please sign in to comment.