Skip to content

feat(studio): adopt @sentry/tanstackstart-react server instrumentation on the TanStack build - #47724

Merged
alaister merged 3 commits into
masterfrom
alaister/tanstack-sentry-server-unified
Jul 10, 2026
Merged

alaister merged 3 commits into
masterfrom
alaister/tanstack-sentry-server-unified

Conversation

@alaister

@alaister alaister commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Stacked on #47666 (base alaister/tanstack-sentry-init; retarget to master when that merges). Supersedes #47721 (the manual @sentry/node wrapper). Client stays on #47666's @sentry/react setup.

Adopts the official @sentry/tanstackstart-react SDK on the server only, after a spike (#47723) evaluating the full unified client+server SDK. The spike found the SDK's browser tanstackRouterBrowserTracingIntegration is a broken no-op stub at 10.59.0/10.64.0 — so the client stays on @sentry/react (whose equivalent integration is a real, working implementation, already shipped in #47666). The server exports, however, are a clear upgrade and slot in cleanly.

What this adds (server-side, TanStack build only)

  • instrument.server.mjs — Sentry.init from @sentry/tanstackstart-react, mirroring sentry.server.config.ts + release: VERCEL_GIT_COMMIT_SHA.
  • start.ts — sentryGlobalRequestMiddleware + sentryGlobalFunctionMiddleware at the front of the existing createStart(...) middleware. This is the win: it captures request- and server-function errors including the ones swallowed into 500s — the exact class the manual wrapper (and the Next server SDK) miss.
  • api/server.js / scripts/serve.js — gated (STUDIO_FRAMEWORK==='tanstack') instrument init + wrapFetchWithSentry on the handler.
  • vite.config.ts — sentryTanstackStart({ …, autoInstrumentMiddleware: false }) as the last plugin: source-map upload + release injection (skips gracefully without an auth token). Middleware is wired explicitly rather than via the plugin's string-rewrite.

Guarantees

  • Client untouched — the @sentry/nextjs→@sentry/react alias and fix(studio): initialize Sentry on the TanStack build (captures were silent no-ops) #47666's client init are unchanged.
  • Next untouched — instrumentation.ts / sentry.server.config.ts etc. stay as-is; all new code is TanStack-gated.
  • No server SDK in the client bundle — verified after build: no @sentry/node / server middleware / wrapFetchWithSentry in dist/client/assets (start.ts's server import is tree-shaken out).

Verified

TanStack build exit 0 (past assertNoChunkCycles), post-build server boot served /api/get-utc-time → 200, tsc --noEmit clean, prettier/eslint clean. Node smoke: no-DSN init is a clean no-op; wrapped handler returns 200.

To test (deploy with a server DSN)

Throw a server error from an /api/* route (or a /_serverFn/*) — including one that gets turned into a 500 without rethrowing — and confirm a server event in Sentry with release = the deploy SHA. Compared to #47721, the swallowed-500 case should now be captured via the middleware.

Summary by CodeRabbit

  • New Features

    • Added Sentry integration for the Studio app’s TanStack Start runtime, including request and server-function instrumentation.
    • Wrapped server request handling to capture errors reliably, with tracing enabled.
    • Updated build tooling to conditionally upload source maps when credentials are present.
  • Bug Fixes

    • Improved resilience by safely falling back to a no-op Sentry setup if instrumentation cannot be loaded.
    • Ensured existing request protection remains enabled while adding observability middleware.
  • Chores / Config

    • Added SKIP_ASSET_UPLOAD to the build environment list to control cache/build behavior.

@alaister
alaister requested a review from a team as a code owner July 8, 2026 06:27
@vercel

vercel Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Jul 10, 2026 8:36am
docs Ready Ready Preview, Comment, Open in v0 Jul 10, 2026 8:36am
studio-self-hosted Ready Ready Preview, Comment Jul 10, 2026 8:36am
studio-staging Ready Ready Preview, Comment Jul 10, 2026 8:36am
ui-library Ready Ready Preview, Comment Jul 10, 2026 8:36am
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 Jul 10, 2026 8:36am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 10, 2026 8:36am

Request Review

@supabase

supabase Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 03b8649c-1601-494f-8dac-8a77a64def8c

📥 Commits

Reviewing files that changed from the base of the PR and between 437d176 and b1f9a7d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (2)
  • apps/studio/package.json
  • pnpm-workspace.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/package.json

📝 Walkthrough

Walkthrough

Adds Sentry error and performance instrumentation to the apps/studio TanStack Start runtime through server initialization, handler wrapping, global middleware, dependency registration, Vite integration, and Turbo build environment configuration.

Changes

Sentry instrumentation integration

Layer / File(s) Summary
Sentry server initialization and dependency
apps/studio/instrument.server.mjs, apps/studio/package.json, pnpm-workspace.yaml
Initializes Sentry from environment values with tracing and ignored errors, and registers @sentry/tanstackstart-react in the workspace dependency catalog.
Server handler wrapping
apps/studio/api/server.js, apps/studio/scripts/serve.js
Conditionally initializes Sentry and wraps TanStack rawHandler.fetch with fallback behavior in API and development server entry points.
TanStack middleware wiring
apps/studio/start.ts
Adds global Sentry request and function middleware alongside platformApiGuard.
Vite and build environment integration
apps/studio/vite.config.ts, apps/studio/turbo.jsonc
Adds the Sentry TanStack Start Vite plugin with conditional sourcemap settings and includes SKIP_ASSET_UPLOAD in Turbo build inputs.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ServerEntry as api/server.js or serve.js
  participant Instrument as instrument.server.mjs
  participant Sentry as `@sentry/tanstackstart-react`
  participant RawHandler as TanStack rawHandler

  ServerEntry->>Instrument: import and initialize Sentry
  ServerEntry->>Sentry: import wrapFetchWithSentry
  ServerEntry->>RawHandler: import raw handler
  ServerEntry->>Sentry: wrap rawHandler.fetch
  Client->>ServerEntry: fetch request
  ServerEntry->>RawHandler: invoke wrapped fetch
  RawHandler-->>Client: return Response
Loading

Suggested reviewers: djhi, ivasilov, jeremenichelli

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding TanStack server instrumentation for Sentry.
Description check ✅ Passed The description covers the change, current/new behavior, context, and verification, though it doesn't follow the template headings exactly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alaister/tanstack-sentry-server-unified

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  237 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  243 tests across 28 suites
duration  3 minutes, 46 seconds
commit  b1f9a7d

Flaky tests

Features › table-editor.spec.ts › table editor › should show rls accordingly

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/studio/instrument.server.mjs (1)

27-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Next.js-specific ignore patterns in a TanStack-only file.

NEXT_NOT_FOUND / NEXT_REDIRECT are Next.js control-flow signals; this module is exclusively wired into the TanStack build (per PR objectives). These entries are inert here and appear to be a straight copy from sentry.server.config.ts. Harmless but worth pruning for clarity.

🧹 Suggested cleanup
   ignoreErrors: [
     'ResizeObserver',
     'Failed to load Stripe.js',
-    // Next.js internals — not actual errors
-    'NEXT_NOT_FOUND',
-    'NEXT_REDIRECT',
     // Network / infrastructure
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/instrument.server.mjs` around lines 27 - 44, Prune the
Next.js-only ignore entries from the ignoreErrors list in instrument.server.mjs,
since this module is only used for the TanStack build and those patterns are
inert here. Update the ignoreErrors array in the instrumentation config to
remove NEXT_NOT_FOUND and NEXT_REDIRECT, keeping the remaining non-Next.js
patterns intact.
apps/studio/package.json (1)

67-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Version pinning inconsistent with neighboring Sentry deps.

@sentry/tanstackstart-react is exact-pinned (10.59.0) while @sentry/react uses a caret range (^10.27.0) and @sentry/nextjs uses the workspace catalog:. Consider aligning with the existing convention (caret range or catalog entry) unless the exact pin is intentional for this beta SDK.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/package.json` at line 67, The dependency version for
`@sentry/tanstackstart-react` is pinned differently from the neighboring Sentry
packages, so align its version specifier with the existing convention used in
package.json. Update the `@sentry/tanstackstart-react` entry to match either the
caret-range style used by `@sentry/react` or the catalog-based style used by
`@sentry/nextjs`, and keep the package name entry itself as the locator for the
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/studio/api/server.js`:
- Around line 17-30: The Sentry startup imports in the server bootstrap can
currently fail the whole API if `instrument.server.mjs` or
`@sentry/tanstackstart-react` throws during top-level await. Update
`apps/studio/api/server.js` to mirror the defensive pattern used in
`scripts/serve.js`: wrap the `await import('../instrument.server.mjs')` and the
`wrapFetchWithSentry` import in try/catch, keep the existing fallback
`wrapFetchWithSentry` identity function, and allow the server to continue
booting even when Sentry initialization fails.

---

Nitpick comments:
In `@apps/studio/instrument.server.mjs`:
- Around line 27-44: Prune the Next.js-only ignore entries from the ignoreErrors
list in instrument.server.mjs, since this module is only used for the TanStack
build and those patterns are inert here. Update the ignoreErrors array in the
instrumentation config to remove NEXT_NOT_FOUND and NEXT_REDIRECT, keeping the
remaining non-Next.js patterns intact.

In `@apps/studio/package.json`:
- Line 67: The dependency version for `@sentry/tanstackstart-react` is pinned
differently from the neighboring Sentry packages, so align its version specifier
with the existing convention used in package.json. Update the
`@sentry/tanstackstart-react` entry to match either the caret-range style used by
`@sentry/react` or the catalog-based style used by `@sentry/nextjs`, and keep the
package name entry itself as the locator for the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d01d0d2c-ca0f-444a-ba7c-e0741485d6b8

📥 Commits

Reviewing files that changed from the base of the PR and between d0155f6 and 632a7a1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (7)
  • apps/studio/api/server.js
  • apps/studio/instrument.server.mjs
  • apps/studio/package.json
  • apps/studio/scripts/serve.js
  • apps/studio/start.ts
  • apps/studio/turbo.jsonc
  • apps/studio/vite.config.ts

Comment thread apps/studio/api/server.js Resolved
@alaister
alaister force-pushed the alaister/tanstack-sentry-init branch from d0155f6 to 3f65818 Compare July 8, 2026 07:02
@alaister
alaister requested a review from a team as a code owner July 8, 2026 07:02
@alaister
alaister force-pushed the alaister/tanstack-sentry-server-unified branch from 09c0294 to ebc7195 Compare July 8, 2026 07:04
Base automatically changed from alaister/tanstack-sentry-init to master July 9, 2026 10:41
alaister added 2 commits July 9, 2026 18:46
…n on the TanStack build

Hybrid Sentry setup for the TanStack Start build:

- Server: use the unified `@sentry/tanstackstart-react` SDK (pinned to
  10.59.0 to share the single @sentry/core hub) for server instrumentation.
  `sentryGlobalRequestMiddleware` + `sentryGlobalFunctionMiddleware` wrap the
  whole request / server-function lifecycle — capturing request- and
  function-scoped errors, including ones downstream code swallows into a 500
  that the manual `@sentry/nextjs` path never sees — and `wrapFetchWithSentry`
  wraps the fetch handler on both Vercel (api/server.js) and self-hosted
  (scripts/serve.js). `instrument.server.mjs` mirrors sentry.server.config.ts
  (dsn/environment/tracesSampleRate/ignoreErrors) + release for source maps.
  `sentryTanstackStart()` runs last in vite.config for source-map/release
  upload (skipped gracefully without SENTRY_AUTH_TOKEN); middleware auto-wrap
  is disabled since start.ts wires the middlewares explicitly.

- Client: stays on `@sentry/react` (via #47666's `@sentry/nextjs` → compat
  shim alias). The unified SDK's browser `tanstackRouterBrowserTracingIntegration`
  is a no-op stub (returns undefined → TypeError), so the client keeps the
  verified `@sentry/react` integration. The server files import
  `@sentry/tanstackstart-react` directly — they only run in the SSR/Node
  bundle, so the broken browser export never loads. Verified the server SDK
  (`@sentry/node`, global middlewares) does not leak into the client bundle.

- Next.js build path (instrumentation.ts / sentry.server.config.ts /
  next.config.ts) is untouched. Supersedes the manual `@sentry/node` server
  wrapper.

Claude-Session: https://claude.ai/code/session_01MLH8WVg8zBJnmZTYTV3ooo
- api/server.js: wrap the Sentry boot (instrument import + SDK import) in
  try/catch with an identity-wrapper fallback, mirroring scripts/serve.js,
  so a Sentry init/import failure can never take the API function down.
- instrument.server.mjs: drop the Next-only NEXT_NOT_FOUND / NEXT_REDIRECT
  ignoreErrors entries — inert in the TanStack server runtime.
- package.json: pin @sentry/tanstackstart-react via catalog (like the other
  @sentry packages) instead of a bare version.

Claude-Session: https://claude.ai/code/session_01MLH8WVg8zBJnmZTYTV3ooo
@alaister
alaister force-pushed the alaister/tanstack-sentry-server-unified branch from ebc7195 to 437d176 Compare July 9, 2026 10:46

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified changes locally! Verified that throwing an error on an API route sends an event to sentry in tanstack mode

@alaister
alaister merged commit ad18148 into master Jul 10, 2026
34 checks passed
@alaister
alaister deleted the alaister/tanstack-sentry-server-unified branch July 10, 2026 08:52
@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1783673718)

Score Average Improvements Regressions
Knowledge Usage 94.9% (-3pp) - 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Tool Usage 72.5% (-4pp) - 2 🔴
Time_to_first_token 2.48tok (-0.49tok) 21 🟢 8 🔴
Llm_calls 2.78 (-0.23) 5 🟢 19 🔴
Tool_calls 3.25 (+0.31) 15 🟢 8 🔴
Errors 5.3 (-0.02) 4 🟢 2 🔴
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 26654.29tok (+858.8tok) 14 🟢 12 🔴
Prompt_cached_tokens 7915.4tok (-971.03tok) 10 🟢 15 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 621.77tok (+15.18tok) 13 🟢 16 🔴
Completion_reasoning_tokens 100.31tok (+3.69tok) 14 🟢 14 🔴
Total_tokens 27276.06tok (+873.99tok) 16 🟢 13 🔴
Estimated_cost 0$ (+0$) 13 🟢 13 🔴
Duration 14.73s (-2.2s) 23 🟢 6 🔴
Llm_duration 10.04s (-1.28s) 23 🟢 6 🔴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants