Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (release = process.env.SENTRY_RELEASE) => {
const sentryOptions = {
dsn: process.env.SENTRY_DSN,
release,
maxBreadcrumbs: 50,
attachStacktrace: true,
}
// When we're developing locally
if (process.env.NODE_ENV !== 'production') {
// Don't actually send the errors to Sentry
sentryOptions.beforeSend = () => null
// Instead, dump the errors to the console
sentryOptions.integrations = [
new SentryIntegrations.Debug({
// Trigger DevTools debugger instead of using console.log
debugger: false,
}),
]
}
Sentry.init(sentryOptions)
return {
Sentry,
captureException: (err, ctx) => {
Sentry.configureScope(scope => {
if (err.message) {
// De-duplication currently doesn't work correctly for SSR / browser errors
// so we force deduplication by error message if it is present
scope.setFingerprint([err.message])
const Sentry = require('@sentry/node')
const sentryStream = require('bunyan-sentry-stream')
const Integrations = require('@sentry/integrations')
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
release: process.env.HEROKU_SLUG_COMMIT,
integrations: [
new Integrations.Transaction(),
new Integrations.Debug(),
new Integrations.ExtraErrorData()
]
})
module.exports = app => {
app.log.debug('Errors will be reported to Sentry')
app.log.target.addStream(sentryStream(Sentry, 'error'))
const router = app.route('/')
router.get('/boom', req => {
const err = new Error('Boom')
if (req.query.async) {
app.log.error(err)
return Promise.reject(err)
}
app.log.error(err)