Skip to content

Commit

Permalink
fix: add sentry server side #337
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab authored and frodrigo committed Oct 25, 2024
1 parent 5a545cb commit ae0af90
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugins/sentry.ts → plugins/sentry.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/vue'

export default defineNuxtPlugin((nuxtApp) => {
const router = useRouter()
const { sentry } = useRuntimeConfig().public
const { public: { sentry } } = useRuntimeConfig()

if (!sentry.dsn)
return
Expand All @@ -13,7 +13,10 @@ export default defineNuxtPlugin((nuxtApp) => {
environment: sentry.environment,
integrations: [
Sentry.browserTracingIntegration({ router }),
Sentry.replayIntegration(),
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
}),
],

// Set tracesSampleRate to 1.0 to capture 100%
Expand Down
42 changes: 42 additions & 0 deletions server/plugins/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as Sentry from '@sentry/node'
import { H3Error } from 'h3'

export default defineNitroPlugin((nitroApp) => {
const { public: { sentry } } = useRuntimeConfig()

// If no sentry DSN set, ignore and warn in the console
if (!sentry.dsn) {
console.warn('Sentry DSN not set, skipping Sentry initialization')
return
}

// Initialize Sentry
Sentry.init({
dsn: sentry.dsn,
environment: sentry.environment,
integrations: [],
// Performance Monitoring
tracesSampleRate: 1.0, // Change in production!
// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0, // Change in production!
})

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)
})
})

0 comments on commit ae0af90

Please sign in to comment.