StartStack uses Sentry to handle errors. Sentry is a popular error handling platform that provides detailed error reports, crash reports, and monitoring for web and mobile applications. It's the standard in the industry for handling errors and it integrates with Next.js seamlessly.
Sentry Setup
- Sign up for a Sentry account.
- Click on
Settings
. Note theOrganization Slug
. - Update the
SENTRY_ORG
in your.env
file.
SENTRY_ORG="<YOUR-ORGANIZATION-SLUG>"
- Create a new project and note the
Project Name
. - Update the
SENTRY_PROJECT
in your.env
file.
SENTRY_PROJECT="<YOUR-PROJECT-NAME>"
- Create a new auth token. Click
Settings
->Auth Tokens
->Create Auth Token
. - Update the
SENTRY_AUTH_TOKEN
in your.env
file.
SENTRY_AUTH_TOKEN="<YOUR-AUTH-TOKEN>"
- Create a new client key. Click
Settings
->Client Keys
copy the DSN orGenerate New Key
. - Update the
NEXT_PUBLIC_SENTRY_DSN
in your.env
file.
NEXT_PUBLIC_SENTRY_DSN="<YOUR-DSN>"
Sentry Configuration
Sentry is configured in the next.config.mjs
file. We have setup some defaults for you, but you can configure it to
your liking. Full documentation on the available options can be found here.
// export with sentry config, if you don't have a sentry auth token it will just ignore itexport default withSentryConfig(nextConfig, {silent: true, // Used to suppress logs, set to false to see sentry logs on buildtelemetry: false, // Set to true to send telemetry data to sentry// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#configure-tunneling-to-avoid-ad-blockerstunnelRoute: "/monitoring-tunnel",// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-maphideSourceMaps: process.env.NEXT_PUBLIC_VERCEL_ENV === "production",// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#disable-the-sentry-sdk-debug-logger-to-save-bundle-sizedisableLogger: process.env.NEXT_PUBLIC_VERCEL_ENV === "production",})
Capturing Errors
By default, StartStack will capture errors via:
/components/error-boundary.tsx
component used for creating error boundaries around other components./app/(app)/error.tsx
page./app/(auth)/error.tsx
page./app/(marketing)/error.tsx
page./app/global-error.tsx
page.- any
logger.error
calls.
If Sentry is configured the above will call Sentry's captureException
method.