From c9dd7a5fb2489c2a4178be9c0b9638a9b7dfa141 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Wed, 24 Apr 2024 11:02:33 -0500 Subject: [PATCH] fix(bot): make influx and sentry optional --- apps/bot/src/influx.ts | 2 +- apps/bot/src/sentry.ts | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/bot/src/influx.ts b/apps/bot/src/influx.ts index fa2ec942..e595482f 100644 --- a/apps/bot/src/influx.ts +++ b/apps/bot/src/influx.ts @@ -8,7 +8,7 @@ import { hostname } from 'os'; import { client as dexareClient, CraigBotConfig } from './bot'; import type RecorderModule from './modules/recorder'; -const influxOpts: any = config.get('influx'); +const influxOpts: any = config.has('influx') ? config.get('influx') : null; export const client: InfluxDB | null = influxOpts && influxOpts.url ? new InfluxDB({ url: influxOpts.url, token: influxOpts.token }) : null; export const cron = new CronJob('*/5 * * * *', collect, null, false, 'America/New_York'); diff --git a/apps/bot/src/sentry.ts b/apps/bot/src/sentry.ts index 1d3f4f4c..3a600eea 100644 --- a/apps/bot/src/sentry.ts +++ b/apps/bot/src/sentry.ts @@ -8,24 +8,26 @@ import { CommandContext } from 'slash-create'; import Recording from './modules/recorder/recording'; import { prisma } from './prisma'; -const sentryOpts: any = config.get('sentry'); -Sentry.init({ - dsn: sentryOpts.dsn, - integrations: [ - new Sentry.Integrations.Http({ tracing: true }), - new RewriteFrames({ - root: __dirname - }), - new Integrations.Prisma({ client: prisma }) - ], +const sentryOpts: any = config.has('sentry') ? config.get('sentry') : null; +if (sentryOpts) + Sentry.init({ + dsn: sentryOpts.dsn, + integrations: [ + new Sentry.Integrations.Http({ tracing: true }), + new RewriteFrames({ + root: __dirname + }), + new Integrations.Prisma({ client: prisma }) + ], - environment: sentryOpts.env || process.env.NODE_ENV || 'development', - // eslint-disable-next-line @typescript-eslint/no-var-requires - release: `craig-bot@${require('../package.json').version}`, - tracesSampleRate: sentryOpts.sampleRate ? parseFloat(sentryOpts.sampleRate) : 1.0 -}); + environment: sentryOpts.env || process.env.NODE_ENV || 'development', + // eslint-disable-next-line @typescript-eslint/no-var-requires + release: `craig-bot@${require('../package.json').version}`, + tracesSampleRate: sentryOpts.sampleRate ? parseFloat(sentryOpts.sampleRate) : 1.0 + }); export function reportErrorFromCommand(ctx: CommandContext, error: any, commandName: string, type?: string) { + if (!sentryOpts) return; Sentry.withScope((scope) => { scope.setTag('type', type || 'generic'); if (commandName) scope.setTag('command', commandName); @@ -43,6 +45,7 @@ export function reportErrorFromCommand(ctx: CommandContext, error: any, commandN } export function reportRecordingError(ctx: CommandContext, error: any, recording?: Recording) { + if (!sentryOpts) return; Sentry.withScope((scope) => { scope.setTag('type', 'command'); scope.setTag('command', 'join'); @@ -61,6 +64,7 @@ export function reportRecordingError(ctx: CommandContext, error: any, recording? } export function reportAutorecordingError(member: Eris.Member, guildId: string, channelId: string, error: any, recording?: Recording) { + if (!sentryOpts) return; Sentry.withScope((scope) => { scope.setTag('type', 'autorecord'); if (recording) scope.setTag('recording', recording.id); @@ -77,5 +81,6 @@ export function reportAutorecordingError(member: Eris.Member, guildId: string, c } export function close() { + if (!sentryOpts) return; return Sentry.close(); }