-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Rework Next.js quick start guide (wizard) #12291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2d668f7
4712da1
14aab2d
e183e6a
eddbdb0
e7707fc
25b37d9
abbeca1
37d0c9e
a832d7e
72bc602
e85c74e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,10 @@ Check out the other SDKs we support in the left-hand dropdown. | |
|
|
||
| ## Prerequisites | ||
|
|
||
| * You need a Sentry [account](https://sentry.io/signup/) and [project](/product/projects/) | ||
| You need: | ||
|
|
||
| - A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/) | ||
| - Your application up and running | ||
|
|
||
| </PlatformSection> | ||
|
|
||
|
|
@@ -32,11 +35,33 @@ Select which Sentry features you'd like to install in addition to Error Monitori | |
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformSection supported={["javascript.nextjs"]}> | ||
chargome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Step 1: Choose Your Sentry Features (Optional) | ||
|
||
|
|
||
| During setup, you'll have the option to enable specific Sentry features for your application. | ||
| Here's a quick overview of what's what: | ||
|
|
||
| - [**Error Monitoring**](/product/issues) (always enabled): Automatically report errors, uncaught exceptions, and unhandled rejections. If you have something that looks like an exception, Sentry can capture it. | ||
| - **Tunneling**: Route browser requests to Sentry through a Next.js rewrite to bypass ad-blockers that might interfere with Sentry's data collection. | ||
| - [**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/getting-started/): 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. | ||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Step 2: Install | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformSection notSupported={["javascript.nextjs"]}> | ||
|
|
||
| ## Install | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformCategorySection notSupported={["server"]}> | ||
| <PlatformSection notSupported={["javascript", "javascript.cordova"]}> | ||
| <OnboardingOptionButtons options={["error-monitoring", "performance", "session-replay"]} /> | ||
| <OnboardingOptionButtons | ||
| options={["error-monitoring", "performance", "session-replay"]} | ||
| /> | ||
| </PlatformSection> | ||
| </PlatformCategorySection> | ||
|
|
||
|
|
@@ -64,12 +89,17 @@ Select which Sentry features you'd like to install in addition to Error Monitori | |
| </PlatformSection> | ||
| </PlatformCategorySection> | ||
|
|
||
| <PlatformSection notSupported={["javascript.nextjs"]}> | ||
|
|
||
| Sentry captures data by using an SDK within your application’s runtime. | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformContent includePath="getting-started-install" /> | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformSection notSupported={["javascript.nextjs"]}> | ||
| ## Configure | ||
|
|
||
| <PlatformSection notSupported={["javascript.nextjs", "javascript.astro", "javascript.react", "javascript.react-router"]}> | ||
|
|
@@ -86,6 +116,8 @@ Sentry supports multiple versions of React Router. To learn how to configure the | |
|
|
||
| <PlatformContent includePath="getting-started-config" /> | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformContent includePath="getting-started-sourcemaps" /> | ||
|
|
||
| <PlatformSection supported={["javascript.bun"]}> | ||
|
|
@@ -96,6 +128,14 @@ Sentry supports multiple versions of React Router. To learn how to configure the | |
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformSection supported={["javascript.nextjs"]}> | ||
|
|
||
| <PlatformContent includePath="getting-started-verify" /> | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformSection notSupported={["javascript.nextjs"]}> | ||
|
|
||
| ## Verify | ||
|
|
||
| This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. | ||
|
|
@@ -110,4 +150,6 @@ Learn more about manually capturing an error or message in our <PlatformLink to= | |
|
|
||
| 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. | ||
|
|
||
| </PlatformSection> | ||
|
|
||
| <PlatformContent includePath="getting-started-next-steps" /> | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,24 +1,25 @@ | ||||||
| We recommend installing the SDK through our installation wizard: | ||||||
| To install Sentry using the installation wizard, run the following command within your project: | ||||||
|
|
||||||
| ```bash | ||||||
| npx @sentry/wizard@latest -i nextjs | ||||||
| ``` | ||||||
|
|
||||||
| The wizard will prompt you to log in to Sentry. It will then automatically do the following steps for you: | ||||||
| The wizard starts guiding you through the setup process, which also includes enabling the Sentry features listed above. | ||||||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| - create config files with the default `Sentry.init()` calls for each runtime (node, browser, edge) | ||||||
| - add a Next.js instrumentation hook to your project (`instrumentation.ts`) | ||||||
| - create or update your Next.js config with the default Sentry configuration | ||||||
| - create `.sentryclirc` with an auth token to upload source maps (this file is automatically added to `.gitignore`) | ||||||
| - add an example page to your app to verify your Sentry setup | ||||||
| <Alert level="warning" title="Important"> | ||||||
|
|
||||||
| After the wizard setup is completed, the SDK will automatically capture unhandled errors, and monitor performance. | ||||||
| You can also <PlatformLink to="/usage/">manually capture errors</PlatformLink>. | ||||||
| This guide assumes you enable all Sentry features during the wizard setup and allow it to create an example page and route. If you make different choices, you can still follow along, but you may need to make adjustments as you proceed. | ||||||
|
|
||||||
| To learn how to connect your app to Sentry and deploy it on Vercel, see the [Vercel integration](/organization/integrations/deployment/vercel/). | ||||||
| </Alert> | ||||||
|
|
||||||
| <Note> | ||||||
| You can always add or remove config options manually later if needed. Though, the earlier you set these up, the better. | ||||||
|
|
||||||
| If the setup through the wizard doesn't work for you, you can also <PlatformLink to="/manual-setup/">set up the SDK manually</PlatformLink>. | ||||||
| <Expandable permalink title="What does the installation wizard change inside your application?"> | ||||||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| </Note> | ||||||
| - Create config files with the default `Sentry.init()` calls for each runtime (node, browser, edge) | ||||||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - Add a Next.js instrumentation hook to your project (`instrumentation.ts`) | ||||||
|
||||||
| - Add a Next.js instrumentation hook to your project (`instrumentation.ts`) | |
| - Addition of Next.js instrumentation hook to your project (`instrumentation.ts`) |
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ## Next Steps | ||
|
|
||
| You should now have integrated Sentry into your Next.js application and should already be sending error and performance data to your Sentry project. | ||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Now's a good time to customize your setup and look into more advanced topics. | ||
| Our next recommended steps for you are: | ||
|
|
||
| - Learn more about our [Vercel integration](/organization/integrations/deployment/vercel/) | ||
| - Continue to [customize your configuration](/platforms/javascript/guides/nextjs/configuration/) | ||
| - Learn how to [manually capture errors](/platforms/javascript/guides/nextjs/usage/) | ||
| - Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts | ||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Expandable permalink={false} title="Did you experience any issues with this guide?"> | ||
|
|
||
| - 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> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,9 @@ | ||
| Features: | ||
| <Expandable title="Are you developing with Turbopack?"> | ||
chargome marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Automatic [Error Tracking](/product/issues/) with source maps for both JavaScript and TypeScript | ||
| - Automatic [Tracing](/product/performance/) for both the client and server | ||
| - Errors and Performance support for [Middleware](https://vercel.com/docs/concepts/functions/edge-middleware) and [Edge routes](https://vercel.com/docs/concepts/functions/edge-functions) in Vercel's edge runtime. Due to complexities with the runtime, some features of errors like stack traces may not be as expected. Requires <code>sentry.edge.config.js</code>, more info [here](/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files) | ||
| - Events [enriched](/platforms/javascript/enriching-events/context/) with device data | ||
| - [Breadcrumbs](/platforms/javascript/enriching-events/breadcrumbs/) created for outgoing HTTP request with XHR and Fetch, and console logs | ||
| - [Release health](/product/releases/health/) for tracking crash-free users and sessions | ||
| The Sentry SDK doesn't fully support `next dev --turbo` as Turbopack is still under development. | ||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Note> | ||
| However, Sentry will work fine in your production builds. | ||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The Sentry SDK does not fully support `next dev --turbo` while Turbopack does not ship all the features required to run Sentry. | ||
| Check the latest information on [Sentry's support for Turbopack on GitHub](https://github.com/getsentry/sentry-javascript/issues/8105). | ||
|
|
||
| Currently, when you run your devserver with Turbopack, the Sentry Next.js SDK will not be loaded in the browser. | ||
| Keep this in mind when configuring the SDK. | ||
|
|
||
| Note that this only affects the devserver. | ||
| The Sentry SDK will run without issues when you do a production build, even if you develop locally with Turbopack. | ||
|
|
||
| To support the SDK in the browser with Turbopack, [follow the feature request for client-side instrumentation in the Next.js repository](https://github.com/vercel/next.js/discussions/69294). | ||
|
|
||
| You can track Sentry's Turbopack support in the [GitHub Issue in the Sentry SDK repository](https://github.com/getsentry/sentry-javascript/issues/8105). | ||
|
|
||
| </Note> | ||
| </Expandable> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,30 @@ | ||
| Add a button to a frontend component that throws an error: | ||
| ## Step 3: Verify Your Setup | ||
|
||
|
|
||
| ```javascript {filename:pages/index.js} | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| throw new Error("Sentry Frontend Error"); | ||
| }} | ||
| > | ||
| Throw error | ||
| </button> | ||
| ``` | ||
| Let's confirm that Sentry is working properly and sending data to your Sentry project by using the example page and route created by the installation wizard. | ||
|
|
||
| And throw an error in an API route: | ||
| 1. Open the example page at [http://localhost:3000/sentry-example-page](http://localhost:3000/sentry-example-page) | ||
|
||
| 2. Click the "Throw error" button. This triggers two errors: | ||
| - a frontend error | ||
| - an error within the API route | ||
|
|
||
| ```javascript {filename:pages/api/error.js} | ||
| export default (req, res) => { | ||
| throw new Error("API throw error test"); | ||
| res.status(200).json({ name: "John Doe" }); | ||
| }; | ||
| ``` | ||
| Sentry will capture 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. | ||
|
|
||
| ```typescript {filename:pages/api/error.ts} | ||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||
| <Alert level="success" title="Tip"> | ||
|
|
||
| export default (req: NextApiRequest, res: NextApiResponse) => { | ||
| throw new Error("API throw error test"); | ||
| res.status(200).json({ name: "John Doe" }); | ||
| }; | ||
| ``` | ||
| Make sure to explore the example files' code in your project to understand what's happening after your button click. | ||
|
|
||
| <Note> | ||
|
|
||
| Errors triggered from within Browser DevTools are sandboxed, so they will not trigger error monitoring. Keep this in mind when verifying your Sentry SDK installation. | ||
|
|
||
| </Note> | ||
| </Alert> | ||
|
|
||
| <Alert title="Nested React Server Components" level="warning"> | ||
| ### View Captured Data in Sentry | ||
|
|
||
| Prior to Next.js version 15, errors thrown in nested React Server Components were not exposed by the framework, preventing the SDK from capturing them. | ||
| Now head over to your Sentry project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). | ||
|
|
||
| Next.js 15 introduced an `onRequestError` hook in `instrumentation.ts` that allows capturing and reporting these errors. | ||
| <Alert level="warning" title="Important"> | ||
|
|
||
| Refer to <PlatformLink to="/manual-setup/#errors-from-nested-react-server-components">Capturing Errors From Nested React Server Components</PlatformLink> for detailed setup instructions. | ||
| Errors triggered from within your browser's developer tools are sandboxed, so they will not trigger Sentry's error monitoring. | ||
lforst marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| </Alert> | ||
|
|
||
| 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. | ||
Uh oh!
There was an error while loading. Please reload this page.