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_ORGin your.envfile.
SENTRY_ORG="<YOUR-ORGANIZATION-SLUG>"
- Create a new project and note the
Project Name. - Update the
SENTRY_PROJECTin your.envfile.
SENTRY_PROJECT="<YOUR-PROJECT-NAME>"
- Create a new auth token. Click
Settings->Auth Tokens->Create Auth Token. - Update the
SENTRY_AUTH_TOKENin your.envfile.
SENTRY_AUTH_TOKEN="<YOUR-AUTH-TOKEN>"
- Create a new client key. Click
Settings->Client Keyscopy the DSN orGenerate New Key. - Update the
NEXT_PUBLIC_SENTRY_DSNin your.envfile.
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.tsxcomponent used for creating error boundaries around other components./app/(app)/error.tsxpage./app/(auth)/error.tsxpage./app/(marketing)/error.tsxpage./app/global-error.tsxpage.- any
logger.errorcalls.
If Sentry is configured the above will call Sentry's captureException method.