mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* Collect only anonymous page views on published applications. * Explain why a published page is counted once when it opens.
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import { useRuntimeConfig, useAppConfig, useRouter } from '#imports'
|
|
import { makeFakeTransport } from './modules/core/utils/sentryFakeTransport'
|
|
import {
|
|
SILENCED_API_ERRORS,
|
|
SILENCED_ERROR_PATTERNS,
|
|
} from './modules/core/utils/sentryErrors'
|
|
import {
|
|
addReplayOutsidePrivateLinks,
|
|
redactPrivateLinks,
|
|
} from './modules/core/utils/templatePrivateLink'
|
|
import { dropRouteParams } from './modules/core/utils/sentryTransactions'
|
|
import {
|
|
getReplayOptions,
|
|
isPublishedSite,
|
|
} from './modules/core/utils/publishedSite'
|
|
import * as Sentry from '@sentry/nuxt'
|
|
|
|
const config = useRuntimeConfig()
|
|
const appConfig = useAppConfig()
|
|
const dsn =
|
|
config.public.sentryDsn === 'fake'
|
|
? 'https://fake@localhost/1'
|
|
: config.public.sentryDsn
|
|
const isDev = import.meta.dev && config.public.sentryDsn === 'fake'
|
|
|
|
if (dsn && dsn !== '') {
|
|
const defaultConfig = {
|
|
dsn,
|
|
release: `baserow-web-frontend@${config.public.version}`,
|
|
environment: config.public.sentryEnvironment || 'production',
|
|
ignoreErrors: SILENCED_ERROR_PATTERNS,
|
|
integrations: [
|
|
Sentry.browserTracingIntegration({
|
|
router: useRouter(),
|
|
}),
|
|
],
|
|
// Sample rate for performance tracing, configurable via the
|
|
// SENTRY_TRACES_SAMPLE_RATE env var (shared with the backend).
|
|
tracesSampleRate: parseFloat(config.public.sentryTracesSampleRate) || 0,
|
|
replaysSessionSampleRate: 0,
|
|
// Sample rate for saving a session replay on error, configurable via the
|
|
// SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE env var to cap replay volume.
|
|
replaysOnErrorSampleRate:
|
|
parseFloat(config.public.sentryReplaysOnErrorSampleRate) || 0,
|
|
...(isDev ? { transport: makeFakeTransport } : {}),
|
|
beforeSend(event, hint) {
|
|
const err = hint?.originalException
|
|
if (err?.fatal === false) {
|
|
return null
|
|
} else if (err?.fatal === true && err?.data?.report === false) {
|
|
return null
|
|
}
|
|
// Filter out axios errors without a response like
|
|
// network error, timeout, aborted, cancelled requests
|
|
if (err?.name === 'AxiosError' && !err?.response) {
|
|
return null
|
|
}
|
|
|
|
// Filter known API errors that are handled by the application (e.g. forceLogoff).
|
|
const status = err?.response?.status || err?.statusCode
|
|
const errorCode = err?.response?.data?.error || err?.data?.error
|
|
if (SILENCED_API_ERRORS[status]?.includes(errorCode)) {
|
|
return null
|
|
}
|
|
|
|
if (isDev) {
|
|
console.error('[Sentry captured error]', `${err}`)
|
|
return null
|
|
} else {
|
|
return redactPrivateLinks(event)
|
|
}
|
|
},
|
|
beforeSendTransaction: (event) =>
|
|
redactPrivateLinks(dropRouteParams(event)),
|
|
}
|
|
|
|
// Merge with user-provided configuration from app config
|
|
// appConfig.sentry.config can be used to extend or override defaults
|
|
const userConfig = appConfig.sentry?.config || {}
|
|
let finalIntegrations = defaultConfig.integrations
|
|
if (userConfig.integrations) {
|
|
finalIntegrations = [
|
|
...defaultConfig.integrations,
|
|
...userConfig.integrations,
|
|
]
|
|
delete userConfig.integrations
|
|
}
|
|
|
|
const finalConfig = {
|
|
...defaultConfig,
|
|
...userConfig,
|
|
integrations: finalIntegrations,
|
|
}
|
|
|
|
Sentry.init(finalConfig)
|
|
|
|
// Session replay is large, so it's only downloaded when replays are recorded,
|
|
// and loaded after init so that it doesn't block the page.
|
|
if (finalConfig.replaysOnErrorSampleRate > 0) {
|
|
addReplayOutsidePrivateLinks({
|
|
router: useRouter(),
|
|
loadReplayIntegration: () =>
|
|
import('@sentry/replay').then((module) => module.replayIntegration),
|
|
addIntegration: Sentry.addIntegration,
|
|
replayOptions: getReplayOptions({
|
|
publishedSite: isPublishedSite(window.location.hostname, config.public),
|
|
}),
|
|
})
|
|
}
|
|
}
|