-
-
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 6 commits
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,24 +1,40 @@ | ||||||
| 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 then guides you through the setup process, asking you to enable additional (optional) Sentry features for your application beyond error monitoring. | ||||||
|
|
||||||
| - 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 | ||||||
| <Expandable title="Want to learn a bit more about these features?"> | ||||||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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>. | ||||||
| - [**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. | ||||||
| - [**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. | ||||||
|
|
||||||
| To learn how to connect your app to Sentry and deploy it on Vercel, see the [Vercel integration](/organization/integrations/deployment/vercel/). | ||||||
| </Expandable> | ||||||
|
|
||||||
| <Note> | ||||||
| <Alert level="warning" title="Important"> | ||||||
|
|
||||||
| If the setup through the wizard doesn't work for you, you can also <PlatformLink to="/manual-setup/">set up the SDK manually</PlatformLink>. | ||||||
| This guide assumes that you enable all features and allow the wizard to create an example page and route. Keep this in mind as you proceed. | ||||||
|
|
||||||
| </Note> | ||||||
| </Alert> | ||||||
|
|
||||||
| You can always add or remove features manually later if needed. Though, the earlier you set these up, the better. | ||||||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| <Expandable title="What does the installation wizard change inside your application?"> | ||||||
|
|
||||||
| - Create config files with the default `Sentry.init()` calls for all runtimes (Node.js, Browser, and Edge) | ||||||
inventarSarah 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 how to [manually capture errors](/platforms/javascript/guides/nextjs/usage/) | ||
| - Continue to [customize your configuration](/platforms/javascript/guides/nextjs/configuration/) | ||
| - Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts | ||
| - Learn more about our [Vercel integration](/organization/integrations/deployment/vercel/) | ||
|
|
||
| <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 @@ | ||
| Features: | ||
|
|
||
| - 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 | ||
|
|
||
| <Note> | ||
|
|
||
| The Sentry SDK does not fully support `next dev --turbo` while Turbopack does not ship all the features required to run Sentry. | ||
|
|
||
| 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,42 @@ | ||
| Add a button to a frontend component that throws an error: | ||
| ## Step 2: Verify Your Setup | ||
|
|
||
| ```javascript {filename:pages/index.js} | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| throw new Error("Sentry Frontend Error"); | ||
| }} | ||
| > | ||
| Throw error | ||
| </button> | ||
| ``` | ||
| <Expandable title="Are you developing with Turbopack?"> | ||
|
|
||
| And throw an error in an API route: | ||
| The Sentry SDK doesn't fully support `next dev --turbo` as Turbopack is still under development. This means that the Sentry SDK will not capture any data for the frontend. Other than that, your devserver should be fully operational. | ||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```javascript {filename:pages/api/error.js} | ||
| export default (req, res) => { | ||
| throw new Error("API throw error test"); | ||
| res.status(200).json({ name: "John Doe" }); | ||
| }; | ||
| ``` | ||
| Check the latest information on [Sentry's support for Turbopack on GitHub](https://github.com/getsentry/sentry-javascript/issues/8105). | ||
|
|
||
| ```typescript {filename:pages/api/error.ts} | ||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||
| </Expandable> | ||
|
|
||
| export default (req: NextApiRequest, res: NextApiResponse) => { | ||
| throw new Error("API throw error test"); | ||
| res.status(200).json({ name: "John Doe" }); | ||
| }; | ||
| ``` | ||
| If you haven't tested your setup yet, let's do it now. You can 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. | ||
inventarSarah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Note> | ||
| 1. Open the example page `/sentry-example-page`. | ||
| 2. Click the "Throw error" button. This triggers two errors: | ||
| - a frontend error | ||
| - an error within the API route | ||
|
|
||
| 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. | ||
| 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. | ||
|
|
||
| </Note> | ||
| <Alert level="success" title="Tip"> | ||
|
|
||
| <Alert title="Nested React Server Components" level="warning"> | ||
| Don't forget to explore the example files' code in your project to understand what's happening after your button click. | ||
|
|
||
| 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. | ||
| </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). | ||
|
|
||
| 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 (i.e., the browser console) are sandboxed, so they will not trigger Sentry's error monitoring. | ||
|
|
||
| </Alert> | ||
|
|
||
| <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> | ||
Uh oh!
There was an error while loading. Please reload this page.