Skip to content

Commit 7c6ba74

Browse files
inventarSarahmydea
andauthored
docs(js): React Quick Start guide for Error Monitoring feature only (#13061)
* React Quick Start guide for Error Monitoring feature only * update section on error boundary * make Step 4 optional * Update JS snippet Co-authored-by: Francesco Gringl-Novy <[email protected]> --------- Co-authored-by: Francesco Gringl-Novy <[email protected]>
1 parent 5f6ef99 commit 7c6ba74

File tree

7 files changed

+144
-84
lines changed

7 files changed

+144
-84
lines changed

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Next.js'
2+
title: "Next.js"
33
description: Learn how to set up and configure Sentry in your Next.js application using the installation wizard, capture your first errors, and view them in Sentry.
44
sdk: sentry.javascript.nextjs
55
categories:
@@ -23,13 +23,13 @@ The wizard then guides you through the setup process, asking you to enable addit
2323

2424
<Expandable title="Want to learn more about these features?">
2525

26-
- [**Issues**](/product/issues) (always enabled): Sentry's core error monitoring product that automatically reports errors,
26+
- [**Issues**](/product/issues) (always enabled): Sentry's core error monitoring product that automatically reports errors,
2727
uncaught exceptions, and unhandled rejections. If you have something that
2828
looks like an exception, Sentry can capture it.
29-
- [**Tracing**](/product/tracing): Track software performance while seeing the
29+
- [**Tracing**](/product/tracing): Track software performance while seeing the
3030
impact of errors across multiple systems. For example, distributed tracing
3131
allows you to follow a request from the frontend to the backend and back.
32-
- [**Session Replay**](/product/explore/session-replay/web):
32+
- [**Session Replay**](/product/explore/session-replay/web):
3333
Get to the root cause of an issue faster by viewing a video-like reproduction
3434
of what was happening in the user's browser before, during, and after the
3535
problem.
@@ -40,12 +40,12 @@ This guide assumes that you enable all features and allow the wizard to create a
4040

4141
<Expandable title="What does the installation wizard change inside your application?">
4242

43-
- Creates config files with the default `Sentry.init()` calls for all runtimes (Node.js, Browser, and Edge)
44-
- Adds a Next.js instrumentation hook to your project (`instrumentation.ts`)
45-
- Creates or updates your Next.js config with the default Sentry settings
46-
- Creates error handling components (`global-error.(jsx|tsx)` and `_error.jsx` for the Pages Router) if they don't already exist
47-
- Creates `.sentryclirc` with an auth token to upload source maps (this file is automatically added to `.gitignore`)
48-
- Adds an example page and route to your application to help verify your Sentry setup
43+
- Creates config files with the default `Sentry.init()` calls for all runtimes (Node.js, Browser, and Edge)
44+
- Adds a Next.js instrumentation hook to your project (`instrumentation.ts`)
45+
- Creates or updates your Next.js config with the default Sentry settings
46+
- Creates error handling components (`global-error.(jsx|tsx)` and `_error.jsx` for the Pages Router) if they don't already exist
47+
- Creates `.sentryclirc` with an auth token to upload source maps (this file is automatically added to `.gitignore`)
48+
- Adds an example page and route to your application to help verify your Sentry setup
4949

5050
</Expandable>
5151

@@ -57,34 +57,25 @@ If you haven't tested your Sentry configuration yet, let's do it now. You can co
5757

5858
1. Open the example page `/sentry-example-page` in your browser. For most Next.js applications, this will be at localhost.
5959
2. Click the "Throw error" button. This triggers two errors:
60+
6061
- a frontend error
6162
- an error within the API route
6263

6364
Sentry captures both of these errors for you. Additionally, the button click starts a performance trace to measure the time it takes for the API request to complete.
6465

6566
<Alert level="success" title="Tip">
6667

67-
Don't forget to explore the example files' code in your project to understand what's happening after your button click.
68+
Don't forget to explore the example files' code in your project to understand what's happening after your button click.
6869

6970
</Alert>
7071

7172
### View Captured Data in Sentry
7273

7374
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).
7475

75-
<Alert level="warning" title="Important">
76-
77-
Errors triggered from within your browser's developer tools (i.e., the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
78-
79-
</Alert>
76+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
8077

81-
<Expandable title="Need help locating the captured errors in your Sentry project?">
82-
83-
1. Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues) page and select an error from the issues list to view the full details and context of this error. For an interactive UI walkthrough, click [here](/product/sentry-basics/integrate-frontend/generate-first-error/#ui-walkthrough).
84-
2. Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/traces) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](/product/sentry-basics/distributed-tracing/generate-first-error/#ui-walkthrough).
85-
3. Open the [**Replays**](https://sentry.io/orgredirect/organizations/:orgslug/replays) page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
86-
87-
</Expandable>
78+
<PlatformContent includePath="getting-started-verify-locate-data" />
8879

8980
## Next Steps
9081

@@ -100,7 +91,7 @@ Our next recommended steps for you are:
10091

10192
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
10293

103-
- If you encountered issues with our installation wizard, try [setting up Sentry manually](/platforms/javascript/guides/nextjs/manual-setup/)
104-
- [Get support](https://sentry.zendesk.com/hc/en-us/)
94+
- If you encountered issues with our installation wizard, try [setting up Sentry manually](/platforms/javascript/guides/nextjs/manual-setup/)
95+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
10596

10697
</Expandable>

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ description: "Learn how to manually set up Sentry in your Next.js app and captur
1515

1616
Choose the features you want to configure, and this guide will show you how:
1717

18-
<OnboardingOptionButtons options={["error-monitoring", "performance", "session-replay"]} />
18+
<OnboardingOptionButtons
19+
options={["error-monitoring", "performance", "session-replay"]}
20+
/>
1921

2022
<Expandable title="Want to learn more about these features?">
2123

@@ -647,11 +649,7 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
647649
localhost) and click the button to trigger a frontend error.
648650
</OnboardingOption>
649651

650-
<Alert level="warning" title="Important">
651-
652-
Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
653-
654-
</Alert>
652+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
655653

656654
<OnboardingOption optionId="performance">
657655
### Tracing
@@ -703,13 +701,7 @@ Additionally, this starts a performance trace to measure the time it takes for t
703701
704702
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).
705703
706-
<Expandable title="Need help locating the captured errors in your Sentry project?">
707-
708-
1. Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues) page and select an error from the issues list to view the full details and context of this error. For an interactive UI walkthrough, click [here](/product/sentry-basics/integrate-frontend/generate-first-error/#ui-walkthrough).
709-
2. Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/traces) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](/product/sentry-basics/distributed-tracing/generate-first-error/#ui-walkthrough).
710-
3. Open the [**Replays**](https://sentry.io/orgredirect/organizations/:orgslug/replays) page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
711-
712-
</Expandable>
704+
<PlatformContent includePath="getting-started-verify-locate-data" />
713705
714706
## Next Steps
715707

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

Lines changed: 104 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
---
22
title: React
3-
description: "Learn about Sentry's React SDK and how it automatically reports errors and exceptions in your application."
3+
description: "Learn how to manually set up Sentry in your React app and capture your first errors."
44
sdk: sentry.javascript.react
55
categories:
66
- javascript
77
- browser
88
---
99

10-
<Alert>
11-
12-
Sentry's React SDK enables automatic reporting of errors and exceptions. The SDK is a wrapper around @sentry/browser, with added functionality related to React. All methods available in @sentry/browser can be imported from @sentry/react.
13-
14-
</Alert>
15-
1610
<PlatformContent includePath="getting-started-prerequisites" />
1711

18-
## Features
19-
20-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](/product/explore/session-replay/web/getting-started/).
12+
## Step 1: Install
2113

22-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
23-
24-
## Install
14+
Choose the features you want to configure, and this guide will show you how:
2515

2616
<OnboardingOptionButtons
2717
options={["error-monitoring", "performance", "session-replay"]}
2818
/>
2919

30-
Sentry captures data by using an SDK within your application’s runtime.
20+
<Expandable title="Want to learn more about these features?">
21+
22+
- [**Issues**](/product/issues) (always enabled): Sentry's core error monitoring product that automatically reports errors,
23+
uncaught exceptions, and unhandled rejections. If you have something that
24+
looks like an exception, Sentry can capture it.
25+
- [**Tracing**](/product/tracing): Track software performance while seeing the
26+
impact of errors across multiple systems. For example, distributed tracing
27+
allows you to follow a request from the frontend to the backend and back.
28+
- [**Session Replay**](/product/explore/session-replay/web):
29+
Get to the root cause of an issue faster by viewing a video-like reproduction
30+
of what was happening in the user's browser before, during, and after the
31+
problem.
32+
33+
</Expandable>
34+
35+
### Install the Sentry SDK
36+
37+
Run the command for your preferred package manager to add the Sentry SDK to your application:
3138

3239
```bash {tabTitle:npm}
3340
npm install @sentry/react --save
@@ -41,13 +48,15 @@ yarn add @sentry/react
4148
pnpm add @sentry/react
4249
```
4350

44-
## Configure
51+
## Step 2: Configure
4552

4653
Sentry supports multiple versions of React Router. To learn how to configure them, read the <PlatformLink to="/configuration/integrations/react-router/">React Router Integration</PlatformLink> docs.
4754

48-
Sentry should be initialized as early as possible in your application. We recommend putting the Sentry initialization code into its own file and including that file as the first import in your application entry point as shown in the example below:
55+
### Initialize the Sentry SDK
56+
57+
To import and initialize Sentry, create a file in your project's root directory, for example, `instrument.js`, and add the following code:
4958

50-
```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "3-8, 13-21, 24-30", "session-replay": "22, 33-39"}}
59+
```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "1, 3-8, 13-21, 24-30", "session-replay": "22, 33-39"}}
5160
import { useEffect } from "react";
5261
import * as Sentry from "@sentry/react";
5362
import {
@@ -90,7 +99,9 @@ Sentry.init({
9099
});
91100
```
92101

93-
Include the Sentry initialization file as the first import statement:
102+
### Apply Instrumentation to Your App
103+
104+
Initialize Sentry as early as possible in your application. We recommend putting the import of your initialization code as the first import in your app's entry point:
94105

95106
```javascript
96107
// Sentry initialization should be imported first!
@@ -103,11 +114,14 @@ const root = createRoot(container);
103114
root.render(<App />);
104115
```
105116

106-
Once this is done, all unhandled exceptions will be automatically captured by Sentry.
117+
## Step 3: Capture React Errors
118+
119+
To make sure Sentry captures all your app's errors, configure error handling based on your React version.
107120

108-
### React 19 Error Reporting
121+
### Configure Error Hooks (React 19+)
109122

110-
Starting with React 19, the `createRoot` and `hydrateRoot` methods from `react-dom` will expose error hooks that are used to capture errors automatically. To customize how errors are handled in specific error hooks, use the `Sentry.reactErrorHandler` function.
123+
The `createRoot` and `hydrateRoot` methods provide error hooks to capture errors automatically. These hooks apply to all React components mounted to the root container.
124+
Integrate Sentry with these hooks and customize error handling:
111125

112126
```javascript
113127
import { createRoot } from "react-dom/client";
@@ -126,25 +140,61 @@ const root = createRoot(container, {
126140
root.render();
127141
```
128142

129-
These hooks apply to all React components that are mounted to the container which is passed onto `createRoot`/`hydrateRoot`. For more precise control over error handling, we recommend adding an `ErrorBoundary` component to your application.
143+
### Add Error Boundary Components (React \<19)
130144

131-
### Add Error Boundary
145+
Use the [`ErrorBoundary`](features/error-boundary/) component to automatically send errors from specific component trees to Sentry and provide a fallback UI:
132146

133-
If you're using React 16 or above, you can use the [Error Boundary](features/error-boundary/) component to automatically send JavaScript errors from inside a component tree to Sentry, and set a fallback UI.
147+
```javascript
148+
import React from "react";
149+
import * as Sentry from "@sentry/react";
134150

135-
### Set Up React Router
151+
<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
152+
<Example />
153+
</Sentry.ErrorBoundary>;
154+
```
155+
156+
<Alert level="info">
157+
To capture errors manually with your own error boundary, use the
158+
`captureReactException` function as described
159+
[here](features/error-boundary/#manually-capturing-errors).
160+
</Alert>
161+
162+
<OnboardingOption optionId="performance">
163+
## Step 4: Set Up React Router (Optional)
136164

137165
The React Router integration is designed to work with our tracing package. Learn more about set up for our [React Router Integration](configuration/integrations/react-router/).
138166

139-
### Apply Redux
167+
## Step 5: Capture Redux State Data (Optional)
168+
169+
</OnboardingOption>
170+
171+
<OnboardingOption optionId="performance" hideForThisOption>
172+
## Step 4: Capture Redux State Data (Optional)
173+
</OnboardingOption>
140174

141-
To apply Sentry to Redux, learn more about the [Redux Integration](configuration/integrations/redux/) and its options.
175+
To capture Redux state data, use `Sentry.createReduxEnhancer` when initializing your Redux store.
142176

143-
<PlatformContent includePath="getting-started-sourcemaps" />
177+
<PlatformContent includePath="configuration/redux-init" />
144178

145-
## Verify
179+
<OnboardingOption optionId="performance">
180+
## Step 6: Add Readable Stack Traces With Source Maps (Optional)
181+
</OnboardingOption>
182+
<OnboardingOption optionId="performance" hideForThisOption>
183+
## Step 5: Add Readable Stack Traces With Source Maps (Optional)
184+
</OnboardingOption>
146185

147-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
186+
<PlatformContent includePath="getting-started-sourcemaps-short-version" />
187+
188+
<OnboardingOption optionId="performance">
189+
## Step 7: Verify Your Setup
190+
</OnboardingOption>
191+
<OnboardingOption optionId="performance" hideForThisOption>
192+
## Step 6: Verify Your Setup
193+
</OnboardingOption>
194+
195+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
196+
197+
Add the following test button to one of your pages, which will trigger an error that Sentry will capture when you click it:
148198

149199
```javascript
150200
<button
@@ -157,10 +207,30 @@ This snippet includes an intentional error, so you can test that everything is w
157207
</button>
158208
```
159209

160-
<Alert>
210+
Open the page in a browser (for most React applications, this will be at localhost) and click the button to trigger a frontend error.
161211

162-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
212+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
163213

164-
</Alert>
214+
### View Captured Data in Sentry
215+
216+
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).
217+
218+
<PlatformContent includePath="getting-started-verify-locate-data" />
219+
220+
## Next Steps
221+
222+
At this point, you should have integrated Sentry into your React application and should already be sending data to your Sentry project.
223+
224+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
225+
226+
- Extend Sentry to your backend using one of our [SDKs](/)
227+
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
228+
- Make use of <PlatformLink to="/features/redux">React-specific features</PlatformLink>
229+
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
230+
- Avoid ad-blockers with <PlatformLink to="/troubleshooting/#using-the-tunnel-option">tunneling</PlatformLink>
231+
232+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
233+
234+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
165235

166-
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.
236+
</Expandable>

docs/platforms/javascript/guides/tanstackstart-react/index.mdx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
242242
Open the page in a browser and click the button to trigger a frontend error.
243243
</OnboardingOption>
244244

245-
<Alert level="warning" title="Important">
246-
247-
Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
248-
249-
</Alert>
245+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
250246

251247
<OnboardingOption optionId="performance">
252248
### Tracing
@@ -303,13 +299,7 @@ Additionally, this starts a performance trace to measure the time it takes for t
303299

304300
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).
305301

306-
<Expandable title="Need help locating the captured errors in your Sentry project?">
307-
308-
1. Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues) page and select an error from the issues list to view the full details and context of this error. For an interactive UI walkthrough, click [here](/product/sentry-basics/integrate-frontend/generate-first-error/#ui-walkthrough).
309-
2. Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/traces) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](/product/sentry-basics/distributed-tracing/generate-first-error/#ui-walkthrough).
310-
3. Open the [**Replays**](https://sentry.io/orgredirect/organizations/:orgslug/replays) page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
311-
312-
</Expandable>
302+
<PlatformContent includePath="getting-started-verify-locate-data" />
313303

314304
## Next Steps
315305

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Alert level="warning" title="Important">
2+
3+
Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
4+
5+
</Alert>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The stack traces in your Sentry errors probably won't look like your actual code. To fix this, upload your source maps to Sentry. The easiest way to do this is by using the Sentry Wizard:
2+
3+
```bash
4+
npx @sentry/wizard@latest -i sourcemaps
5+
```

0 commit comments

Comments
 (0)