Skip to content

Instantly share code, notes, and snippets.

@l2ysho
Last active January 6, 2021 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l2ysho/1f966c604c02c10be15535049b7a1e97 to your computer and use it in GitHub Desktop.
Save l2ysho/1f966c604c02c10be15535049b7a1e97 to your computer and use it in GitHub Desktop.
sentry setup
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