Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions docs/platforms/javascript/guides/nextjs/index.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Next.js'
title: "Next.js"
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.
sdk: sentry.javascript.nextjs
categories:
Expand All @@ -23,13 +23,13 @@ The wizard then guides you through the setup process, asking you to enable addit

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

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

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

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

</Expandable>

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

1. Open the example page `/sentry-example-page` in your browser. For most Next.js applications, this will be at localhost.
2. Click the "Throw error" button. This triggers two errors:

- a frontend error
- an error within the API route

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.

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

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

</Alert>

### View Captured Data in Sentry

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

<Alert level="warning" title="Important">

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.

</Alert>
<PlatformContent includePath="getting-started-browser-sandbox-warning" />

<Expandable title="Need help locating the captured errors in your Sentry project?">

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

</Expandable>
<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

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

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

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

</Expandable>
18 changes: 5 additions & 13 deletions docs/platforms/javascript/guides/nextjs/manual-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ description: "Learn how to manually set up Sentry in your Next.js app and captur

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

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

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

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

<Alert level="warning" title="Important">

Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.

</Alert>
<PlatformContent includePath="getting-started-browser-sandbox-warning" />

<OnboardingOption optionId="performance">
### Tracing
Expand Down Expand Up @@ -703,13 +701,7 @@ Additionally, this starts a performance trace to measure the time it takes for t

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

<Expandable title="Need help locating the captured errors in your Sentry project?">

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

</Expandable>
<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

Expand Down
127 changes: 96 additions & 31 deletions docs/platforms/javascript/guides/react/index.mdx
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
---
title: React
description: "Learn about Sentry's React SDK and how it automatically reports errors and exceptions in your application."
description: "Learn how to manually set up Sentry in your React app and capture your first errors."
sdk: sentry.javascript.react
categories:
- javascript
- browser
---

<Alert>

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

</Alert>
## Step 1: Install

<PlatformContent includePath="getting-started-prerequisites" />
Choose the features you want to configure, and this guide will show you how:

## Features
<OnboardingOptionButtons
options={["error-monitoring", "performance", "session-replay"]}
/>

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/).
<Expandable title="Want to learn more about these features?">

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
- [**Issues**](/product/issues) (always enabled): Sentry's core error monitoring product that automatically reports errors,
uncaught exceptions, and unhandled rejections. If you have something that
looks like an exception, Sentry can capture it.
- [**Tracing**](/product/tracing): Track software performance while seeing the
impact of errors across multiple systems. For example, distributed tracing
allows you to follow a request from the frontend to the backend and back.
- [**Session Replay**](/product/explore/session-replay/web):
Get to the root cause of an issue faster by viewing a video-like reproduction
of what was happening in the user's browser before, during, and after the
problem.

## Install
</Expandable>

<OnboardingOptionButtons options={["error-monitoring", "performance", "session-replay"]} />
### Install the Sentry SDK

Sentry captures data by using an SDK within your application’s runtime.
Run the command for your preferred package manager to add the Sentry SDK to your application:

```bash {tabTitle:npm}
npm install @sentry/react --save
Expand All @@ -39,12 +48,13 @@ yarn add @sentry/react
pnpm add @sentry/react
```

## Configure
## Step 2: Configure

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.

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:
### Initialize the Sentry SDK

To import and initialize Sentry, create a file, for example, `instrument.js`, in your project and add the following code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To import and initialize Sentry, create a file, for example, `instrument.js`, in your project and add the following code:
To import and initialize Sentry, create a file in your project's root directory, for example, `instrument.js`, in your project and add the following code:


```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "3-8, 13-21, 24-30", "session-replay": "22, 33-39"}}
import { useEffect } from "react";
Expand Down Expand Up @@ -89,7 +99,9 @@ Sentry.init({
});
```

Include the Sentry initialization file as the first import statement:
### Apply Instrumentation to Your App

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:

```javascript
// Sentry initialization should be imported first!
Expand All @@ -102,11 +114,14 @@ const root = createRoot(container);
root.render(<App />);
```

Once this is done, all unhandled exceptions will be automatically captured by Sentry.
## Step 3: Capture React Errors

To make sure Sentry captures all your app's errors, configure error handling based on your React version.

### React 19 Error Reporting
### Configure Error Hooks (React 19+)

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.
The `createRoot` and `hydrateRoot` methods provide error hooks to capture errors automatically. These hooks apply to all React components mounted to the root container.
Integrate Sentry with these hooks and customize error handling:

```javascript
import { createRoot } from "react-dom/client";
Expand All @@ -125,25 +140,55 @@ const root = createRoot(container, {
root.render();
```

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.
### Add Error Boundary Components (React \<19)

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

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.
```javascript
import React from "react";
import * as Sentry from "@sentry/react";

<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
<Example />
</Sentry.ErrorBoundary>;
```

### Set Up React Router
<OnboardingOption optionId="performance">
## Step 4: Set Up React Router
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is optional


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/).

### Apply Redux
## Step 5: Capture Redux State Data (Optional)

</OnboardingOption>

<OnboardingOption optionId="performance" hideForThisOption>
## Step 4: Capture Redux State Data (Optional)
</OnboardingOption>

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

<PlatformContent includePath="getting-started-sourcemaps" />
<PlatformContent includePath="configuration/redux-init" />

## Verify
<OnboardingOption optionId="performance">
## Step 6: Add Readable Stack Traces With Source Maps (Optional)
</OnboardingOption>
<OnboardingOption optionId="performance" hideForThisOption>
## Step 5: Add Readable Stack Traces With Source Maps (Optional)
</OnboardingOption>

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
<PlatformContent includePath="getting-started-sourcemaps-short-version" />

<OnboardingOption optionId="performance">
## Step 7: Verify Your Setup
</OnboardingOption>
<OnboardingOption optionId="performance" hideForThisOption>
## Step 6: Verify Your Setup
</OnboardingOption>

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

Add the following test button to one of your pages, which will trigger an error that Sentry will capture when you click it:

```javascript
<button
Expand All @@ -156,10 +201,30 @@ This snippet includes an intentional error, so you can test that everything is w
</button>
```

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

<PlatformContent includePath="getting-started-browser-sandbox-warning" />

### View Captured Data in Sentry

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

<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

At this point, you should have integrated Sentry into your React application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

- Extend Sentry to your backend using one of our [SDKs](/)
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
- Make use of <PlatformLink to="/features/redux">React-specific features</PlatformLink>
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
- Avoid ad-blockers with <PlatformLink to="/troubleshooting/#using-the-tunnel-option">tunneling</PlatformLink>

Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
<Expandable permalink={false} title="Are you having problems setting up the SDK?">

</Alert>
- [Get support](https://sentry.zendesk.com/hc/en-us/)

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.
</Expandable>
14 changes: 2 additions & 12 deletions docs/platforms/javascript/guides/tanstackstart-react/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,7 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
Open the page in a browser and click the button to trigger a frontend error.
</OnboardingOption>

<Alert level="warning" title="Important">

Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.

</Alert>
<PlatformContent includePath="getting-started-browser-sandbox-warning" />

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

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

<Expandable title="Need help locating the captured errors in your Sentry project?">

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

</Expandable>
<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Alert level="warning" title="Important">

Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.

</Alert>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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:

```bash
npx @sentry/wizard@latest -i sourcemaps
```
Loading