diff --git a/docs/platforms/javascript/guides/nextjs/index.mdx b/docs/platforms/javascript/guides/nextjs/index.mdx index 1895484668458..cf45d28635725 100644 --- a/docs/platforms/javascript/guides/nextjs/index.mdx +++ b/docs/platforms/javascript/guides/nextjs/index.mdx @@ -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: @@ -23,13 +23,13 @@ The wizard then guides you through the setup process, asking you to enable addit - - [**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. @@ -40,12 +40,12 @@ This guide assumes that you enable all features and allow the wizard to create a - - 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 @@ -57,6 +57,7 @@ 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 @@ -64,7 +65,7 @@ Sentry captures both of these errors for you. Additionally, the button click sta - 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. @@ -72,19 +73,9 @@ Sentry captures both of these errors for you. Additionally, the button click sta 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). - - - 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. - - + - - - 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. - - + ## Next Steps @@ -100,7 +91,7 @@ Our next recommended steps for you are: - - 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/) diff --git a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx index 39137f271cb07..99f2de1096250 100644 --- a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -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: - + @@ -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. - - -Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring. - - + ### Tracing @@ -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). - - -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. - - + ## Next Steps diff --git a/docs/platforms/javascript/guides/react/index.mdx b/docs/platforms/javascript/guides/react/index.mdx index 02fe363a240ce..4222d5488ac38 100644 --- a/docs/platforms/javascript/guides/react/index.mdx +++ b/docs/platforms/javascript/guides/react/index.mdx @@ -1,33 +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 --- - - -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. - - - -## Features - -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/). +## Step 1: Install -Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. - -## Install +Choose the features you want to configure, and this guide will show you how: -Sentry captures data by using an SDK within your application’s runtime. + + +- [**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 the Sentry SDK + +Run the command for your preferred package manager to add the Sentry SDK to your application: ```bash {tabTitle:npm} npm install @sentry/react --save @@ -41,13 +48,15 @@ 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 React Router Integration 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 in your project's root directory, for example, `instrument.js`, and add the following code: -```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "3-8, 13-21, 24-30", "session-replay": "22, 33-39"}} +```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "1, 3-8, 13-21, 24-30", "session-replay": "22, 33-39"}} import { useEffect } from "react"; import * as Sentry from "@sentry/react"; import { @@ -90,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! @@ -103,11 +114,14 @@ const root = createRoot(container); root.render(); ``` -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"; @@ -126,25 +140,61 @@ 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 [`ErrorBoundary`](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"; -### Set Up React Router +An error has occurred

}> + +
; +``` + + + To capture errors manually with your own error boundary, use the + `captureReactException` function as described + [here](features/error-boundary/#manually-capturing-errors). + + + +## Step 4: Set Up React Router (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) + + + + + ## Step 4: Capture Redux State Data (Optional) + -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. - + -## Verify + + ## Step 6: Add Readable Stack Traces With Source Maps (Optional) + + + ## Step 5: Add Readable Stack Traces With Source Maps (Optional) + -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. + + + + ## Step 7: Verify Your Setup + + + ## Step 6: Verify Your Setup + + +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