This app demonstrates how to configure Sentry (both @sentry/browser
and @sentry/node
) in a NextJS application to capture:
- Unhandled exceptions
- Handled exception
- Capture message
You'll also be able to do the following:
- Capture the user
- Associate commits (make sure that your GitHub repo is integrated into your Sentry organization)
- Manaully upload source maps using
sentry-cli
- Automatically upload source maps using the
sentry-webpack-plugin
. (Use withnpm run start
/production. This is an alternative to manually uploading source maps)
Official documentation:
| dependency | version
| ------------- |:-------------:|
| @sentry/browser | ^5.15.4 |
| @sentry/node | ^5.15.4 |
| sentry-cli | 1.53.0 |
| @sentry/webpack-plugin | ^1.10.0 |
| @zeit/next-source-maps | 0.0.4-canary.1 |
| next | 9.3.6
| react | 16.13.1 |
| react-dom | 16.13.1 |
| swr | ^0.2.0 |
| node.js | 13.8.0 |
-
git clone git@github.com:sentry-demos/next-js.git
-
Install dependencies
$ npm install
-
Create a Sentry project and replace
SENTRY_DSN
with your Sentry DSN innext.config.js
-
Include your
SENTRY_AUTH_TOKEN
,SENTRY_ORG
, andSENTRY_PROJECT
to theMakefile
. If you haven't created an Auth Token, you can create one from your Sentry organization on the API Keys page. Make sure that your GitHub repo is integrated with your Sentry Organization.
- Run the dev server and generate souce maps for the dev environment (this will create a
.next
folder)
$ npm run dev
- Create a release, associate commits, and upload source maps
$ make setup_release
- Build the production app and generate souce maps (this will create a
.next
folder)
$ npm run build
- Create a release, associate commits, and upload source maps
$ make setup_release
- If you only need to upload source maps
make upload_sourcemaps
-
If using
sentry-webpack-plugin
, uncomment the configuration innext.config.js
-
Run the production app
$ npm run start
- To upgrade NextJS
$ npm i next@latest react@latest react-dom@latest
- Sentry JavaScript
- Sentry Node
- NextJS
- This is a Next.js project bootstrapped with
create-next-app