Skip to content

Commit 20ef031

Browse files
committed
remix manual quick start guide and small update to wizard QS guide
1 parent 53ca31f commit 20ef031

File tree

2 files changed

+201
-59
lines changed

2 files changed

+201
-59
lines changed

docs/platforms/javascript/guides/remix/index.mdx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,47 @@ This guide assumes that you enable all features and allow the wizard to create a
3636

3737
</Expandable>
3838

39-
## Step 2: Avoid Ad Blockers With Tunneling (Optional)
39+
## Step 2: Server-Side Performance Monitoring
40+
41+
To capture performance data on the server side, wrap your Remix root component (`root.tsx`) with `withSentry`:
42+
43+
```tsx {filename: root.tsx}
44+
import {
45+
Links,
46+
LiveReload,
47+
Meta,
48+
Outlet,
49+
Scripts,
50+
ScrollRestoration,
51+
} from "@remix-run/react";
52+
53+
import { withSentry } from "@sentry/remix";
54+
55+
function App() {
56+
return (
57+
<html>
58+
<head>
59+
<Meta />
60+
<Links />
61+
</head>
62+
<body>
63+
<Outlet />
64+
<ScrollRestoration />
65+
<Scripts />
66+
<LiveReload />
67+
</body>
68+
</html>
69+
);
70+
}
71+
72+
export default withSentry(App);
73+
```
74+
75+
## Step 3: Avoid Ad Blockers With Tunneling (Optional)
4076

4177
<PlatformContent includePath="getting-started-tunneling" />
4278

43-
## Step 3: Verify Your Setup
79+
## Step 4: Verify Your Setup
4480

4581
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:
4682

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

Lines changed: 163 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
---
22
title: Manual Setup
33
sidebar_order: 1
4-
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."
55
---
66

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+
<Alert type="info">
8+
For the fastest setup, we recommend using the [wizard
9+
installer](/platforms/javascript/guides/remix).
10+
</Alert>
1011

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.
12+
<PlatformContent includePath="getting-started-prerequisites" />
1213

13-
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
1415

15-
## Install
16+
Choose the features you want to configure, and this guide will show you how:
1617

1718
<OnboardingOptionButtons
18-
options={["error-monitoring", "performance", "profiling", "session-replay"]}
19+
options={["error-monitoring", "performance", "session-replay"]}
1920
/>
2021

21-
Get started by installing the Sentry Remix SDK:
22+
<PlatformContent includePath="getting-started-features-expandable" />
23+
24+
### Install the Sentry SDK
25+
26+
Run the command for your preferred package manager to add the Sentry SDK to your application:
2227

2328
```bash {tabTitle:npm}
2429
npm install @sentry/remix --save
@@ -32,11 +37,11 @@ yarn add @sentry/remix
3237
pnpm add @sentry/remix
3338
```
3439

35-
## Configure
40+
## Step 2: Configure
3641

37-
To use this SDK, initialize Sentry in your Remix project for both the client and server.
42+
### Configure Client-Side Sentry
3843

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:
4045

4146
```typescript {tabTitle:Client} {filename: entry.client.tsx}
4247
import { useLocation, useMatches } from "@remix-run/react";
@@ -45,11 +50,11 @@ import { useEffect } from "react";
4550

4651
Sentry.init({
4752
dsn: "___PUBLIC_DSN___",
48-
53+
4954
// Adds request headers and IP for users, for more info visit:
5055
// https://docs.sentry.io/platforms/javascript/guides/remix/configuration/options/#sendDefaultPii
5156
sendDefaultPii: true,
52-
57+
5358
integrations: [
5459
// ___PRODUCT_OPTION_START___ performance
5560
Sentry.browserTracingIntegration({
@@ -89,12 +94,14 @@ Sentry.init({
8994

9095
#### Remix ErrorBoundary
9196

92-
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:
93100

94101
```tsx {filename: root.tsx}
95102
import { captureRemixErrorBoundaryError } from "@sentry/remix";
96103

97-
export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
104+
export const ErrorBoundary = () => {
98105
const error = useRouteError();
99106

100107
captureRemixErrorBoundaryError(error);
@@ -103,7 +110,9 @@ export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
103110
};
104111
```
105112

106-
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:
107116

108117
```tsx {filename: root.tsx}
109118
import {
@@ -137,21 +146,21 @@ function App() {
137146
export default withSentry(App);
138147
```
139148

140-
### Server-side Configuration
149+
### Configure Server-Side Sentry
141150

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:
143152

144153
```typescript {tabTitle:Server} {filename: instrument.server.mjs}
145154
import * as Sentry from "@sentry/remix";
146155

147156
Sentry.init({
148157
dsn: "___PUBLIC_DSN___",
149-
158+
150159
// Adds request headers and IP for users, for more info visit: and captures action formData attributes
151160
// https://docs.sentry.io/platforms/javascript/guides/remix/configuration/options/#sendDefaultPii
152161
sendDefaultPii: true,
153162
// ___PRODUCT_OPTION_START___ performance
154-
163+
155164
// Set tracesSampleRate to 1.0 to capture 100%
156165
// of transactions for tracing.
157166
// We recommend adjusting this value in production
@@ -169,22 +178,34 @@ Sentry.init({
169178
});
170179
```
171180

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:
173182

174183
```bash
175184
NODE_OPTIONS='--import=./instrument.server.mjs' remix-serve build
176185
# or
177186
NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build
178187
```
179188

180-
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+
<Expandable title="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.
194+
import "./instrument.server.mjs";
195+
// alternatively `require('./instrument.server.cjs')`
196+
197+
// ...
198+
199+
const app = express();
200+
201+
// ...
202+
```
181203

182-
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 <Link to="/platforms/javascript/guides/node/configuration/integrations/prisma/">Prisma</Link>, to get spans for your database calls.
204+
</Expandable>
183205

184-
#### Server-side Errors
206+
#### Capture Server-Side Errors
185207

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`:
188209

189210
```typescript {filename: entry.server.tsx}
190211
import * as Sentry from "@sentry/remix";
@@ -199,56 +220,141 @@ export const handleError = Sentry.wrapHandleErrorWithSentry(
199220
export const handleError = Sentry.sentryHandleError;
200221
```
201222

202-
### Source Maps Upload
223+
<Alert level="success" title="Tip">
203224

204-
To enable readable stack traces, <PlatformLink to="/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.
205226

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).
227+
</Alert>
207228

208-
## Verify
229+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
209230

210-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
231+
To upload source maps for clear error stack traces, add your Sentry auth token, organization, and project slug in your `vite.config.ts` file:
211232

212-
<Alert>
233+
<Alert title="Not using Vite?">
234+
Check our [Source Maps documentation](/platforms/remix/source-maps) for
235+
alternative setup options.
236+
</Alert>
213237

214-
Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead.
238+
```javascript {filename:vite.config.ts} {3, 10-17,20-23}
239+
import { defineConfig } from "vite";
240+
import { vitePlugin as remix } from "@remix-run/dev";
241+
import { sentryVitePlugin } from "@sentry/vite-plugin";
215242

216-
</Alert>
243+
export default defineConfig({
244+
plugins: [
245+
remix({
246+
// ... your Remix plugin options
247+
}),
248+
sentryVitePlugin({
249+
// If you use .sentryclirc or environment variables,
250+
// you don't need to specify these options
251+
org: "___ORG_SLUG___",
252+
project: "___PROJECT_SLUG___",
253+
// store your auth token in an environment variable
254+
authToken: process.env.SENTRY_AUTH_TOKEN,
255+
}),
256+
],
217257

218-
Then, throw an error in a `loader` or `action`.
258+
build: {
259+
sourcemap: true,
260+
// ... rest of your Vite build options
261+
},
262+
});
263+
```
219264

220-
```typescript {filename:routes/error.tsx}
221-
export const action: ActionFunction = async ({ request }) => {
222-
throw new Error("Sentry Error");
223-
};
265+
To keep your auth token secure, always store it in an environment variable instead of directly in your files:
266+
267+
<OrgAuthTokenNote />
268+
269+
```bash {filename:.env}
270+
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
224271
```
225272

226-
<Alert>
273+
## Step 4: Avoid Ad Blockers With Tunneling (Optional)
227274

228-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
275+
<PlatformContent includePath="getting-started-tunneling" />
229276

230-
</Alert>
277+
## Step 5: Verify Your Setup
231278

232-
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.
233280

234-
<Alert>
281+
### Issues
235282

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:
237284

238-
</Alert>
285+
```javascript
286+
<button
287+
type="button"
288+
onClick={
289+
throw new Error("Sentry Example Frontend Error");
290+
}
291+
>
292+
<span>
293+
Throw Sample Error
294+
</span>
295+
</button>
296+
```
239297

240-
## Custom Express Server
298+
<OnboardingOption optionId="performance" hideForThisOption>
299+
300+
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+
<OnboardingOption optionId="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+
await Sentry.startSpan(
315+
{
316+
name: "Example Frontend Span",
317+
op: "test",
318+
},
319+
async () => {
320+
const res = await fetch("/api/sentry-example-api");
321+
if (!res.ok) {
322+
throw new Error("Sentry Example Frontend Error");
323+
}
324+
}
325+
);
326+
}}
327+
>
328+
<span>Throw Sample Error</span>
329+
</button>
330+
```
241331

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

244-
```typescript {filename: server.ts}
245-
// import the Sentry instrumentation file before anything else.
246-
import "./instrument.server.mjs";
247-
// alternatively `require('./instrument.server.cjs')`
334+
</OnboardingOption>
248335

249-
// ...
336+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
250337

251-
const app = express();
338+
### View Captured Data in Sentry
252339

253-
// ...
254-
```
340+
Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).
341+
342+
<PlatformContent includePath="getting-started-verify-locate-data" />
343+
344+
## Next Steps
345+
346+
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+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
355+
356+
- If you encountered issues with the manual setup, try <PlatformLink to="/">our installation wizard</PlatformLink>
357+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
358+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
359+
360+
</Expandable>

0 commit comments

Comments
 (0)