Skip to content

Commit 9d53631

Browse files
yanglluocodex
andcommitted
docs(remix): update Vite and server setup instructions
Co-Authored-By: Codex <codex@openai.com>
1 parent 5be77ff commit 9d53631

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

‎packages/remix/README.md‎

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,37 @@
1515
This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added
1616
functionality related to Remix.
1717

18-
To use this SDK, initialize Sentry in your Remix entry points for both the client and server.
18+
The following setup is for Remix on Node.js. For Cloudflare, follow the
19+
[Remix configuration guide](https://docs.sentry.io/platforms/javascript/guides/remix/).
20+
21+
## Vite Configuration
22+
23+
Add `sentryRemixVitePlugin` after the Remix plugin. It provides the route manifest used to parameterize client-side
24+
transaction names, instruments supported server-side dependencies at build time, and uploads source maps.
25+
26+
```ts
27+
// vite.config.ts
28+
import { vitePlugin as remix } from '@remix-run/dev';
29+
import { sentryRemixVitePlugin } from '@sentry/remix/vite';
30+
import { defineConfig } from 'vite';
31+
32+
export default defineConfig({
33+
plugins: [
34+
remix(),
35+
sentryRemixVitePlugin({
36+
org: 'your-org',
37+
project: 'your-project',
38+
authToken: process.env.SENTRY_AUTH_TOKEN,
39+
}),
40+
],
41+
});
42+
```
43+
44+
Set `SENTRY_AUTH_TOKEN` in your build environment for source-map uploads. Do not expose it in client-side code.
45+
46+
## Client Initialization
47+
48+
Initialize Sentry in your client entry point:
1949

2050
```ts
2151
// entry.client.tsx
@@ -38,23 +68,43 @@ Sentry.init({
3868
});
3969
```
4070

41-
```ts
42-
// entry.server.tsx
71+
## Server Initialization
4372

44-
import { prisma } from '~/db.server';
73+
Initialize Sentry in a separate file and preload it before the server starts so instrumentation is registered before
74+
application dependencies load:
4575

76+
```js
77+
// instrument.server.mjs
4678
import * as Sentry from '@sentry/remix';
4779

4880
Sentry.init({
4981
dsn: '__DSN__',
5082
tracesSampleRate: 1,
51-
integrations: [Sentry.prismaIntegration()],
5283
// ...
5384
});
5485
```
5586

56-
Also, wrap your Remix root with `withSentry` to catch React component errors and to get parameterized router
57-
transactions.
87+
For example, start a Vite-built app with:
88+
89+
```bash
90+
NODE_OPTIONS="--import=./instrument.server.mjs" remix-serve ./build/server/index.js
91+
```
92+
93+
In your server entry point, export Sentry's error handler alongside your existing request handler:
94+
95+
```ts
96+
// entry.server.tsx
97+
import * as Sentry from '@sentry/remix';
98+
99+
export const handleError = Sentry.sentryHandleError;
100+
```
101+
102+
If you already have a custom `handleError`, wrap it with `Sentry.wrapHandleErrorWithSentry` instead.
103+
104+
## React Error Capture
105+
106+
Wrap your Remix root with `withSentry` to capture React component errors. Parameterized client-side transaction names
107+
also require the route manifest provided by the Vite plugin above.
58108

59109
```ts
60110
// root.tsx
@@ -119,8 +169,12 @@ Sentry.captureEvent({
119169

120170
## Sourcemaps and Releases
121171

122-
The Remix SDK provides a script that automatically creates a release and uploads sourcemaps. To generate sourcemaps with
123-
Remix, you need to call `remix build` with the `--sourcemap` option.
172+
For Vite projects, use `sentryRemixVitePlugin` as shown above to generate and upload source maps during the build.
173+
174+
### Classic Remix Compiler
175+
176+
For projects using the classic Remix compiler, the SDK provides a script that automatically creates a release and
177+
uploads sourcemaps. Generate sourcemaps by calling `remix build` with the `--sourcemap` option.
124178

125179
On release, call the upload sourcemaps command to upload source maps and create a release:
126180

0 commit comments

Comments
 (0)