Files
Davide Silvestri 1c2480f1dc fix: Keep the default Sentry filters when the app config extends them (#7011)
* fix: keep the default Sentry filters when the app config extends them

The app config replaced ignoreErrors and beforeSend instead of extending
them, so deployments that set their own dropped Baserow's silenced error
patterns, the handled API error filter and the private link redaction.

* fix: preserve Sentry redaction across app hooks
2026-12-03 11:12:29 +01:00

70 lines
2.3 KiB
JavaScript

import {
filterAndRedactEvent,
SILENCED_ERROR_PATTERNS,
} from '@baserow/modules/core/utils/sentryErrors'
import { makeFakeTransport } from '@baserow/modules/core/utils/sentryFakeTransport'
import { dropRouteParams } from '@baserow/modules/core/utils/sentryTransactions'
import { redactPrivateLinks } from '@baserow/modules/core/utils/templatePrivateLink'
const redactTransaction = (event) => redactPrivateLinks(dropRouteParams(event))
const withAppHook = (prepare, appHook, redact) => {
if (!appHook) {
return prepare
}
return async (event, hint) => {
const prepared = prepare(event, hint)
if (prepared === null) {
return null
}
const result = await appHook(prepared, hint)
// An app hook can add fresh URLs or route parameters to an already redacted event.
return result === null ? null : redact(result)
}
}
export const buildSentryConfig = ({
publicConfig,
tracingIntegration,
userConfig,
isDev,
}) => {
const app = userConfig ?? {}
const fakeDsn = publicConfig.sentryDsn === 'fake'
const fakeTransport = isDev && fakeDsn
const defaults = {
dsn: fakeDsn ? 'https://fake@localhost/1' : publicConfig.sentryDsn,
release: `baserow-web-frontend@${publicConfig.version}`,
environment: publicConfig.sentryEnvironment || 'production',
integrations: [tracingIntegration],
ignoreErrors: SILENCED_ERROR_PATTERNS,
tracesSampleRate: parseFloat(publicConfig.sentryTracesSampleRate) || 0,
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate:
parseFloat(publicConfig.sentryReplaysOnErrorSampleRate) || 0,
}
const beforeSend = (event, hint) => {
const kept = filterAndRedactEvent(event, hint)
if (fakeTransport && kept) {
console.error('[Sentry captured error]', `${hint?.originalException}`)
}
return kept
}
const config = {
...defaults,
...app,
beforeSend: withAppHook(beforeSend, app.beforeSend, redactPrivateLinks),
beforeSendTransaction: withAppHook(
redactTransaction,
app.beforeSendTransaction,
redactTransaction
),
...(fakeTransport ? { transport: makeFakeTransport } : {}),
}
for (const key of ['integrations', 'ignoreErrors', 'denyUrls']) {
config[key] = [...(defaults[key] ?? []), ...(app[key] ?? [])]
}
return config
}