chore: misc update

This commit is contained in:
Jessica Boezwinkle
2023-06-23 16:49:40 +01:00
parent e41515564b
commit 607d345eb2
2 changed files with 46 additions and 47 deletions

View File

@@ -40,7 +40,7 @@ export default config;
### Data Source Name (DSN) and where to find it
- `dsn` : string[] | required
- `dsn` : string | required
Sentry automatically assigns a DSN when you create a project, the unique DSN informs Sentry where to send events so they are associated with the correct project.

View File

@@ -9,54 +9,53 @@ import type { PluginOptions } from './types'
export const startSentry = (pluginOptions: PluginOptions): void => {
const { dsn, options } = pluginOptions
if (dsn)
try {
const app = express()
if (!dsn) return
Sentry.init({
...options?.init,
dsn: dsn,
integrations: [
...(options?.init?.integrations || []),
new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.Express({ app }),
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
})
try {
const app = express()
app.use(
Sentry.Handlers.requestHandler(options?.requestHandler || {}) as express.RequestHandler,
)
app.use(Sentry.Handlers.tracingHandler())
Sentry.init({
...options?.init,
dsn: dsn,
integrations: [
...(options?.init?.integrations || []),
new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.Express({ app }),
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
})
app.use(
Sentry.Handlers.errorHandler({
shouldHandleError(error) {
if (error.status === 500) {
return true
}
if (
options?.captureErrors &&
typeof error.status === 'number' &&
options.captureErrors.includes(error.status)
) {
return true
}
return false
},
}) as express.ErrorRequestHandler,
)
app.use(Sentry.Handlers.requestHandler(options?.requestHandler || {}) as express.RequestHandler)
app.use(Sentry.Handlers.tracingHandler())
app.use(function onError(
_err: unknown,
_req: Request,
res: Response & { sentry?: string },
_next: NextFunction,
) {
res.statusCode = 500
res.end(res.sentry + '\n')
})
} catch (err: unknown) {
console.log('There was an error initializing Sentry, please ensure you entered a valid DSN')
}
app.use(
Sentry.Handlers.errorHandler({
shouldHandleError(error) {
if (error.status === 500) {
return true
}
if (
options?.captureErrors &&
typeof error.status === 'number' &&
options.captureErrors.includes(error.status)
) {
return true
}
return false
},
}) as express.ErrorRequestHandler,
)
app.use(function onError(
_err: unknown,
_req: Request,
res: Response & { sentry?: string },
_next: NextFunction,
) {
res.statusCode = 500
res.end(res.sentry + '\n')
})
} catch (err: unknown) {
console.log('There was an error initializing Sentry, please ensure you entered a valid DSN')
}
}