Next.js
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.
You need:
To install Sentry using the installation wizard, run the following command within your project:
npx @sentry/wizard@latest -i nextjs
The wizard then guides you through the setup process, asking you to enable additional (optional) Sentry features for your application beyond error monitoring.
Want to learn a bit more about these features?
- Error Monitoring (always enabled): Automatically report errors, uncaught exceptions, and unhandled rejections. If you have something that looks like an exception, Sentry can capture it.
- 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: 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.
Important
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.
You can always add or remove features manually later if needed. Though, the earlier you set these up, the better.
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
Are you developing with Turbopack?
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.
Check the latest information on Sentry's support for Turbopack on GitHub.
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.
- Open the example page
/sentry-example-page
. - 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.
Tip
Don't forget to explore the example files' code in your project to understand what's happening after your button click.
Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).
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.
Need help locating the captured errors in your Sentry project?
- Open the 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.
- Open the 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.
- Open the 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.
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
- Continue to customize your configuration
- Get familiar with Sentry's product features like tracing, insights, and alerts
- Learn more about our Vercel integration
Did you experience any issues with this guide?
- If you encountered issues with our installation wizard, try setting up Sentry manually
- Get support
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").