Skip to content
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

Rework Next.js quick start guide (wizard) #12291

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
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
36 changes: 34 additions & 2 deletions docs/platforms/javascript/common/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
lforst marked this conversation as resolved.
Show resolved Hide resolved

</PlatformSection>

Expand All @@ -32,11 +35,23 @@ 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: 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>

Expand Down Expand Up @@ -64,12 +79,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"]}>
Expand All @@ -86,6 +106,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"]}>
Expand All @@ -96,6 +118,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.
Expand All @@ -110,4 +140,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" />
4 changes: 2 additions & 2 deletions docs/platforms/javascript/guides/nextjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
title: Next.js
description: Next.js is a flexible React framework that gives you building blocks to create fast, full-stack web applications. Learn how to set it up with Sentry.
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:
- javascript
Expand Down
42 changes: 29 additions & 13 deletions platform-includes/getting-started-install/javascript.nextjs.mdx
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.
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.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can always add or remove features manually later if needed. Though, the earlier you set these up, the better.
You can always add or remove features manually later if needed, but the setup is easiest if features are enabled from the start.

Not 100% sure, but it seems a bit "unclear" why it is better (from a users point of view). Maybe this is a bit clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could also remove the Alert ("This guide assumes that you enable all features ...") and instead write in basic text:

This guide assumes that you enable all features and allow the wizard to create an example page and route. You can add or remove features at any time, but setting them up now will save you the effort of configuring them manually later.

@mydea what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

sounds good to me!

<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)
- Add a Next.js instrumentation hook to your project (`instrumentation.ts`)
- Create or update your Next.js config with the default Sentry settings
- Create `.sentryclirc` with an auth token to upload source maps (this file is automatically added to `.gitignore`)
- Add an example page and route to your application to help verify your Sentry setup

</Expandable>
18 changes: 18 additions & 0 deletions platform-includes/getting-started-next-steps/javascript.nextjs.mdx
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.

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>
23 changes: 0 additions & 23 deletions platform-includes/getting-started-primer/javascript.nextjs.mdx
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>
60 changes: 28 additions & 32 deletions platform-includes/getting-started-verify/javascript.nextjs.mdx
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.

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

<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>
Loading