Skip to content

Commit

Permalink
fix: sentry should not load if sentryDSN is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Tethik committed Nov 18, 2024
1 parent d7ba3a4 commit ba362dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function createApp(dal: DataAccessLayer) {
const app = express();

// Sentry has to be set up before everything else.
initSentry(app);
initSentry();

// Metrics middleware
app.use(metricsMiddleware);
Expand Down Expand Up @@ -273,7 +273,10 @@ export async function createApp(dal: DataAccessLayer) {
}

// Sentry Error Handler
Sentry.setupExpressErrorHandler(app);
if (config.sentryDSN) {
Sentry.setupExpressErrorHandler(app);
}

// Global Error Handler. Should catch anything that propagates up from the REST routes.
app.use(errorHandler);

Expand Down
7 changes: 5 additions & 2 deletions api/src/util/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from "@gram/core/dist/config/index.js";
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

import { Express } from "express";
import log4js from "log4js";
import { version } from "./version.js";
Expand All @@ -24,12 +24,15 @@ export function hasSentry() {
return !!config.sentryDSN;
}

export function initSentry(app: Express) {
export function initSentry() {
const sentryDSN = config.sentryDSN;
if (!sentryDSN) {
return;
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { nodeProfilingIntegration } = require("@sentry/profiling-node");

Sentry.init({
release: `gram@${version}`,
environment: process.env["NODE_ENV"],
Expand Down

0 comments on commit ba362dc

Please sign in to comment.