The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): adopt @sentry/tanstackstart-react server instrumentation on the TanStack build (#47724)
Alaister Youngad181489b129
diff --git a/apps/studio/api/server.js b/apps/studio/api/server.jsindex 3d12a8e55b3..e999b6ac104 100644--- a/apps/studio/api/server.js+++ b/apps/studio/api/server.js@@ -14,10 +14,35 @@ const isTanstack = process.env.STUDIO_FRAMEWORK === 'tanstack'// .includeFiles` config in vercel.ts.const tanstackEntry = ['..', 'dist', 'server', 'server.js'].join('/')-const handler = isTanstack+// Initialize server-side Sentry BEFORE the handler module is imported, so its+// instrumentation is in place when route modules evaluate. Gated to TanStack+// (the Next deploy uses instrumentation.ts / sentry.server.config.ts instead).+// Vercel functions can't use a `--import` startup flag, so we import the+// instrument module here at boot. Vercel provides env vars via process.env.+// A Sentry boot failure must never take the API down — mirror scripts/serve.js+// and fall back to the identity wrapper if init or the SDK import throws.+let wrapFetchWithSentry = (fetchHandler) => fetchHandler+if (isTanstack) {+ try {+ await import('../instrument.server.mjs')+ } catch (err) {+ console.warn('[api/server] Sentry server init skipped:', err?.message ?? err)+ }+ ;({ wrapFetchWithSentry } = await import('@sentry/tanstackstart-react').catch(() => ({+ wrapFetchWithSentry: (fetchHandler) => fetchHandler,+ })))+}++const rawHandler = isTanstack? (await import(tanstackEntry)).default: { fetch: () => new Response('Not Found', { status: 404 }) }+// Wrap the fetch handler so request-scoped errors (including those swallowed+// into a 500 downstream) are captured with request context.+const handler = isTanstack+ ? { ...rawHandler, fetch: wrapFetchWithSentry(rawHandler.fetch.bind(rawHandler)) }+ : rawHandler+// Vercel's Web API handler convention: export an object with `fetch(request)`.// TanStack's server build is already shaped that way — default-export it// verbatim and Vercel hands us a real Web Request.diff --git a/apps/studio/instrument.server.mjs b/apps/studio/instrument.server.mjsnew file mode 100644index 00000000000..e22bc149a0a--- /dev/null+++ b/apps/studio/instrument.server.mjs@@ -0,0 +1,42 @@+// Server-side Sentry init for the TanStack Start runtime.+//+// Mirrors sentry.server.config.ts (the Next.js server init) but uses the+// unified `@sentry/tanstackstart-react` SDK. Loaded:+// - self-hosted / e2e (scripts/serve.js): dynamically imported AFTER the+// .env files are read into process.env, so the DSN is available.+// - Vercel (api/server.js): imported at module top (gated to TanStack),+// Vercel injects env vars into process.env for us.+//+// Reads process.env at call time (unlike NEXT_PUBLIC_* which the client bundle+// inlines at build time), so it must run after env loading on self-hosted.++import * as Sentry from '@sentry/tanstackstart-react'++Sentry.init({+ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,+ ...(process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT && {+ environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,+ }),+ debug: false,++ // Tie server events to the deploy for source-map resolution.+ release: process.env.VERCEL_GIT_COMMIT_SHA,++ // Enable performance monitoring+ tracesSampleRate: 0.02,+ ignoreErrors: [+ 'ResizeObserver',+ 'Failed to load Stripe.js',+ // Network / infrastructure+ /504 Gateway Time-out/,+ 'Network request failed',+ 'Failed to fetch',+ 'AbortError',+ // Code-split loading failures+ 'ChunkLoadError',+ /Loading chunk [\d]+ failed/,+ // React hydration mismatches caused by extensions modifying DOM before hydration+ /text content does not match/i,+ /There was an error while hydrating/i,+ ],+})diff --git a/apps/studio/package.json b/apps/studio/package.jsonindex 78122739a90..442d76c48d2 100644--- a/apps/studio/package.json+++ b/apps/studio/package.json@@ -65,6 +65,7 @@"@number-flow/react": "^0.3.2","@sentry/nextjs": "catalog:","@sentry/react": "^10.27.0",+ "@sentry/tanstackstart-react": "catalog:","@std/path": "npm:@jsr/std__path@^1.0.8","@stripe/react-stripe-js": "6.1.0","@stripe/stripe-js": "9.1.0",diff --git a/apps/studio/scripts/serve.js b/apps/studio/scripts/serve.jsindex 4be5640a26f..92de487a624 100644--- a/apps/studio/scripts/serve.js+++ b/apps/studio/scripts/serve.js@@ -39,7 +39,25 @@ for (const [k, v] of Object.entries(parsed)) {)}-const { default: handler } = await import(path.join(studioRoot, 'dist/server/server.js'))+// Initialize server-side Sentry now that .env values are in process.env (the+// instrument module reads process.env.NEXT_PUBLIC_SENTRY_DSN at call time).+// Imported dynamically here rather than via a `--import` flag so it runs after+// the env-loading block above. Non-fatal if the SDK isn't present.+try {+ await import(path.join(studioRoot, 'instrument.server.mjs'))+} catch (err) {+ console.warn('[serve] Sentry server init skipped:', err?.message ?? err)+}+const { wrapFetchWithSentry } = await import('@sentry/tanstackstart-react').catch(() => ({+ wrapFetchWithSentry: (fetchHandler) => fetchHandler,+}))++const { default: rawHandler } = await import(path.join(studioRoot, 'dist/server/server.js'))+// Wrap so request-scoped errors (incl. ones swallowed into a 500) are captured.+const handler = {+ ...rawHandler,+ fetch: wrapFetchWithSentry(rawHandler.fetch.bind(rawHandler)),+}const mimeByExt = new Map([['.js', 'application/javascript; charset=utf-8'],diff --git a/apps/studio/start.ts b/apps/studio/start.tsindex 158248a618a..f8abddbf8e2 100644--- a/apps/studio/start.ts+++ b/apps/studio/start.ts@@ -1,3 +1,7 @@+import {+ sentryGlobalFunctionMiddleware,+ sentryGlobalRequestMiddleware,+} from '@sentry/tanstackstart-react'import { createMiddleware, createStart } from '@tanstack/react-start'import { BASE_PATH, IS_PLATFORM } from '@/lib/constants'@@ -30,6 +34,13 @@ const platformApiGuard = createMiddleware({ type: 'request' }).server(({ requestreturn next()})+// Sentry's global middlewares go at the FRONT so they wrap the whole request /+// server-function lifecycle — including errors that downstream code swallows+// into a 500, which the manual `@sentry/nextjs` approach never sees. The SDK's+// Vite plugin can auto-wrap these arrays instead, but we disable that+// (`autoInstrumentMiddleware: false` in vite.config.ts) and wire them+// explicitly so the instrumentation is visible in source.export const startInstance = createStart(() => ({- requestMiddleware: [platformApiGuard],+ requestMiddleware: [sentryGlobalRequestMiddleware, platformApiGuard],+ functionMiddleware: [sentryGlobalFunctionMiddleware],}))diff --git a/apps/studio/turbo.jsonc b/apps/studio/turbo.jsoncindex 08a66e00023..3a085d47704 100644--- a/apps/studio/turbo.jsonc+++ b/apps/studio/turbo.jsonc@@ -82,6 +82,7 @@"SENTRY_ORG","SENTRY_PROJECT","SENTRY_AUTH_TOKEN",+ "SKIP_ASSET_UPLOAD","NEXT_PUBLIC_SENTRY_DSN","AWS_BEDROCK_PROFILE","AWS_BEDROCK_ROLE_ARN",diff --git a/apps/studio/vite.config.ts b/apps/studio/vite.config.tsindex 60849d6f3d0..0ddb1e5f2ca 100644--- a/apps/studio/vite.config.ts+++ b/apps/studio/vite.config.ts@@ -3,6 +3,7 @@import fs from 'node:fs'import path from 'node:path'import { fileURLToPath } from 'node:url'+import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite'import tailwindcss from '@tailwindcss/vite'import { devtools } from '@tanstack/devtools-vite'import { tanstackStart } from '@tanstack/react-start/plugin/vite'@@ -591,6 +592,23 @@ export default defineConfig(({ command, mode }) => {...(basePath && { router: { basepath: basePath } }),}),viteReact(),+ // Sentry's TanStack Start plugin(s) MUST be last so source maps reflect+ // every prior transform. `sentryTanstackStart` returns an ARRAY of+ // plugins (route patterns, source-map upload, middleware auto-wrap), so+ // it's spread. Source-map UPLOAD is skipped gracefully without+ // SENTRY_AUTH_TOKEN (and under SKIP_ASSET_UPLOAD). We disable the+ // middleware auto-wrap because start.ts wires the Sentry global+ // middlewares explicitly.+ ...sentryTanstackStart({+ org: process.env.SENTRY_ORG ?? 'supabase',+ project: process.env.SENTRY_PROJECT ?? 'supabase-studio-tanstack',+ authToken: process.env.SENTRY_AUTH_TOKEN,+ autoInstrumentMiddleware: false,+ sourcemaps:+ process.env.SKIP_ASSET_UPLOAD === '1' || !process.env.SENTRY_AUTH_TOKEN+ ? { disable: true }+ : undefined,+ }),],}})diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 7f1e6200ce6..fd1e33ca42a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -12,6 +12,9 @@ catalogs:'@sentry/nextjs':specifier: ^10.59.0version: 10.59.0+ '@sentry/tanstackstart-react':+ specifier: ^10.59.0+ version: 10.59.0'@supabase/auth-js':specifier: 2.110.1version: 2.110.1@@ -960,6 +963,9 @@ importers:'@sentry/react':specifier: ^10.27.0version: 10.59.0([email protected])+ '@sentry/tanstackstart-react':+ specifier: 'catalog:'+ version: 10.59.0([email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))'@std/path':specifier: npm:@jsr/std__path@^1.0.8version: '@jsr/[email protected]'@@ -7227,6 +7233,15 @@ packages:resolution: {integrity: sha512-fpHL25JErsSfTyusuyZ3Q5JmRZeWYWynJO3PNiQH6A/58EqaCp8U5y8LCJ+CSPaeuBMka3S3Qn6U4eXcvkDMRA==}engines: {node: '>=18'}+ '@sentry/[email protected]':+ resolution: {integrity: sha512-hgPGPYdQJ/G1cGYOxAb7d4z3V+/k/E5/P/5TFPEEBLuIbFFk+JG0CISUDJdzXJjO382Lb99PBJuXGbueBmO79w==}+ engines: {node: '>= 18'}+ peerDependencies:+ rollup: '>=3.2.0'+ peerDependenciesMeta:+ rollup:+ optional: true+'@sentry/[email protected]':resolution: {integrity: sha512-mR3fWaU7uGxIstRba6YO+/6V3qIa7432F7/U8EWHry+dY4C9DWAVG90E2GCzeD2MwLSP0tB25i8p1TWTGiQgVg==}engines: {node: '>=18'}@@ -7236,10 +7251,18 @@ packages:vite:optional: true+ '@sentry/[email protected]':+ resolution: {integrity: sha512-K+22B4iGrlzp+trP9O22N4DdVQZQYlpyljw3SQw8cvOoTwHYarWAyvChvsPCqK7eB1zp+qIr2FP/Y/WO6UNXwQ==}+ engines: {node: '>=18'}+'@sentry/[email protected]':resolution: {integrity: sha512-4iVIZemakPvF8xlRAD7rlYtUlIloCvFHl3s2WGwO4vCa6vs1HtqggOdsDzW/zj6CoZ7kTu7+e7/Rw0EXYsWYrQ==}engines: {node: '>=18'}+ '@sentry/[email protected]':+ resolution: {integrity: sha512-qcoSzo4n2MulVQ70UUPLq6dTleb2a2HwL2wuwvAgWhPChrYTuk6A6mDg6aQb9fairPAwFPiU9PzOANpoDJcz1A==}+ engines: {node: '>= 18'}+'@sentry/[email protected]':resolution: {integrity: sha512-i3OQUrS0FZlXLgq57RIKDp+vHHzuvYKPCKewAPXULWKMsBXFGhP6veGRQ+6To/pmZkkXjEX5ofVNDy9C3jEPKQ==}engines: {node: '>= 18'}@@ -22881,6 +22904,16 @@ snapshots:'@sentry/browser-utils': 10.59.0'@sentry/core': 10.59.0+ dependencies:+ '@sentry/bundler-plugin-core': 5.3.0([email protected])([email protected])+ magic-string: 0.30.21+ optionalDependencies:+ rollup: 4.60.3+ transitivePeerDependencies:+ - encoding+ - supports-color+'@sentry/[email protected]([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))':dependencies:'@apm-js-collab/code-transformer': 0.15.0@@ -22894,12 +22927,38 @@ snapshots:transitivePeerDependencies:- supports-color+ '@sentry/[email protected]([email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))':+ dependencies:+ '@opentelemetry/api': 1.9.1+ '@sentry/browser-utils': 10.59.0+ '@sentry/conventions': 0.12.0+ '@sentry/core': 10.59.0+ '@sentry/node': 10.59.0([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))+ '@sentry/react': 10.59.0([email protected])+ transitivePeerDependencies:+ - '@opentelemetry/exporter-trace-otlp-http'+ - encoding+ - react+ - rollup+ - supports-color+ - vite+'@sentry/[email protected]':dependencies:'@opentelemetry/api': 1.9.1'@opentelemetry/resources': 2.8.0(@opentelemetry/[email protected])'@sentry/core': 10.59.0+ dependencies:+ '@sentry/bundler-plugin-core': 5.3.0([email protected])([email protected])+ transitivePeerDependencies:+ - encoding+ - rollup+ - supports-color+'@sentry/[email protected]([email protected])([email protected])([email protected]([email protected]))':dependencies:'@sentry/bundler-plugin-core': 5.3.0([email protected])([email protected])diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 4112912416c..a5efde9543d 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -9,6 +9,7 @@ blockExoticSubdeps: truecatalog:'@monaco-editor/react': ^4.7.0'@sentry/nextjs': ^10.59.0+ '@sentry/tanstackstart-react': ^10.59.0'@supabase/auth-js': 2.110.1'@supabase/postgrest-js': 2.110.1'@supabase/realtime-js': 2.110.1