Skip to content

Commit

Permalink
fix: use loglevel-sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
maneki-admin committed Apr 2, 2024
1 parent 3c5729a commit 617f0e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/fnd-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ log.setLevel((process.env.LOG_LEVEL as log.LogLevelDesc) || "DEBUG");
import router from "./router";
import { registerSentry, registerSentryErrorHandler } from "./utils/sentry";

// setup app
process.on("uncaughtException", (err) => {
log.error(err, "uncaughtException");
});

// setup app
const app = express();
const port = process.env.PORT || process.argv[2] || 8060;
Expand Down
11 changes: 8 additions & 3 deletions packages/fnd-server/src/utils/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";
import LoglevelSentryPlugin from "@toruslabs/loglevel-sentry";
import { Express } from "express";
import log from "loglevel";

import redact from "./redactSentry";

Expand Down Expand Up @@ -36,6 +38,9 @@ export const registerSentry = (app: Express): void => {
);
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());

const plugin = new LoglevelSentryPlugin(Sentry);
plugin.install(log);
}
};

Expand All @@ -44,9 +49,9 @@ export const registerSentryErrorHandler = (app: Express): void => {
if (sentryDsn) {
app.use(
Sentry.Handlers.errorHandler({
shouldHandleError() {
// always send the errors to sentry, will dial down if needed
return true;
shouldHandleError(error) {
// Capture all 404 and 500 errors
return typeof error.status === "number" ? error.status >= 400 : false;
},
})
);
Expand Down

0 comments on commit 617f0e9

Please sign in to comment.