Skip to content

spike(studio): evaluate @sentry/tanstackstart-react unified SDK (client + server) - #47723

Closed
alaister wants to merge 1 commit into
masterfrom
alaister/tanstack-sentry-unified-spike
Closed

alaister wants to merge 1 commit into
masterfrom
alaister/tanstack-sentry-unified-spike

Conversation

@alaister

@alaister alaister commented Jul 8, 2026

Copy link
Copy Markdown
Member

Spike / comparison — not for merge as-is. Evaluates adopting the official unified @sentry/tanstackstart-react SDK (client + server) vs. the hand-rolled approach in #47666 (client) + #47721 (server). Base master.

Verdict: COMPARABLE effort, but the value is on the server — recommend a hybrid

The TanStack build compiled cleanly (✓ built, exit 0, server-boot smoke passed), tsc clean, instrumentation-client.test.ts 33/33. The Sentry vite plugin coexisted with assertNoChunkCycles/manualChunks/umdAmdShortCircuit with no new chunk cycles. So it's viable — but net effort is about the same as hand-rolling, because Studio's dual-runtime constraint still forces a compat alias + shared client-config module a normal TanStack app wouldn't need.

⚠️ Key finding: the SDK's client router-tracing is broken in the published browser bundle

Sentry.tanstackRouterBrowserTracingIntegration(router) — the flagship client integration — is not exported from the browser entry at both 10.59.0 and 10.64.0 (it exists only as a no-op stub on the server entry), yet the top-level .d.ts declares it. So tsc passes but the browser gets undefined → TypeError at init. Worked around with a typeof === 'function' guard falling back to browserTracingIntegration(). The documented client recipe is not actually shippable at these versions.

What the SDK gives us that the manual approach doesn't

  • Server request/function middleware (sentryGlobalRequestMiddleware / sentryGlobalFunctionMiddleware) that captures errors swallowed into 500s downstream — the exact class the manual wrapFetchHandler (and @sentry/nextjs) miss. Low-friction to add (Studio already has createStart({ requestMiddleware })).
  • wrapFetchWithSentry request-scoped context on the custom entries.
  • Source-map upload + release injection wired into the vite build (skips gracefully without a token) — we do neither today.
  • Removing the old @sentry/nextjs CJS-interop SSR-bundling workaround from vite.config.ts (the unified ESM server entry exposes real named exports).

What it costs

  • Coupling to an SDK whose client integration is currently broken (above).
  • The compat shim + alias + shared-config module are ongoing dual-runtime maintenance.
  • Bundle roughly comparable to the @sentry/nextjs it replaces (not smaller).

Recommendation — hybrid

  1. Adopt the SDK's server pieces (middleware + wrapFetchWithSentry + instrument.server.mjs) — a clear upgrade over feat(studio): report server-side errors to Sentry on the TanStack build #47721's manual wrapper (catches swallowed-500s) and low-friction.
  2. Adopt the @sentry/nextjs→unified alias — removes real CJS cruft from vite.config.ts.
  3. Keep the client hand-rolled / guarded (as in fix(studio): initialize Sentry on the TanStack build (captures were silent no-ops) #47666) until Sentry ships a working tanstackRouterBrowserTracingIntegration in the browser build.

Files: ~3 new modules + 7 edits (compat shim, lib/sentry-client-config.ts, instrument.server.mjs, router.tsx, start.ts, both server entries, vite.config.ts, instrumentation-client.ts). Full friction breakdown in the commit / thread.

https://claude.ai/code/session_01MLH8WVg8zBJnmZTYTV3ooo

Replaces Studio's hand-rolled Sentry wiring on the TanStack Start build with
the official unified `@sentry/tanstackstart-react` SDK (pinned to 10.59.0 to
match the existing @sentry/nextjs / @sentry/react versions):

- compat/sentry-nextjs.ts + vite alias: re-point the app's ubiquitous
  `@sentry/nextjs` imports to the unified SDK in the TanStack build (single
  SDK / single @sentry/core hub). Drops the @sentry/nextjs SSR-bundling
  workarounds since the unified SDK's ESM server entry exposes real named
  exports.
- lib/sentry-client-config.ts: shared client init factory + noise predicates,
  extracted from instrumentation-client.ts so both runtimes gate identically.
- router.tsx: client Sentry.init (client-only) via the shared factory + router
  browser tracing.
- instrument.server.mjs + start.ts + api/server.js + scripts/serve.js: server
  init, global request/function middleware, and wrapFetchWithSentry.
- vite.config.ts: sentryTanstackStart() plugin appended last.

TanStack build + server-boot smoke pass; tsc clean; client tests pass. Next.js
build path (instrumentation.ts / sentry.server.config.ts / next.config.ts)
left intact. See PR body for the difficulty assessment + friction points.

Claude-Session: https://claude.ai/code/session_01MLH8WVg8zBJnmZTYTV3ooo
@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 ↗︎.

@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)
studio-self-hosted Ready Ready Preview, Comment Jul 8, 2026 6:07am
studio-staging Ready Ready Preview, Comment Jul 8, 2026 6:07am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 8, 2026 6:07am
design-system Skipped Skipped Jul 8, 2026 6:07am
docs Skipped Skipped Open in v0 Jul 8, 2026 6:07am
ui-library Skipped Skipped Jul 8, 2026 6:07am
zone-www-dot-com Skipped Skipped Open in v0 Jul 8, 2026 6:07am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b3b1801d-0ec0-4b07-bdf0-4b552f5615bd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alaister/tanstack-sentry-unified-spike

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  232 passed
skipped  5 skipped

Details

stats  237 tests across 27 suites
duration  3 minutes, 52 seconds
commit  5911b6c

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

@alaister

alaister commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Spike done — verdict captured in the description. The real hybrid landed as #47724: adopts the unified SDK's server instrumentation (middleware + wrapFetchWithSentry + source maps) stacked on #47666, while the client stays on @sentry/react because the unified SDK's browser router-tracing integration is a broken stub at these versions. Closing this in favour of #47724.

@alaister alaister closed this Jul 8, 2026
alaister added a commit that referenced this pull request Jul 10, 2026
…n on the TanStack build (#47724)

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
#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.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <[email protected]>
Co-authored-by: Joshen Lim <[email protected]>
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.

1 participant