Skip to content

Commit

Permalink
Update error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Jan 28, 2024
1 parent 905dfe1 commit 9ea427c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
66 changes: 33 additions & 33 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,41 @@ 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 (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 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
30 changes: 19 additions & 11 deletions src/global/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ import {
// import { Logtail } from '@logtail/node'; // eslint-disable-line
// import { LogtailTransport } from '@logtail/winston'; // eslint-disable-line
import Rollbar, { Level } from 'rollbar';
// import * as Sentry from '@sentry/node'; // eslint-disable-line
// import SentryTransport from 'winston-transport-sentry-node'; // eslint-disable-line
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 {
combine,
splat,
Expand Down Expand Up @@ -61,15 +71,7 @@ const myFormat = printf(({
return msg;
});

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

global.rollbar = new Rollbar(rollbarConfig);

// Old sentry stuff
// const sentryConfig = {
// dsn: env.SENTRY_TOKEN,
// debug: true, // Enable debug mode to log internal transactions
Expand Down Expand Up @@ -119,10 +121,16 @@ const transportOptions = [
new transports.Console(),
];

// We only want logtail logs in production
// We only want rollbar logs in production
// let transportOptions = [];
if (env.NODE_ENV === 'production') {
transportOptions.push(new RollbarTransport({ rollbarConfig }));
// Setup glitchTip
Sentry.init({
dsn: env.GLITCHTIP_DSN,
// debug: true,
environment: env.NODE_ENV,
});
}

const logger = createLogger({
Expand Down
7 changes: 0 additions & 7 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import * as path from 'path';
import Canvas from '@napi-rs/canvas';
import { PrismaClient } from '@prisma/client';
import * as Sentry from '@sentry/node';
import { env } from './global/utils/env.config';
import { log } from './global/utils/log';
import validateEnv from './global/utils/env.validate'; // eslint-disable-line
Expand Down Expand Up @@ -46,12 +45,6 @@ async function start() {
log.info(F, 'Initializing service!');
if (validateEnv('SERVICES')) {
api();
Sentry.init({
dsn: env.GLITCHTIP_DSN,
// debug: true,
environment: env.NODE_ENV,
});

global.db = new PrismaClient({ log: ['error'] });
await updateDb();
if (env.DISCORD_CLIENT_TOKEN && validateEnv('DISCORD')) await discordConnect();
Expand Down

0 comments on commit 9ea427c

Please sign in to comment.