Skip to content

Commit 1748841

Browse files
committed
feat(remix): Add OTEL auto-instrumentation instructions.
1 parent 13e3c61 commit 1748841

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

docs/platforms/javascript/guides/remix/manual-setup.mdx

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ pnpm add @sentry/remix
2424

2525
## Configuration
2626

27-
To use this SDK, initialize Sentry in your Remix entry points for both the client and server.
28-
29-
Create two files in the root directory of your project, `entry.client.tsx` and `entry.server.tsx` (if they don't already exist). Add your initialization code in these files for the client-side and server-side SDK, respectively.
30-
31-
The two configuration types are mostly the same, except that some configuration features, like Session Replay, only work in `entry.client.tsx`.
27+
To use this SDK, initialize Sentry in your Remix project for both the client and server.
3228

3329
<SignInNote />
3430

3531
### Client-side Configuration
3632

33+
Create `entry.client.tsx` in the root directory of your project (if it doesn't already exist). Add your client-side initialization code there.
34+
35+
<Note>
36+
Session Replay only works on the client-side.
37+
</Note>
38+
3739
```typescript {tabTitle:Client} {filename: entry.client.tsx}
3840
import { useLocation, useMatches } from "@remix-run/react";
3941
import * as Sentry from "@sentry/remix";
@@ -66,22 +68,6 @@ Sentry.init({
6668
});
6769
```
6870

69-
### Server-side Configuration
70-
71-
```typescript {tabTitle:Server} {filename: entry.server.tsx}
72-
import * as Sentry from "@sentry/remix";
73-
74-
Sentry.init({
75-
dsn: "___PUBLIC_DSN___",
76-
77-
// Set tracesSampleRate to 1.0 to capture 100%
78-
// of transactions for tracing.
79-
// We recommend adjusting this value in production
80-
tracesSampleRate: 1.0,
81-
});
82-
```
83-
84-
Initialize Sentry in your entry point for the server to capture exceptions and get performance metrics for your [`action`](https://remix.run/docs/en/main/route/action) and [`loader`](https://remix.run/docs/en/main/route/loader) functions. You can also initialize Sentry's database integrations, such as <Link to="/platforms/javascript/guides/node/tracing/database/opt-in/#prisma-orm-integration">Prisma</Link>, to get spans for your database calls.
8571

8672
To catch React component errors (in Remix v1) and routing transactions (in all Remix versions), wrap your Remix root with `withSentry`.
8773

@@ -145,6 +131,48 @@ withSentry(App, {
145131
});
146132
```
147133

134+
135+
### Server-side Configuration
136+
137+
Create an instrumentation file (named here as `instrument.server.mjs`) in your project. Add your initialization code in this file for the server-side SDK.
138+
139+
```typescript {tabTitle:Server} {filename: instrument.server.mjs}
140+
import * as Sentry from "@sentry/remix";
141+
142+
Sentry.init({
143+
dsn: "___PUBLIC_DSN___",
144+
// Set tracesSampleRate to 1.0 to capture 100%
145+
// of transactions for tracing.
146+
// We recommend adjusting this value in production
147+
tracesSampleRate: 1.0,
148+
149+
// To use Sentry OpenTelemetry auto-instrumentation
150+
// default: false
151+
autoInstrumentRemix: true,
152+
153+
// Optionally capture action formData attributes with errors.
154+
// This requires `sendDefaultPii` set to true as well.
155+
captureActionFormDataKeys: {
156+
key_x: true,
157+
key_y: true,
158+
},
159+
// To capture action formData attributes.
160+
sendDefaultPii: true
161+
});
162+
```
163+
164+
Then run your Remix server with:
165+
166+
```bash
167+
NODE_OPTIONS='--import=./instrument.server.mjs' remix-serve build
168+
# or
169+
NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build
170+
```
171+
172+
If you use Express server instead of Remix built-in server. You can alternatively import your instrumentation file directly at the top of your server implementation. See the example [here](#custom-express-server).
173+
174+
Sentry's Remix SDK will automatically record your `loader` and `action` transactions, as well as server-side errors. You can also [manually capture transactions](/platforms/javascript/guides/remix/usage).
175+
148176
## Remix v2 Features
149177

150178
_Available from SDK version 7.59.0_
@@ -209,24 +237,18 @@ To enable readable stack traces, <PlatformLink to="/sourcemaps">configure source
209237

210238
## Custom Express Server
211239

212-
If you use a custom Express server in your Remix application, you should wrap your [`createRequestHandler` function](https://remix.run/docs/en/main/other-api/adapter#createrequesthandler) manually with `wrapExpressCreateRequestHandler`. This isn't necessary if you're using the built-in Remix App Server.
240+
You can import your server instrumentation file at the top of your Express server implementation.
213241

214-
<Note>
215-
216-
`wrapExpressCreateRequestHandler` is available starting with version 7.11.0.
217-
218-
</Note>
219-
220-
```typescript {filename: server/index.ts}
221-
import { wrapExpressCreateRequestHandler } from "@sentry/remix";
222-
import { createRequestHandler } from "@remix-run/express";
242+
```typescript {filename: server.ts}
243+
// import the Sentry instrumentation file before anything else.
244+
import './instrument.server.mjs';
245+
// alternatively `require('./instrument.server.cjs')`
223246

224247
// ...
225248

226-
const createSentryRequestHandler =
227-
wrapExpressCreateRequestHandler(createRequestHandler);
249+
const app = express();
228250

229-
app.all("*", createSentryRequestHandler(/* ... */));
251+
// ...
230252
```
231253

232254
### Usage with Vite development mode (only for SDK versions < 7.106.0)

0 commit comments

Comments
 (0)