Skip to content
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
10 changes: 8 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ const getHost = (req: { get: (key: string) => string | undefined }) =>

const MODE = process.env.NODE_ENV

if (MODE === 'production' && process.env.SENTRY_DSN) {
const SHOULD_INIT_SENTRY =
MODE === 'production' &&
Boolean(process.env.SENTRY_DSN) &&
// `start:mocks` (used in CI + local e2e) runs with `MOCKS=true`.
process.env.MOCKS !== 'true'

if (SHOULD_INIT_SENTRY) {
void import('./utils/monitoring.js').then(({ init }) => init())
}

if (MODE === 'production') {
if (SHOULD_INIT_SENTRY) {
sentryInit({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0.3,
Expand Down
42 changes: 34 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@ import 'dotenv/config'
import { reactRouter } from '@react-router/dev/vite'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import tailwindcss from '@tailwindcss/vite'
import { glob } from 'glob'
import { defineConfig } from 'vite'
import { envOnlyMacros } from 'vite-env-only'
import { cjsInterop } from 'vite-plugin-cjs-interop'
import tsconfigPaths from 'vite-tsconfig-paths'

const MODE = process.env.NODE_ENV
const SENTRY_UPLOAD =
process.env.SENTRY_UPLOAD === 'true' || process.env.SENTRY_UPLOAD === '1'

if (SENTRY_UPLOAD && MODE === 'production') {
const authToken = process.env.SENTRY_AUTH_TOKEN
const project = process.env.SENTRY_PROJECT
const org = process.env.SENTRY_ORG
// New-style Sentry auth tokens (prefix "sntrys_") embed the org, so SENTRY_ORG
// is not required when using one.
const tokenImpliesOrg = Boolean(authToken?.startsWith('sntrys_'))

// If upload is "on" but required settings are missing, the Sentry plugin will
// just warn + skip the upload. Fail fast so we don't silently deploy without
// sourcemaps in Sentry.
if (!authToken) {
throw new Error('SENTRY_UPLOAD is enabled, but SENTRY_AUTH_TOKEN is missing')
}
if (!project) {
throw new Error('SENTRY_UPLOAD is enabled, but SENTRY_PROJECT is missing')
}
if (!org && !tokenImpliesOrg) {
throw new Error('SENTRY_UPLOAD is enabled, but SENTRY_ORG is missing')
}
}

export default defineConfig(async () => {
return {
Expand All @@ -24,28 +47,31 @@ export default defineConfig(async () => {
tailwindcss(),
reactRouter(),
tsconfigPaths(),
process.env.SENTRY_UPLOAD
SENTRY_UPLOAD
? sentryVitePlugin({
disable: MODE !== 'production',
authToken: process.env.SENTRY_AUTH_TOKEN,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
// By default the bundler plugin logs and continues on upload/release
// errors. Fail the build so we don't deploy with broken symbolication.
errorHandler: (err) => {
throw err
},
Comment on lines +56 to +60
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

@sentry/vite-plugin errorHandler default behavior documentation latest

💡 Result:

In @sentry/vite-plugin, the errorHandler option is a callback invoked when the plugin hits an error during release creation or sourcemaps upload. By default, no handler is set and the plugin throws the error, which fails/stops the Vite build. If you provide an errorHandler, the build will continue unless your handler itself throws. [1]


Fix inaccurate plugin behavior comment.

The code comment stating "by default the bundler plugin logs and continues on upload/release errors" contradicts the actual documented behaviour of @sentry/vite-plugin. By default (without an errorHandler), the plugin throws an error and stops the build. The explicit errorHandler here is appropriate as a defensive measure to preserve throwing semantics when Sentry switches to log-and-continue defaults in a future SDK version.

✏️ Suggested comment fix
-						// By default the bundler plugin logs and continues on upload/release
-						// errors. Fail the build so we don't deploy with broken symbolication.
+						// Override the default throw behaviour explicitly so this keeps
+						// failing the build even after Sentry switches to log-and-continue
+						// defaults in a future SDK version.
						errorHandler: (err) => {
							throw err
						},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// By default the bundler plugin logs and continues on upload/release
// errors. Fail the build so we don't deploy with broken symbolication.
errorHandler: (err) => {
throw err
},
// Override the default throw behaviour explicitly so this keeps
// failing the build even after Sentry switches to log-and-continue
// defaults in a future SDK version.
errorHandler: (err) => {
throw err
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vite.config.ts` around lines 54 - 58, The existing comment about the bundler
plugin's default behavior is incorrect; update the comment near the errorHandler
option in vite.config.ts (the errorHandler: (err) => { throw err } block) to
state that currently the `@sentry/vite-plugin` throws by default and that this
explicit errorHandler preserves that throwing behavior as a defensive measure in
case the plugin later changes to log-and-continue; modify the comment text only
(leave the errorHandler implementation unchanged) to accurately describe current
behavior and intent.

release: {
name: process.env.COMMIT_SHA,
setCommits: {
auto: true,
},
},
sourcemaps: {
filesToDeleteAfterUpload: await glob([
'./build/**/*.map',
'.server-build/**/*.map',
]),
},
})
: null,
],
build: {
// This is an OSS project, so it's fine to generate "regular" sourcemaps.
// If we ever want sourcemaps upload without exposing them publicly, switch
// to `sourcemap: 'hidden'` (and keep uploading to Sentry).
sourcemap: true,
cssMinify: MODE === 'production',
rollupOptions: {
external: [/node:.*/, 'stream', 'crypto'],
Expand Down