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
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nextjs/index.mdx
+16-25Lines changed: 16 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: 'Next.js'
2
+
title: "Next.js"
3
3
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.
4
4
sdk: sentry.javascript.nextjs
5
5
categories:
@@ -23,13 +23,13 @@ The wizard then guides you through the setup process, asking you to enable addit
23
23
24
24
<Expandabletitle="Want to learn more about these features?">
Get to the root cause of an issue faster by viewing a video-like reproduction
34
34
of what was happening in the user's browser before, during, and after the
35
35
problem.
@@ -40,12 +40,12 @@ This guide assumes that you enable all features and allow the wizard to create a
40
40
41
41
<Expandabletitle="What does the installation wizard change inside your application?">
42
42
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
49
49
50
50
</Expandable>
51
51
@@ -57,34 +57,25 @@ If you haven't tested your Sentry configuration yet, let's do it now. You can co
57
57
58
58
1. Open the example page `/sentry-example-page` in your browser. For most Next.js applications, this will be at localhost.
59
59
2. Click the "Throw error" button. This triggers two errors:
60
+
60
61
- a frontend error
61
62
- an error within the API route
62
63
63
64
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.
64
65
65
66
<Alertlevel="success"title="Tip">
66
67
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.
68
69
69
70
</Alert>
70
71
71
72
### View Captured Data in Sentry
72
73
73
74
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).
74
75
75
-
<Alertlevel="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.
<Expandabletitle="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.
<Expandabletitle="Want to learn more about these features?">
21
23
@@ -647,11 +649,7 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
647
649
localhost) and click the button to trigger a frontend error.
648
650
</OnboardingOption>
649
651
650
-
<Alertlevel="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.
@@ -703,13 +701,7 @@ Additionally, this starts a performance trace to measure the time it takes for t
703
701
704
702
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).
705
703
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.
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."
4
4
sdk: sentry.javascript.react
5
5
categories:
6
6
- javascript
7
7
- browser
8
8
---
9
9
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.
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
21
13
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:
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:
31
38
32
39
```bash {tabTitle:npm}
33
40
npm install @sentry/react --save
@@ -41,13 +48,15 @@ yarn add @sentry/react
41
48
pnpm add @sentry/react
42
49
```
43
50
44
-
## Configure
51
+
## Step 2: Configure
45
52
46
53
Sentry supports multiple versions of React Router. To learn how to configure them, read the <PlatformLinkto="/configuration/integrations/react-router/">React Router Integration</PlatformLink> docs.
47
54
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:
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:
94
105
95
106
```javascript
96
107
// Sentry initialization should be imported first!
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.
107
120
108
-
### React 19 Error Reporting
121
+
### Configure Error Hooks (React 19+)
109
122
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:
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)
130
144
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:
132
146
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
+
importReactfrom"react";
149
+
import*asSentryfrom"@sentry/react";
134
150
135
-
### Set Up React Router
151
+
<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
152
+
<Example />
153
+
</Sentry.ErrorBoundary>;
154
+
```
155
+
156
+
<Alertlevel="info">
157
+
To capture errors manually with your own error boundary, use the
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/).
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.
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/tanstackstart-react/index.mdx
+2-12Lines changed: 2 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -242,11 +242,7 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
242
242
Open the page in a browser and click the button to trigger a frontend error.
243
243
</OnboardingOption>
244
244
245
-
<Alertlevel="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.
@@ -303,13 +299,7 @@ Additionally, this starts a performance trace to measure the time it takes for t
303
299
304
300
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).
305
301
306
-
<Expandabletitle="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.
Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
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:
0 commit comments