Practical walkthrough
Error tracking in a Next.js app: what actually gets captured
Next.js apps break in two places — the browser and the server — and most 'Next.js error tracking' pages blur the difference. This one doesn't. Here's how Faultline capture works in a Next.js app today: what the snippet catches, what the error boundary adds, and precisely where the coverage stops on the server side.
The browser side: the snippet
Faultline's capture is one small, dependency-free script. After you sign up, the onboarding screen shows it pre-filled with your personal ingest key. In a Next.js App Router app, the clean place for it is the root layout, loaded with next/script:
// app/layout.tsx — add the snippet Faultline gives you on the
// onboarding screen (it's pre-filled with your ingest key).
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Script id="faultline" strategy="afterInteractive">
{/* the pre-filled snippet from your onboarding page */}
</Script>
</body>
</html>
);
}Once loaded, it hooks two browser events:
- —
window.onerror— uncaught exceptions in client components, event handlers, and plain scripts. - —
unhandledrejection— promises that reject with no.catch(), the most common silent failure in data-fetching code.
Each report carries the message, stack trace, and current route, and lands in the same grouped issue list as everything else. It also exposes window.faultline.captureError(err) for errors you catch yourself but still want reported.
Render errors: the boundary and error.tsx
An error thrown while a component renders doesn't reach window.onerror the same way — React unwinds the tree instead. Two mechanisms cover it:
The Faultline error boundary
A copy-paste FaultlineErrorBoundary component ships with the product. Wrap any part of your client tree with it and render errors inside get reported through the snippet and replaced with your fallback UI.
Next.js error.tsx
App Router's own convention works too. error.tsx is a client component that receives the thrown error as a prop — forward it in an effect and it joins the same issue list:
// app/error.tsx — Next.js renders this when a route segment throws.
// It's a client component, so it can forward the error to Faultline.
"use client";
import { useEffect } from "react";
export default function Error({ error, reset }) {
useEffect(() => {
window.faultline?.captureError(error);
}, [error]);
return (
<div>
<p>Something went wrong.</p>
<button onClick={() => reset()}>Try again</button>
</div>
);
}The honest limit: the server side
There is no Faultline server SDK, and this page won't pretend otherwise. Errors thrown inside Server Components, Server Actions, and route handlers run in Node, where window doesn't exist — the browser snippet can't see them, and nothing captures them automatically today.
What you can do today is report them manually: the ingest endpoint accepts a plain JSON POST from anywhere, so a try/catch in a route handler can forward the failure in a few lines:
// Anywhere you can make an HTTP request — a route handler's
// catch block, a server action, a cron job:
await fetch("https://YOUR-APP/api/ingest/YOUR-INGEST-KEY", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: err.message,
stack: err.stack,
route: "/api/checkout",
source: "server-manual",
}),
});Manual, yes — but the payload is identical, so server reports group into issues right alongside browser ones. If your app is client-heavy (most dashboards, tools, and marketing-driven SaaS apps are), the snippet plus boundary covers the large majority of what your users can hit. If your app is mostly server logic, weigh that limit honestly — the Sentry comparison lays out when a full platform is the better buy.
The two-minute version
- 1. Sign up and generate your ingest key on the onboarding screen.
- 2. Add the pre-filled snippet to your root layout, wrap risky subtrees in the error boundary.
- 3. Click “send a test error” in onboarding and watch the grouped issue appear — then resolve it. Loop proven before a real user ever breaks anything.
New to the whole idea? Start with error tracking for indie hackers — what to track, why grouping matters, and what a good alert looks like when the team is you.
Try the loop on your own app — free tier, no card, set up in under two minutes.