Skip to content

Commit

Permalink
chore: Update npm dependencies and add Sentry integration for error l…
Browse files Browse the repository at this point in the history
…ogging and performance monitoring
  • Loading branch information
imnaiyar committed Jul 14, 2024
1 parent 01754c7 commit cb945ba
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dev": "bun run src/index.ts",
"commands": "node dist/src/libs/registerCommands.js",
"bun-cmd": "bun run src/libs/registerCommands.ts",
"format": "npx prettier --write \"**/*.{js,css,ejs, ts}\""
"format": "npx prettier --write \"**/*.{js,css,ejs, ts}\"",
"upload-source-maps": "sentry-cli sourcemaps inject dist && sentry-cli sourcemaps upload dist --project node"
},
"author": "Naiyar Imam",
"license": "MIT",
Expand All @@ -28,6 +29,8 @@
"@nestjs/platform-express": "^10.3.8",
"@sapphire/stopwatch": "^1.5.2",
"@sapphire/type": "^2.4.4",
"@sentry/node": "^8.17.0",
"@sentry/profiling-node": "^8.17.0",
"chalk": "^4.1.2",
"cors": "^2.8.5",
"cropify": "^1.0.9",
Expand All @@ -46,8 +49,7 @@
"pino-pretty": "^10.2.0",
"skyhelper-utils": "^1.2.5",
"table": "^6.8.1",
"topgg-autoposter": "^2.0.2",
"uuid": "^9.0.1"
"topgg-autoposter": "^2.0.2"
},
"imports": {
"#handlers": [
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EmbedBuilder, WebhookClient, codeBlock } from "discord.js";
import config from "#src/config";
import { v4 as genId } from "uuid";
import util from "node:util";
import { postToHaste } from "skyhelper-utils";
import { Logger } from "@nestjs/common";
import { captureException } from "@sentry/node";
const webhookLogger = process.env.ERROR_LOGS ? new WebhookClient({ url: process.env.ERROR_LOGS }) : undefined;

async function sendWebhook(id: string, content: any, err?: any): Promise<void> {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default class {
* @returns The error ID
*/
static error(content: any, ex?: any) {
const id = genId();
const id = captureException(ex || content);
if (ex) {
Logger.error(ex, `${id} => ${content}`);
} else {
Expand Down
45 changes: 33 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";
import "dotenv/config";
import { SkyHelper } from "#structures";
import { initializeMongoose } from "#src/database/mongoose";
Expand All @@ -11,20 +13,37 @@ declare global {
isBun?: boolean;
}
interface ProcessEnv {
TOKEN: string
MONGO_CONNECTION: string
AUTH_TOKEN: string
TOPGG_TOKEN?: string
GUILD?: string
ERROR_LOGS?: string
READY_LOGS?: string
SUGGESTION?: string
CONTACT_US?: string
COMMANDS_USED?: string
BUG_REPORTS?: string
TOKEN: string;
NODE_ENV: "development" | "production";
MONGO_CONNECTION: string;
SENTRY_DSN: string;
AUTH_TOKEN: string;
TOPGG_TOKEN?: string;
GUILD?: string;
ERROR_LOGS?: string;
READY_LOGS?: string;
SUGGESTION?: string;
CONTACT_US?: string;
COMMANDS_USED?: string;
BUG_REPORTS?: string;
}
}
}
// Init Sentry
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [
nodeProfilingIntegration(),
Sentry.rewriteFramesIntegration({
root: global.__dirname,
}),
],
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions

// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
});

const root = process.isBun ? "src" : "dist/src";
await client.loadEvents(root + "/events");
Expand All @@ -36,7 +55,9 @@ await initializeMongoose();
console.log(chalk.blueBright("\n\n<------------------------ Dashboard --------------------------->\n"));
if (client.config.DASHBOARD.enabled) Dashboard(client);
// Catching unhandle rejections
process.on("unhandledRejection", (err) => client.logger.error(err));
process.on("unhandledRejection", (err) => {
client.logger.error(err);
});
process.on("uncaughtException", (err) => client.logger.error(err));
// Login
client.login(process.env.TOKEN);
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"target": "ES2022",
"module": "NodeNext",
"allowSyntheticDefaultImports": true,

// Source maps
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
Expand Down

0 comments on commit cb945ba

Please sign in to comment.