You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 738dfdd
Browse filesBrowse the repository at this point in the historyBrowse files
docs(tanstackstart-react): Update setup for TanStack Start stable (#20910)
## DESCRIBE YOUR PR
Updates the TanStack Start React docs for TanStack Start stable and the
current `@sentry/tanstackstart-react` SDK.
- Remove the beta alerts and require `@tanstack/react-start` 1.169.0 or
newer
- Make the automatic `instrument.server` loading in Nitro builds the
main path and drop the `cp`/`--import` production steps
- Forward request options in `src/server.ts` and add the CSRF middleware
back in `start.ts`
- Document server function spans (available since 11.15.0) and route
`onError` for loader errors
- Fix the error boundary and `errorComponent` examples
## IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs
to go live.
Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the
due date. You can update this information later by editing the PR
description.
- [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD
- [ ] Other deadline: YYYY-MM-DD
- [x] No deadline: Not urgent, can wait up to 1 week+
## SLA
- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
supplied a deadline.
Thanks in advance for your help!
## PRE-MERGE CHECKLIST
_Make sure you've checked the following before merging your changes:_
- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/tanstackstart-react/features/sentryTanstackStart.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ description: "Learn about the sentryTanstackStart Vite plugin."
7
7
8
8
The `sentryTanstackStart` Vite plugin simplifies source map configuration for TanStack Start applications. It automatically handles source map generation and upload to Sentry during production builds.
9
9
10
+
The plugin also loads your `instrument.server` file in production builds that use Nitro for a Node.js runtime. Learn more in [Load the Server Config When the Server Starts](/platforms/javascript/guides/tanstackstart-react/manual-setup/#load-the-server-config-when-the-server-starts).
11
+
10
12
## Usage
11
13
12
14
To automatically upload source maps, you need to provide your Sentry auth token, organization, and project slugs in your Vite configuration. The plugin then, by default, automatically enables hidden source maps and deletes `.map` files after upload.
To capture server-side errors from HTTP requests and server function calls, add Sentry's global middlewares to `createStart()` in your `src/start.ts` file.
150
+
To capture server-side errors from HTTP requests and server function calls, add Sentry's global middlewares to `createStart()` in your `src/start.ts` file. Since version 11.15.0, `sentryGlobalFunctionMiddleware` also creates a span for every server function call, including calls from other server functions or from loaders on the server. Without this middleware, Sentry doesn't create server function spans.
149
151
150
152
The Sentry middleware should be the first middleware in the arrays to ensure all errors are captured.
151
153
152
-
<Alertlevel="info">
153
-
SSR rendering exceptions are not captured by the middleware. Use
154
-
`captureException` to manually capture those errors.
155
-
</Alert>
154
+
A custom `src/start.ts` turns off the CSRF protection that TanStack Start adds to server functions by default, so the snippet adds it back with `createCsrfMiddleware`.
If a `loader` or `beforeLoad` throws while a page renders on the server, the router catches the error and shows the route's error component. Sentry doesn't report these errors automatically. To report them, set `onError` on the route:
This SDK is compatible with TanStack Start 1.0 RC and is currently in **beta**. Beta features are still in progress and may have bugs.
17
-
Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns.
18
-
19
-
</Alert>
20
-
21
14
This guide walks you through setting up Sentry in a [TanStack Start (React)](https://tanstack.com/start/latest/docs/framework/react/overview) app on Node.js.
22
15
For [TanStack Router (React)](https://tanstack.com/router/latest/docs/framework/react/overview), see our [React TanStack Router guide](/platforms/javascript/guides/react/features/tanstack-router/).
To capture server-side errors and tracing data, you need to explicitly define a [server entry point](https://tanstack.com/start/latest/docs/framework/react/guide/server-entry-point) in your application and wrap your request handler with `wrapFetchWithSentry`.
192
185
193
-
Follow the section below that matches your deployment setup:
194
-
195
-
#### With `--import` Flag (e.g. Node.js Server)
196
-
197
-
Use this setup when you can configure Node.js CLI flags.
198
-
199
-
Create a `src/server.ts` file in your project:
186
+
Create a `src/server.ts` file in your project. Pass `opts` on to the handler, so the request context that TanStack Start passes to it isn't lost:
##### Move the Sentry Server Config File for Production Usage
204
+
####Load the Server Config When the Server Starts
215
205
216
-
For production monitoring, you need to move the Sentry server config file to your build output. The exact location depends on where your build artifacts are deployed (for example, `"/dist"`, `".output/server"` or a platform-specific directory). For example, when using Nitro, copy the instrumentation file to `".output/server"` as shown in the example on the right.
If your app builds with [Nitro](https://nitro.build/) for a Node.js runtime, the `sentryTanstackStart` Vite plugin loads your server config for you in production builds:
226
209
227
-
##### Load Instrumentation on Startup
210
+
- It looks for `instrument.server.{ts,mts,js,mjs}` in the project root, then in `src/`.
211
+
- It bundles the file into the Nitro server build and loads it when the server starts.
212
+
- It instruments database drivers and other libraries at build time.
228
213
229
-
To load `instrument.server.mjs`, add the `--import` flag either directly to your run command or to the `NODE_OPTIONS` environment variable.
214
+
You start your production build as usual, without the `--import` flag.
215
+
216
+
`vite dev` doesn't create a server build, so in development, load the file with the `--import` flag in the `NODE_OPTIONS` environment variable:
+ "dev": "NODE_OPTIONS='--import ./instrument.server.mjs' vite dev --port 3000",
224
+
"start": "node .output/server/index.mjs",
239
225
}
240
226
}
241
227
```
242
228
243
-
#### Without `--import` Flag
244
-
245
-
Use this setup when you can't configure Node.js CLI flags or environment variables at runtime (for example, when deploying to serverless platforms like Vercel or Netlify).
246
-
247
-
<Alertlevel='warning'title='Restrictions'>
229
+
This doesn't apply to Cloudflare. For Cloudflare Workers, follow the [Cloudflare guide](/platforms/javascript/guides/tanstackstart-react/manual-setup/cloudflare/).
248
230
249
-
You can only instrument native Node.js APIs (such as `fetch` and the `http` module) with this installation method.
250
-
This means that the Sentry SDK will not capture data from database calls, queues, ORMs, third-party libraries, or other framework-specific data.
251
-
Thus, we recommend you follow the [`--import` flag setup instructions](#with---import-flag-eg-nodejs-server) if possible.
231
+
##### Without Nitro
252
232
253
-
This setup doesn't work for Cloudflare deployments.
254
-
255
-
</Alert>
256
-
257
-
Create a `src/server.ts` file in your project and import the server instrumentation file directly at the top of your server entry point.
The plugin loads the server config through a Nitro hook. If you deploy to Node.js without Nitro, load `instrument.server.mjs` yourself: add the `--import` flag to your start command, or import the file at the top of `src/server.ts`.
272
234
273
235
### Capture TanStack Start React Errors
274
236
275
237
#### Capture Server-Side Errors
276
238
277
-
To capture server-side errors from HTTP requests and server function calls, add Sentry's global middlewares to `createStart()` in your `src/start.ts` file.
239
+
To capture server-side errors from HTTP requests and server function calls, add Sentry's global middlewares to `createStart()` in your `src/start.ts` file. Since version 11.15.0, `sentryGlobalFunctionMiddleware` also creates a span for every server function call, including calls from other server functions or from loaders on the server. Without this middleware, Sentry doesn't create server function spans.
278
240
279
241
The Sentry middleware should be the first middleware in the arrays to ensure all errors are captured.
280
242
281
-
<Alertlevel="info">
282
-
SSR rendering exceptions are not captured by the middleware. Use
283
-
`captureException` to manually capture those errors.
284
-
</Alert>
243
+
A custom `src/start.ts` turns off the CSRF protection that TanStack Start adds to server functions by default, so the snippet adds it back with `createCsrfMiddleware`.
#### Capture Errors in Error Boundaries and Components (Optional)
266
+
#### Capture Errors in Route Loaders
302
267
303
-
Sentry automatically captures unhandled client-side errors. Errors caught by your own error boundaries aren't captured unless you report them manually:
268
+
If a `loader` or `beforeLoad` throws while a page renders on the server, the router catches the error and shows the route's error component. Sentry doesn't report these errors automatically. To report them, set `onError` on the route:
Sentry automatically captures unhandled client-side errors. Errors caught by your own error boundaries aren't captured unless you report them manually:
287
+
288
+
##### Custom Error Boundary
289
+
290
+
To report the errors that an error boundary catches, use Sentry's `ErrorBoundary` component instead of your own. Learn more in [React Error Boundary](/platforms/javascript/guides/react/features/error-boundary/).
324
291
325
292
##### TanStack Router `errorComponent`
326
293
327
294
Use Sentry's `captureException` function inside a `useEffect` hook within your `errorComponent`:
0 commit comments