-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsentry.ts
45 lines (38 loc) · 1.05 KB
/
sentry.ts
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
40
41
42
43
44
45
import * as Sentry from '@sentry/node'
import {
nodeProfilingIntegration,
} from '@sentry/profiling-node'
import { H3Error } from 'h3'
export default defineNitroPlugin((nitroApp) => {
const { public: { sentry } } = useRuntimeConfig()
if (!sentry.dsn) {
console.warn('Sentry DSN not set, skipping Sentry initialization')
return
}
Sentry.init({
dsn: sentry.dsn,
environment: sentry.environment,
integrations: [
nodeProfilingIntegration(),
],
// Performance Monitoring
tracesSampleRate: 0.2,
// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 0.2,
})
nitroApp.hooks.hook('error', (error) => {
// Do not handle 404s and 422s
if (error instanceof H3Error) {
if (error.statusCode === 404 || error.statusCode === 422) {
return
}
}
Sentry.captureException(error)
})
nitroApp.hooks.hook('request', (event) => {
event.context.$sentry = Sentry
})
nitroApp.hooks.hookOnce('close', async () => {
await Sentry.close(2000)
})
})