Skip to content

Commit

Permalink
chore: add sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
sparky-raccoon committed Mar 16, 2024
1 parent 3627de2 commit 13caa5d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"homepage": "https://github.com/sparky-raccoon/epitome#readme",
"dependencies": {
"@sentry/node": "^7.107.0",
"axios": "^0.27.2",
"discord.js": "^14.14.0",
"dotenv": "^16.0.0",
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import * as dotenv from "dotenv";
import initDiscordClient from "@/client";
import logger from "@/utils/logger";
import * as Sentry from "@sentry/node";

dotenv.config();
const { NODE_ENV, TOKEN, TOKEN_DEV, CLIENT_ID, CLIENT_ID_DEV } = process.env;

Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: NODE_ENV,
tracesSampleRate: 1.0,
});

const token = NODE_ENV === "development" ? TOKEN_DEV : TOKEN;
const clientId = NODE_ENV === "development" ? CLIENT_ID_DEV : CLIENT_ID;
const { client } = initDiscordClient(clientId, token);
Expand All @@ -20,9 +28,13 @@ const handleShutDown = () => {
};

type ErrorType = "uncaughtException" | "unhandledRejection";
const handleError = (type: ErrorType, err: Error) => {
const handleError = async (type: ErrorType, err: Error) => {
console.log('Handling error')
Sentry.captureException(err);
logger.error(`${type}: ${err.message}`);
cleanup();

await Sentry.close();
process.exit(1);
};

Expand Down
2 changes: 2 additions & 0 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { confirmOrCancelButton } from "@/components/confirm-button";
import { FSource } from "@/bdd/collections/source";
import { Source } from "@/utils/types";
import * as Sentry from "@sentry/node";

const getColorForSourceType = (sourceType: string): ColorResolvable => {
switch (sourceType) {
Expand Down Expand Up @@ -247,6 +248,7 @@ const getMessage = (type: Message, data?: MessageData): any => {
} else result.push(buildDiscordMessage(true, { title, description, color, imageUrl, component }));
return result;
} catch (err) {
Sentry.captureException(err);
console.error(err);
return buildDiscordMessage(true, {
title: "Erreur",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { reply, editReply } from "@/utils/replier";
import FirestoreSource, { FSource } from "@/bdd/collections/source";
import FirestoreChannel from "@/bdd/collections/channel";
import { Source } from "@/utils/types";
import * as Sentry from "@sentry/node";

const TIMEOUT = 60000;

Expand Down Expand Up @@ -88,6 +89,7 @@ class Process {

this.terminate(this.interaction.user.id);
} catch (err) {
Sentry.captureException(err);
if (err instanceof Error) await this.error(err.message);
else if (typeof err === "string") await this.error(err);
}
Expand Down Expand Up @@ -136,6 +138,7 @@ class Process {

this.terminate(this.interaction.user.id);
} catch (err) {
Sentry.captureException(err);
if (err instanceof Error) await this.error(err.message);
else if (typeof err === "string") await this.error(err);
}
Expand Down Expand Up @@ -179,6 +182,7 @@ class Process {

this.terminate(this.interaction.user.id);
} catch (err) {
Sentry.captureException(err);
if (err instanceof Error) await this.error(err.message);
else if (typeof err === "string") await this.error(err);
}
Expand All @@ -200,6 +204,7 @@ class Process {

this.terminate(this.interaction.user.id);
} catch (err) {
Sentry.captureException(err);
if (err instanceof Error) await this.error(err.message);
else if (typeof err === "string") await this.error(err);
}
Expand Down
39 changes: 39 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,45 @@
resolved "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.1.tgz"
integrity sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==

"@sentry-internal/[email protected]":
version "7.107.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.107.0.tgz#a10b4abcbc9e0d8da948e3a95029574387ca7b16"
integrity sha512-le9wM8+OHBbq7m/8P7JUJ1UhSPIty+Z/HmRXc5Z64ODZcOwFV6TmDpYx729IXDdz36XUKmeI+BeM7yQdTTZPfQ==
dependencies:
"@sentry/core" "7.107.0"
"@sentry/types" "7.107.0"
"@sentry/utils" "7.107.0"

"@sentry/[email protected]":
version "7.107.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.107.0.tgz#926838ba2c2861d6bd2bced0232e1f9d1ead6c75"
integrity sha512-C7ogye6+KPyBi8NVL0P8Rxx3Ur7Td8ufnjxosVy678lqY+dcYPk/HONROrzUFYW5fMKWL4/KYnwP+x9uHnkDmw==
dependencies:
"@sentry/types" "7.107.0"
"@sentry/utils" "7.107.0"

"@sentry/node@^7.107.0":
version "7.107.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.107.0.tgz#d60c2e28953f2ba14d12ada9190f1fc577b2b280"
integrity sha512-UZXkG7uThT2YyPW8AOSKRXp1LbVcBHufa4r1XAwBukA2FKO6HHJPjMUgY6DYVQ6k+BmA56CNfVjYrdLbyjBYYA==
dependencies:
"@sentry-internal/tracing" "7.107.0"
"@sentry/core" "7.107.0"
"@sentry/types" "7.107.0"
"@sentry/utils" "7.107.0"

"@sentry/[email protected]":
version "7.107.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.107.0.tgz#5ba4b472be6ccad9aecd58dbc0141a09dafb68c1"
integrity sha512-H7qcPjPSUWHE/Zf5bR1EE24G0pGVuJgrSx8Tvvl5nKEepswMYlbXHRVSDN0gTk/E5Z7cqf+hUBOpkQgZyps77w==

"@sentry/[email protected]":
version "7.107.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.107.0.tgz#b8524539d052a40f9c5f34a8347501f0f81a0751"
integrity sha512-C6PbN5gHh73MRHohnReeQ60N8rrLYa9LciHue3Ru2290eSThg4CzsPnx4SzkGpkSeVlhhptKtKZ+hp/ha3iVuw==
dependencies:
"@sentry/types" "7.107.0"

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down

0 comments on commit 13caa5d

Please sign in to comment.