This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore: add Sentry configuration for better error handling" (#…
- Loading branch information
1 parent
db9818e
commit ab90516
Showing
2 changed files
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import { ErrorRequestHandler } from 'express'; | ||
import config from '@/config'; | ||
|
||
export const initializeSentry = (app) => { | ||
if (!config.sentryDNS) { | ||
console.log('Sentry DSN not found. Sentry is not initialized.'); | ||
return; | ||
} | ||
import { CaptureConsole as CaptureConsoleIntegration } from "@sentry/integrations"; | ||
import config from '@config'; | ||
|
||
export function initCaptureConsole() { | ||
const logLevel = ['error']; | ||
console.log( | ||
`Initializing Sentry for log level "${logLevel}" and config: ${config.sentryDNS}` | ||
); | ||
Sentry.init({ | ||
dsn: process.env.SENTRY_DSN, | ||
tracesSampleRate: 1.0, | ||
dsn: config.sentryDNS as string, | ||
// https://docs.sentry.io/platforms/javascript/configuration/integrations/plugin/#captureconsole | ||
integrations: [new CaptureConsoleIntegration({ levels: logLevel })], | ||
}); | ||
} | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
}; | ||
export function initCaptureConsoleWithHandler(app) { | ||
if (config.sentryDNS) { | ||
initCaptureConsole(); | ||
|
||
export const sentryErrorHandler: ErrorRequestHandler = | ||
Sentry.Handlers.errorHandler(); | ||
// RequestHandler creates a separate execution context using domains, so that every | ||
// transaction/span/breadcrumb is attached to its own Hub instance | ||
app.use(Sentry.Handlers.requestHandler()); | ||
|
||
// The error handler must be before any other error middleware and after all controllers | ||
app.use(Sentry.Handlers.errorHandler()); | ||
} else { | ||
console.log( | ||
'Sentry was not initialized as SENTRY_DNS env variable is missing' | ||
); | ||
} | ||
} |