Skip to content

Commit ade84e8

Browse files
authored
Add Nuxt3 Sentry (baserow#4756)
1 parent 8c72258 commit ade84e8

7 files changed

Lines changed: 896 additions & 20 deletions

File tree

web-frontend/config/nuxt.config.base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function baserowModuleConfig(
3535
enterpriseBase + '/modules/baserow_enterprise/module.js'
3636
)
3737
}
38-
// baseModules.push('@nuxtjs/sentry')
3938

4039
const modules = baseModules.concat(additionalModules)
4140

web-frontend/env-remap.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ const envMapping = {
5353
BASEROW_PRICING_URL: 'NUXT_PUBLIC_BASEROW_PRICING_URL',
5454
BASEROW_ENTERPRISE_ASSISTANT_LLM_MODEL:
5555
'NUXT_PUBLIC_BASEROW_ENTERPRISE_ASSISTANT_LLM_MODEL',
56-
57-
// Additional env vars
58-
SENTRY_DSN: 'NUXT_PUBLIC_SENTRY_CONFIG_DSN',
59-
SENTRY_ENVIRONMENT: 'NUXT_PUBLIC_SENTRY_CONFIG_ENVIRONMENT',
56+
SENTRY_DSN: 'NUXT_PUBLIC_SENTRY_DSN',
57+
SENTRY_ENVIRONMENT: 'NUXT_PUBLIC_SENTRY_ENVIRONMENT',
6058
MEDIA_URL: 'NUXT_PUBLIC_MEDIA_URL',
6159
}
6260

web-frontend/modules/core/module.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,8 @@ export default defineNuxtModule({
8585
baserowDisableSupport: '',
8686
baserowIntegrationsPeriodicMinuteMin: '1',
8787
mediaUrl: 'http://localhost:4000/media/',
88-
sentry: {
89-
config: {
90-
dsn: '',
91-
environment: '',
92-
},
93-
},
88+
sentryDsn: '',
89+
sentryEnvironment: '',
9490
}
9591
)
9692

@@ -132,6 +128,8 @@ export default defineNuxtModule({
132128
addPlugin(resolve('plugins/featureFlags.js'))
133129
addPlugin(resolve('plugins/papa.js'))
134130
addPlugin(resolve('plugins/ensureRender.js'))
131+
addPlugin(resolve('plugins/sentry.client.js'))
132+
addPlugin(resolve('plugins/sentry.server.js'))
135133
addPlugin(resolve('plugins/version.js'))
136134
addPlugin(resolve('plugins/posthog.js'))
137135
addPlugin(resolve('plugins/vueDatepicker.js'))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export default defineNuxtPlugin(async (nuxtApp) => {
2+
// Only run on client side
3+
if (import.meta.server) {
4+
return
5+
}
6+
7+
const config = useRuntimeConfig()
8+
const dsn = config.public.sentryDsn
9+
10+
if (!dsn || dsn === '') {
11+
return
12+
}
13+
14+
const Sentry = await import('@sentry/vue')
15+
16+
Sentry.init({
17+
app: nuxtApp.vueApp,
18+
dsn,
19+
environment: config.public.sentryEnvironment || 'production',
20+
integrations: [
21+
Sentry.browserTracingIntegration({
22+
router: nuxtApp.$router,
23+
}),
24+
Sentry.replayIntegration({
25+
maskAllText: true,
26+
blockAllMedia: true,
27+
}),
28+
],
29+
tracesSampleRate: 1.0,
30+
replaysSessionSampleRate: 0,
31+
replaysOnErrorSampleRate: 1.0,
32+
})
33+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default defineNuxtPlugin(async (nuxtApp) => {
2+
if (import.meta.client) {
3+
return
4+
}
5+
6+
const config = useRuntimeConfig()
7+
const dsn = config.public.sentryDsn
8+
9+
if (!dsn || dsn === '') {
10+
return
11+
}
12+
13+
const Sentry = await import('@sentry/node')
14+
15+
Sentry.init({
16+
dsn,
17+
environment: config.public.sentryEnvironment || 'production',
18+
tracesSampleRate: 1.0,
19+
})
20+
21+
nuxtApp.hook('app:error', (error) => {
22+
Sentry.captureException(error)
23+
})
24+
25+
nuxtApp.hook('vue:error', (error, instance, info) => {
26+
Sentry.captureException(error, {
27+
contexts: {
28+
vue: {
29+
componentName: instance?.$options?.name,
30+
errorInfo: info,
31+
},
32+
},
33+
})
34+
})
35+
})

web-frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
},
3232
"dependencies": {
3333
"@nuxtjs/i18n": "10.2.1",
34+
"@sentry/node": "^10.38.0",
35+
"@sentry/nuxt": "^10.38.0",
36+
"@sentry/vue": "^10.38.0",
3437
"@tiptap/core": "^3.13.0",
3538
"@tiptap/extension-blockquote": "^3.13.0",
3639
"@tiptap/extension-bold": "^3.13.0",

0 commit comments

Comments
 (0)