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
If you haven't tested your Sentry configuration yet, let's do it now. You can confirm that Sentry is working properly and sending data to your Sentry project by using the example page created by the installation wizard:
description: "Learn how to set up the SDK manually."
4
+
description: "Learn how to manually set up Sentry in your Remix app and capture your first errors."
5
5
---
6
6
7
-
If you can't (or prefer not to) run the [automatic setup](/platforms/javascript/guides/remix/#install), you can follow the instructions below to configure your application.
8
-
9
-
## Features
7
+
<Alerttype="info">
8
+
For the fastest setup, we recommend using the [wizard
9
+
installer](/platforms/javascript/guides/remix).
10
+
</Alert>
10
11
11
-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also analyze performance profiles from real users with [profiling](/product/explore/profiling/). Lastly, adding [session replay](/product/explore/session-replay/web/getting-started/) lets you get to the root of an error or performance issue faster by watching a video-like reproduction of a user session with.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
14
+
## Step 1: Install
14
15
15
-
## Install
16
+
Choose the features you want to configure, and this guide will show you how:
Run the command for your preferred package manager to add the Sentry SDK to your application:
22
27
23
28
```bash {tabTitle:npm}
24
29
npm install @sentry/remix --save
@@ -32,11 +37,11 @@ yarn add @sentry/remix
32
37
pnpm add @sentry/remix
33
38
```
34
39
35
-
## Configure
40
+
## Step 2: Configure
36
41
37
-
To use this SDK, initialize Sentry in your Remix project for both the client and server.
42
+
### Configure Client-Side Sentry
38
43
39
-
### Client-side Configuration
44
+
Create a client file `entry.client.tsx` in the `app` folder of your project if you don't have one already. In this file, import and initialize the Sentry SDK:
To capture errors from [ErrorBoundary](https://remix.run/docs/en/main/route/error-boundary), you should define your own `ErrorBoundary` in `root.tsx` and use `Sentry.captureRemixErrorBoundaryError` inside of it. You can also create route-specific error capturing behavior by defining `ErrorBoundary` in your route components. The `ErrorBoundary` you define in `root.tsx` will be used as a fallback for all routes.
97
+
To capture errors from your [ErrorBoundary](https://remix.run/docs/en/main/route/error-boundary), define it in `root.tsx` to act as a fallback for all routes or create route-specific error boundaries in your route components.
98
+
99
+
In your `ErrorBoundary` component, use `Sentry.captureRemixErrorBoundaryError` to send the captured error to Sentry:
To capture performance data, wrap your Remix root with `withSentry`.
113
+
#### Performance Monitoring
114
+
115
+
Wrap your Remix root component with `withSentry` to capture performance data:
107
116
108
117
```tsx {filename: root.tsx}
109
118
import {
@@ -137,21 +146,21 @@ function App() {
137
146
exportdefaultwithSentry(App);
138
147
```
139
148
140
-
### Server-side Configuration
149
+
### Configure Server-Side Sentry
141
150
142
-
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.
151
+
Create an instrumentation file `instrument.server.mjs` in your project's root folder and initialize the Sentry SDK within it:
// We recommend adjusting this value in production
@@ -169,22 +178,34 @@ Sentry.init({
169
178
});
170
179
```
171
180
172
-
Then run your Remix server with:
181
+
Then run your Remix server using the `--import` command line option and point it to this file to make sure the Sentry module loads before any other application code runs:
If you use the Express server instead of the 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).
189
+
<Expandabletitle="Are you using Express server?">
190
+
If you use the Express server instead of the built-in Remix server, you can import your instrumentation file directly at the top of your server implementation.
191
+
192
+
```typescript {filename: server.ts}
193
+
// import the Sentry instrumentation file before anything else.
Sentry's Remix SDK will automatically record your [`action`](https://remix.run/docs/en/main/route/action) and [`loader`](https://remix.run/docs/en/main/route/loader) transactions, as well as server-side errors. You can also initialize Sentry's database integrations, such as <Linkto="/platforms/javascript/guides/node/configuration/integrations/prisma/">Prisma</Link>, to get spans for your database calls.
204
+
</Expandable>
183
205
184
-
#### Server-side Errors
206
+
#### Capture Server-Side Errors
185
207
186
-
To capture server-side errors automatically, instrument the [`handleError`](https://remix.run/docs/en/main/file-conventions/entry.server#handleerror) function in your server entry point.
187
-
Wrap your error handler with `wrapHandleErrorWithSentry` or use `sentryHandleError` to export as your `handleError` function:
208
+
To automatically capture server-side errors, instrument the [`handleError`](https://remix.run/docs/en/main/file-conventions/entry.server#handleerror) function in your server entry point (`entry.server.tsx`). You can wrap your custom error handler with `wrapHandleErrorWithSentry` or directly use `sentryHandleError`:
To enable readable stack traces, <PlatformLinkto="/sourcemaps">configure source maps upload</PlatformLink> for your production builds.
225
+
Sentry's Remix SDK automatically records your [`action`](https://remix.run/docs/en/main/route/action) and [`loader`](https://remix.run/docs/en/main/route/loader) transactions for performance monitoring. You can also initialize Sentry's database integrations, such as [Prisma](/platforms/javascript/guides/node/configuration/integrations/prisma/), to get spans for your database calls.
205
226
206
-
After you've completed this setup, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance. You can also [manually capture errors](/platforms/javascript/guides/remix/usage).
To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
279
+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
233
280
234
-
<Alert>
281
+
### Issues
235
282
236
-
You can refer to [Remix Docs](https://remix.run/docs/en/main/guides/envvars#browser-environment-variables) to learn how to use your Sentry DSN with environment variables.
283
+
To verify that Sentry captures errors and creates issues in your Sentry project, add a test button to one of your pages:
Open the page in a browser (for most Remix applications, this will be at localhost:3000) and click the button to trigger a frontend error.
301
+
302
+
</OnboardingOption>
303
+
304
+
<OnboardingOptionoptionId="performance">
305
+
306
+
### Tracing
307
+
308
+
To test your tracing configuration, update the previous code snippet by calling a non-existing route and starting a trace to measure the time it takes for the execution of your code:
309
+
310
+
```javascript
311
+
<button
312
+
type="button"
313
+
onClick={async () => {
314
+
awaitSentry.startSpan(
315
+
{
316
+
name:"Example Frontend Span",
317
+
op:"test",
318
+
},
319
+
async () => {
320
+
constres=awaitfetch("/api/sentry-example-api");
321
+
if (!res.ok) {
322
+
thrownewError("Sentry Example Frontend Error");
323
+
}
324
+
}
325
+
);
326
+
}}
327
+
>
328
+
<span>Throw Sample Error</span>
329
+
</button>
330
+
```
241
331
242
-
You can import your server instrumentation file at the top of your Express server implementation.
332
+
Open the page in a browser (for most Remix applications, this will be at localhost:3000) and click the button to trigger the frontend error and a trace.
243
333
244
-
```typescript {filename: server.ts}
245
-
// import the Sentry instrumentation file before anything else.
At this point, you should have integrated Sentry into your Remix application and should already be sending error and performance data to your Sentry project.
347
+
348
+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
349
+
350
+
- Learn how to [manually capture errors](/platforms/javascript/guides/remix/usage/)
351
+
- Continue to [customize your configuration](/platforms/javascript/guides/remix/configuration/)
352
+
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts
353
+
354
+
<Expandablepermalink={false}title="Are you having problems setting up the SDK?">
355
+
356
+
- If you encountered issues with the manual setup, try <PlatformLinkto="/">our installation wizard</PlatformLink>
357
+
- Find various topics in <PlatformLinkto="/troubleshooting">Troubleshooting</PlatformLink>
0 commit comments