# Next.js boilerplate with Sentry

> Error and performance monitoring wired the way Next.js 16 expects it. instrumentation.ts covers the server and edge runtimes, and instrumentation-client.ts covers the browser. onRequestError captures Server Component and Route Handler failures. A global-error boundary catches the ones React would otherwise swallow.
The part that is not boilerplate is src/lib/observability/scrub.ts. Every event passes through it before it leaves the process. Request bodies are dropped, not filtered. Console breadcrumbs are discarded. Users are identified by opaque id only. captureHandled() attaches a stable fingerprint, so caught errors group by cause, not by whichever helper wrapped them.

Stack traces with the release and route attached, scrubbed of user data first.

- **Category:** Errors
- **Pricing:** Free Developer plan: 1 user, 5,000 errors and 5M spans a month. Team starts at $26/month billed yearly, with unlimited users and 50,000 errors. Past the quota, events are dropped unless you set a pay-as-you-go budget. Sampling and noise filters stretch the quota.
- **Best for:** Any app where a user saying "it broke" needs to become a stack trace with the release, the route and the browser attached. Strongest for a small team with no on-call rota: Sentry groups, deduplicates and tells you which deploy introduced the regression.
- **Vendor docs:** https://docs.sentry.io/platforms/javascript/guides/nextjs/

## Trade-offs

- It is a data-protection decision, not just a tool choice. Errors carry request context by default, and Sentry 11's `dataCollection` defaults send cookies, request bodies and query strings. This battery turns those off and puts a scrubbing layer in front, but the responsibility stays yours.
- Noise is the failure mode. An unconfigured project fills up with browser extension errors, chunk-load 404s after every deploy and aborted fetches. The generated `ignoreErrors` list covers the usual suspects. New ones arrive with every browser release.
- Source maps need a build-time token with write access to your org. Keep it a Vercel build variable. Never put it in client code or the runtime environment.
- The SDK adds weight to the client bundle, more with Session Replay. Replay is off here because it records the DOM, and the DOM holds what your users typed.
- Tracing at a high sample rate gets expensive fast on a busy app, and spans are less actionable than errors. Start at 10% and lower it.

## Known fixes it ships

- [One issue with 40,000 events: grouping, fingerprints and the helper that ruined them](https://agenticboilerplate.com/cookbook/sentry/grouping-noisy-errors-with-fingerprints): Sentry groups by stack trace, so a shared fetch wrapper merges every unrelated failure into one useless issue. Fingerprints put the grouping back where the cause is.
- [Scrubbing PII before it leaves your process, not after it reaches Sentry](https://agenticboilerplate.com/cookbook/sentry/scrubbing-pii-before-it-leaves-the-process): Server-side scrubbing runs after the data has crossed the network. beforeSend runs in your process, and it is the only layer you fully control.
- [Source maps on Vercel: why your production stack traces are unreadable](https://agenticboilerplate.com/cookbook/sentry/source-maps-on-vercel): A minified trace means the build never uploaded source maps. The auth token, the release name and the preview environment are the three things that are usually wrong.
- [Telling a real incident from a bot, a browser extension or a stale tab](https://agenticboilerplate.com/cookbook/sentry/telling-a-real-incident-from-a-bot): Most of a new project's error feed is not your bug. The four signatures of noise, how to filter each one at the right layer, and the three signals that mean it is real.
- [Trace sample rates that do not bankrupt you](https://agenticboilerplate.com/cookbook/sentry/trace-sample-rates-that-do-not-bankrupt-you): Errors are cheap and spans are not. How to pick tracesSampleRate, why the edge runtime needs a lower one, and how to keep the traces you actually need while dropping 95% of the rest.

## Generate it

[Build a repo with Sentry](https://agenticboilerplate.com/build?b=sentry)

---

Agentic Boilerplate: A Next.js repo your agent already knows. Free during launch, then $99 once.

- Site map for agents: https://agenticboilerplate.com/llms.txt
- Public API: https://agenticboilerplate.com/openapi.json
- Contact: agenticstudio@gmail.com
