-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathsentry.js
39 lines (38 loc) · 1.75 KB
/
sentry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
let Sentry
module.exports = function(app, options = {}) {
const { SENTRY_DSN, SENTRY_SAMPLE_RATE, SENTRY_REQOPTS } = options
if (SENTRY_DSN && !Sentry) {
Sentry = require('@sentry/node')
const Tracing = require("@sentry/tracing")
Sentry.init({
dsn: SENTRY_DSN,
integrations: [
new Sentry.Integrations.Http({ tracing: true }), // enable HTTP calls tracing
new Tracing.Integrations.Express({ app }), // enable Express.js middleware tracing
// new Sentry.Integrations.OnUncaughtException({onFatalError: (e) => {
// Sentry.captureMessage('BIG Problem')
// // captureException
// // console.log('asdbsdghasdgkhsagdkhagsdjaghsdsjad', e)
// process.exit(1)
// }}),
// new Sentry.Integrations.OnUncaughtException({ onFatalError: () => { /** your implementation */ } }),
// new Sentry.Integrations.OnUnhandledRejection({ onFatalError: () => { /** your implementation */ } }),
],
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring. We recommend adjusting this value in production
tracesSampleRate: SENTRY_SAMPLE_RATE,
environment: process.env.NODE_ENV,
})
// 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(SENTRY_REQOPTS))
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler())
// app.use(Sentry.Handlers.errorHandler({ // by default Sentry handles 500 errors
// shouldHandleError(error) {
// return error.status >= 500 ? true : false
// }
// }))
}
return Sentry
}