Last active
January 6, 2021 07:40
-
-
Save l2ysho/1f966c604c02c10be15535049b7a1e97 to your computer and use it in GitHub Desktop.
sentry setup
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
const app = express() | |
Sentry.init({ | |
dsn: process.env.NODE_ENV === 'production' && process.env.SENTRY_DSN, | |
environment: process.env.SENTRY_ENV, | |
debug: process.env.SENTRY_LOGGING === 'true' || false, | |
release: `${process.env.npm_package_name}@v${process.env.npm_package_version}`, | |
integrations: [ | |
new Sentry.Integrations.Http({ tracing: true }), | |
new Tracing.Integrations.Express({ | |
app, | |
}), | |
], | |
// tracesSampler: samplingContext => { | |
// console.log(samplingContext) | |
// return 1 | |
// }, | |
tracesSampleRate: 1.0, | |
}) | |
app.use(Sentry.Handlers.requestHandler()); | |
app.use(Sentry.Handlers.tracingHandler()); | |
app.use((err: Error, req: Request, _res: Response, next: NextFunction) => { | |
const { user } = req | |
if (user) { | |
Sentry.configureScope((scope: any) => { | |
scope.setUser({ | |
id: user.id | |
}) | |
}) | |
} | |
return next(err) | |
}) | |
// rest of app middlewares and routers | |
app.use(Sentry.Handlers.errorHandler()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment