Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sentry server side #397

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"@fortawesome/vue-fontawesome": "^3.0.3",
"@gtm-support/vue-gtm": "^2.0.0",
"@pinia/nuxt": "0.4.11",
"@sentry/vue": "^7.113.0",
"@sentry/node": "^8.35.0",
"@sentry/vue": "^8.35.0",
"@tailwindcss/typography": "^0.5.9",
"@teritorio/map": "^0.12.7",
"@teritorio/maplibre-gl-teritorio-cluster": "^0.0.8",
Expand Down
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)
})
})
Loading