From f60e3988c3922b8058d33e122542fd38cabfa1a0 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:27:04 -0600 Subject: [PATCH] Final log update, for now --- src/discord/events/error.ts | 71 +++++++++++++++++++------------------ src/global/utils/log.ts | 25 ++++++------- 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/discord/events/error.ts b/src/discord/events/error.ts index 3ce2f3d8..a87f0554 100644 --- a/src/discord/events/error.ts +++ b/src/discord/events/error.ts @@ -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); @@ -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; @@ -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); +}); diff --git a/src/global/utils/log.ts b/src/global/utils/log.ts index a10b4eea..108b3014 100644 --- a/src/global/utils/log.ts +++ b/src/global/utils/log.ts @@ -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, @@ -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,