Skip to content

Commit 3038b0e

Browse files
authored
Fix Sentry source map uploads for Cloudflare builds (#1558)
1 parent 8c1e50a commit 3038b0e

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎docs/cloudflare-workers-migration.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Cloudflare Workers Builds is the production deployment owner. Its production tri
4747

4848
The CI deploy command applies every committed migration and verifies the exact Builder schema before `wrangler deploy` can run. Preview builds use `wrangler versions upload` and must not receive the production database secret.
4949

50+
Set `SENTRY_AUTH_TOKEN` under **Settings → Build → Build variables and secrets** for the `tanstack-com` Worker. Builds on `main` use this token to upload browser and Worker source maps to `tanstack/tanstack-com`. Check the build log and the [Sentry Source Maps page](https://tanstack.sentry.io/settings/projects/tanstack-com/source-maps/) after the next production build.
51+
5052
Required environment:
5153

5254
- `DATABASE_URL`: the production Postgres connection used to verify the Builder schema before the Worker is deployed. Run `pnpm run db:prepare-builder` once after a Builder schema change.

‎public/.assetsignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.map

‎vite.config.ts‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ import { workerIsolation } from './scripts/worker-isolation-vite'
2929
const isDev = process.env.NODE_ENV !== 'production'
3030
const shouldUseRedact = process.env.DISABLE_REDACT !== 'true'
3131
const localRedactPackageRoot = process.env.LOCAL_REDACT_PACKAGE_ROOT
32-
const shouldUseSentryPlugin =
33-
process.env.NODE_ENV === 'production' &&
34-
Boolean(process.env.SENTRY_AUTH_TOKEN)
35-
const shouldBuildSourcemaps =
36-
shouldUseSentryPlugin || process.env.BUILD_SOURCEMAPS === 'true'
3732
const SITE_URL = process.env.STAGING_SITE_URL || 'https://tanstack.com'
3833
const localDocsDevToken = isDev ? randomUUID() : ''
3934

@@ -217,6 +212,19 @@ function chatBuildId() {
217212

218213
export default defineConfig(async ({ command, mode }) => {
219214
const localEnv = { ...loadEnv(mode, __dirname, ''), ...process.env }
215+
const isProductionBuild = command === 'build' && mode === 'production'
216+
const cloudflareBranch = process.env.WORKERS_CI_BRANCH
217+
const sentryAuthToken =
218+
isProductionBuild && (!cloudflareBranch || cloudflareBranch === 'main')
219+
? localEnv.SENTRY_AUTH_TOKEN
220+
: undefined
221+
const shouldBuildSourcemaps =
222+
Boolean(sentryAuthToken) || localEnv.BUILD_SOURCEMAPS === 'true'
223+
if (isProductionBuild && cloudflareBranch === 'main' && !sentryAuthToken) {
224+
console.warn(
225+
'[Sentry] Source map upload skipped. Set SENTRY_AUTH_TOKEN in Cloudflare Workers Builds.',
226+
)
227+
}
220228
const useRemoteAi = Boolean(localEnv.CLOUDFLARE_API_TOKEN)
221229
const egress = command === 'serve' ? await startLocalMcpEgress() : undefined
222230
const config: UserConfig = {
@@ -264,6 +272,9 @@ export default defineConfig(async ({ command, mode }) => {
264272
: undefined,
265273
},
266274
environments: {
275+
client: {
276+
build: { sourcemap: shouldBuildSourcemaps ? 'hidden' : false },
277+
},
267278
ssr: {
268279
optimizeDeps: {
269280
// Resolve SSR dependencies through Redact instead of a separate prebundle.
@@ -520,16 +531,6 @@ export default defineConfig(async ({ command, mode }) => {
520531
viteReact(),
521532
chatIsolation(),
522533
workerIsolation(),
523-
524-
...(shouldUseSentryPlugin
525-
? [
526-
sentryTanstackStart({
527-
authToken: process.env.SENTRY_AUTH_TOKEN,
528-
org: 'tanstack',
529-
project: 'tanstack-com',
530-
}),
531-
]
532-
: []),
533534
contentCollections(),
534535
tailwindcss(),
535536
...(process.env.ANALYZE
@@ -541,6 +542,14 @@ export default defineConfig(async ({ command, mode }) => {
541542
}),
542543
]
543544
: []),
545+
...(sentryAuthToken
546+
? sentryTanstackStart({
547+
authToken: sentryAuthToken,
548+
org: 'tanstack',
549+
project: 'tanstack-com',
550+
autoInstrumentMiddleware: false,
551+
})
552+
: []),
544553
],
545554
}
546555
return config

0 commit comments

Comments
 (0)