Skip to main content
Use @squasher-ai/nextjs for errors on the server and @squasher-ai/browser for errors and Web Vitals in the browser. This page is tested with both packages at version 0.4.0 on Next.js 15.5 with the App Router.

What the SDK captures

Install the SDKs

Add your ingest key and project ID to .env.local. The browser needs its own copies with the NEXT_PUBLIC_ prefix.
.env.local
To get both values, see Create an ingest key.

Initialize the SDK on the server

Create instrumentation.ts in your project root, or in src/ if you use a src folder. Load the SDK only when NEXT_RUNTIME is nodejs. Without this check, an app with Edge code does not build.
instrumentation.ts
resourceAttributes is optional. Set service.name when one project gets data from more than one service. On Next.js 14, also turn on experimental.instrumentationHook in next.config.js.

Capture route handler errors

Wrap each route handler in squasherApiHandler. When the handler throws, the wrapper sends the error with the request URL and method, then throws it again, so Next.js still returns its error response.
app/api/checkout/route.ts

Capture middleware errors

Wrap the middleware in withSquasher, and run it on the Node.js runtime (Next.js 15.5 and later). Middleware on the Edge runtime is not captured.
middleware.ts

Capture Server Component errors

Squasher does not capture errors in Server Components and Server Actions on its own. Catch the error, call captureError, and throw it again:
app/orders/page.tsx
The second argument is optional. It adds your own fields to the event.

Capture browser errors and Web Vitals

Use @squasher-ai/browser in client code. Do not use @squasher-ai/nextjs/client: it does not build in a client bundle today.
1

Create a client provider

app/squasher-provider.tsx
2

Add the provider to the root layout

app/layout.tsx
The browser SDK captures uncaught errors and unhandled promise rejections. SquasherErrorBoundary captures React render errors and shows the fallback. SquasherNextWebVitals sends LCP, CLS, INP, FCP, and TTFB, each with the current pathname. Session replay is on by default. To turn it off, add replay: { enabled: false } to init. See the Browser SDK for all options.

Read stack traces

Server stack traces point at the compiled files in .next/server, and browser stack traces are minified. Upload source maps for each release, and the issue page shows the original files, lines, and functions.

Give the setup to a coding agent

Copy this prompt into your coding agent to install the SDK the same way:

Next steps

Browser SDK

Set sampling, session replay, and privacy options.

Upload source maps

Store source maps for each release.

Vercel log drain

Send Vercel logs and traces to the same project.

Read AI triage

Learn what the triage summary tells you.