Skip to content

Commit e256948

Browse files
inventarSarahchargome
authored andcommitted
docs(js): Create Remix manual quick start guide (#13928)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Converted the Remix Manual Setup guide into a Quick Start guide. I removed the "Profiling" onboarding option because it is not in the wizard. If we want to keep it in the quick start guide(s), we should create a separate GH issue to add Profiling to both guides as a manual step (updating the wizard installer itself would be best, though) There's also an update in the wizard QS guide: "Step 2: Server-Side Performance Monitoring" -> This is an important step that is included in the manual setup but not in the wizard. @chargome is inquiring about updating the wizard installer. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: 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 added an urgent due date to it. 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) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Charly Gomez <charly.gomez@sentry.io>
1 parent 0d85bb3 commit e256948

File tree

2 files changed

+201
-57
lines changed

2 files changed

+201
-57
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 & 55 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
1819
options={["error-monitoring", "performance", "profiling", "session-replay", "user-feedback", "logs"]}
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({
@@ -100,12 +105,14 @@ Sentry.init({
100105

101106
#### Remix ErrorBoundary
102107

103-
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.
108+
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.
109+
110+
In your `ErrorBoundary` component, use `Sentry.captureRemixErrorBoundaryError` to send the captured error to Sentry:
104111

105112
```tsx {filename: root.tsx}
106113
import { captureRemixErrorBoundaryError } from "@sentry/remix";
107114

108-
export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
115+
export const ErrorBoundary = () => {
109116
const error = useRouteError();
110117

111118
captureRemixErrorBoundaryError(error);
@@ -114,7 +121,9 @@ export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
114121
};
115122
```
116123

117-
To capture performance data, wrap your Remix root with `withSentry`.
124+
#### Performance Monitoring
125+
126+
Wrap your Remix root component with `withSentry` to capture performance data:
118127

119128
```tsx {filename: root.tsx}
120129
import {
@@ -148,21 +157,21 @@ function App() {
148157
export default withSentry(App);
149158
```
150159

151-
### Server-side Configuration
160+
### Configure Server-Side Sentry
152161

153-
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.
162+
Create an instrumentation file `instrument.server.mjs` in your project's root folder and initialize the Sentry SDK within it:
154163

155164
```typescript {tabTitle:Server} {filename: instrument.server.mjs}
156165
import * as Sentry from "@sentry/remix";
157166

158167
Sentry.init({
159168
dsn: "___PUBLIC_DSN___",
160-
169+
161170
// Adds request headers and IP for users, for more info visit: and captures action formData attributes
162171
// https://docs.sentry.io/platforms/javascript/guides/remix/configuration/options/#sendDefaultPii
163172
sendDefaultPii: true,
164173
// ___PRODUCT_OPTION_START___ performance
165-
174+
166175
// Set tracesSampleRate to 1.0 to capture 100%
167176
// of transactions for tracing.
168177
// We recommend adjusting this value in production
@@ -185,22 +194,34 @@ Sentry.init({
185194
});
186195
```
187196

188-
Then run your Remix server with:
197+
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:
189198

190199
```bash
191200
NODE_OPTIONS='--import=./instrument.server.mjs' remix-serve build
192201
# or
193202
NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build
194203
```
195204

196-
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).
205+
<Expandable title="Are you using Express?">
206+
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.
197207

198-
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.
208+
```typescript {filename: server.(mjs|cjs)}
209+
// import the Sentry instrumentation file before anything else.
210+
import "./instrument.server.mjs";
211+
// alternatively `require('./instrument.server.cjs')`
199212

200-
#### Server-side Errors
213+
// ...
201214

202-
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.
203-
Wrap your error handler with `wrapHandleErrorWithSentry` or use `sentryHandleError` to export as your `handleError` function:
215+
const app = express();
216+
217+
// ...
218+
```
219+
220+
</Expandable>
221+
222+
#### Capture Server-Side Errors
223+
224+
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`:
204225

205226
```typescript {filename: entry.server.tsx}
206227
import * as Sentry from "@sentry/remix";
@@ -215,56 +236,143 @@ export const handleError = Sentry.wrapHandleErrorWithSentry(
215236
export const handleError = Sentry.sentryHandleError;
216237
```
217238

218-
### Source Maps Upload
239+
<Alert level="success" title="Tip">
219240

220-
To enable readable stack traces, <PlatformLink to="/sourcemaps">configure source maps upload</PlatformLink> for your production builds.
241+
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.
221242

222-
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).
243+
</Alert>
223244

224-
## Verify
245+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
225246

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

228-
<Alert>
249+
<Alert title="Not using Vite?">
229250

230-
Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead.
251+
Check our [Source Maps documentation](/platforms/javascript/guides/remix/sourcemaps/) for
252+
alternative setup options.
231253

232254
</Alert>
233255

234-
Then, throw an error in a `loader` or `action`.
256+
```javascript {filename:vite.config.ts} {3, 10-17,20-23}
257+
import { defineConfig } from "vite";
258+
import { vitePlugin as remix } from "@remix-run/dev";
259+
import { sentryVitePlugin } from "@sentry/vite-plugin";
235260

236-
```typescript {filename:routes/error.tsx}
237-
export const action: ActionFunction = async ({ request }) => {
238-
throw new Error("Sentry Error");
239-
};
261+
export default defineConfig({
262+
plugins: [
263+
remix({
264+
// ... your Remix plugin options
265+
}),
266+
sentryVitePlugin({
267+
// If you use .sentryclirc or environment variables,
268+
// you don't need to specify these options
269+
org: "___ORG_SLUG___",
270+
project: "___PROJECT_SLUG___",
271+
// store your auth token in an environment variable
272+
authToken: process.env.SENTRY_AUTH_TOKEN,
273+
}),
274+
],
275+
276+
build: {
277+
sourcemap: true,
278+
// ... rest of your Vite build options
279+
},
280+
});
240281
```
241282

242-
<Alert>
283+
To keep your auth token secure, always store it in an environment variable instead of directly in your files:
243284

244-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
285+
<OrgAuthTokenNote />
245286

246-
</Alert>
287+
```bash {filename:.env}
288+
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
289+
```
247290

248-
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.
291+
## Step 4: Avoid Ad Blockers With Tunneling (Optional)
249292

250-
<Alert>
293+
<PlatformContent includePath="getting-started-tunneling" />
251294

252-
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.
295+
## Step 5: Verify Your Setup
253296

254-
</Alert>
297+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
255298

256-
## Custom Express Server
299+
### Issues
257300

258-
You can import your server instrumentation file at the top of your Express server implementation.
301+
To verify that Sentry captures errors and creates issues in your Sentry project, add a test button to one of your pages:
259302

260-
```typescript {filename: server.ts}
261-
// import the Sentry instrumentation file before anything else.
262-
import "./instrument.server.mjs";
263-
// alternatively `require('./instrument.server.cjs')`
303+
```javascript
304+
<button
305+
type="button"
306+
onClick={
307+
throw new Error("Sentry Example Frontend Error");
308+
}
309+
>
310+
<span>
311+
Throw Sample Error
312+
</span>
313+
</button>
314+
```
264315

265-
// ...
316+
<OnboardingOption optionId="performance" hideForThisOption>
317+
318+
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.
319+
320+
</OnboardingOption>
321+
322+
<OnboardingOption optionId="performance">
323+
324+
### Tracing
325+
326+
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:
327+
328+
```javascript
329+
<button
330+
type="button"
331+
onClick={async () => {
332+
await Sentry.startSpan(
333+
{
334+
name: "Example Frontend Span",
335+
op: "test",
336+
},
337+
async () => {
338+
const res = await fetch("/api/sentry-example-api");
339+
if (!res.ok) {
340+
throw new Error("Sentry Example Frontend Error");
341+
}
342+
}
343+
);
344+
}}
345+
>
346+
<span>Throw Sample Error</span>
347+
</button>
348+
```
266349

267-
const app = express();
350+
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.
268351

269-
// ...
270-
```
352+
</OnboardingOption>
353+
354+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
355+
356+
### View Captured Data in Sentry
357+
358+
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).
359+
360+
<PlatformContent includePath="getting-started-verify-locate-data" />
361+
362+
## Next Steps
363+
364+
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.
365+
366+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
367+
368+
- Learn how to [manually capture errors](/platforms/javascript/guides/remix/usage/)
369+
- Continue to [customize your configuration](/platforms/javascript/guides/remix/configuration/)
370+
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts
371+
372+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
373+
374+
- If you encountered issues with the manual setup, try <PlatformLink to="/">our installation wizard</PlatformLink>
375+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
376+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
377+
378+
</Expandable>

0 commit comments

Comments
 (0)