Error tracking
Next.js error tracking
@telemetry-tracker/next wraps the core SDK for App Router apps. Call init() in instrumentation-client.ts and uncaught browser errors and unhandled promise rejections are reported from the first render. Errors that your error.tsx or global-error.tsx catches are not uncaught: Next.js only logs them to the console in production, so each of those files needs one trackError call. Optionally, createOnRequestError captures server-side App Router errors.
This is the hosted path: ingest at https://api.telemetry-tracker.com. The full Next.js docs cover the same APIs if you point ingestUrl at a self-hosted API instead.
What the integration does
init()starts the SDK once, ideally ininstrumentation-client.ts(TelemetryProvideris the fallback for Next.js versions before 15.3).- Browser uncaught errors and unhandled rejections are sent automatically.
trackErrorinerror.tsxandglobal-error.tsxreports the render errors those files catch;TelemetryErrorBoundarydoes the same for parts of the tree you wrap yourself.useTrackPage(pathname)sends a screen event on each route change.trackError,trackEvent,screen, andidentifyare re-exported from the same package.- Optional
createOnRequestErrorininstrumentation.tscaptures uncaught App Router server errors (Next.js 15+), matching /docs/nextjs.
Real-user Web Vitals in the same SDK
Browser apps collect LCP, INP, CLS and TTFB by default after SDK initialization, where supported by the browser. Next.js uses @telemetry-tracker/next; React uses@telemetry-tracker/core. No extra package or separate Web Vitals setup is needed. This gives small teams error tracking with Web Vitals from real visits in one dashboard.
Open Performance for p75 values, ratings and trends, plus the Slow pages table with LCP and CLS by page path. Overview includes a Web Vitals snapshot. Set webVitals: false in the init() (or TelemetryProvider) config to turn capture off. Each reported metric is an event and counts as one ingest unit toward your plan limit. These are browser measurements, not native React Native or Node.js server metrics.
See the Web Vitals configuration and limitations. For a broader Next.js monitoring overview covering Web Vitals, releases, alerts and more in one place, see Next.js monitoring.
Install
pnpm add @telemetry-tracker/next
# or
npm install @telemetry-tracker/nextMinimal setup (Next.js 15.3+)
Initialize the SDK in instrumentation-client.ts at the project root (or in src/). Next.js runs this file after the HTML loads and before React hydrates, so the SDK is ready for a crash on the very first render, and it is not part of the React tree, so it keeps running when an error screen replaces your root layout. Set the hosted ingest URL (https://api.telemetry-tracker.com), app name, and NEXT_PUBLIC_TELEMETRY_API_KEY from Settings → API keys.
# .env.local
# Create a project key under Settings → API keys (shown once).
NEXT_PUBLIC_TELEMETRY_INGEST_URL=https://api.telemetry-tracker.com
NEXT_PUBLIC_TELEMETRY_API_KEY=tt_live_<publicId>_<secret>
NEXT_PUBLIC_TELEMETRY_APP=my-next-app// instrumentation-client.ts (project root or src/, Next.js 15.3+)
// Runs before hydration, so the SDK is ready for errors on the first render
// and keeps running when an error screen replaces the root layout.
import { init } from "@telemetry-tracker/next";
init({
ingestUrl:
process.env.NEXT_PUBLIC_TELEMETRY_INGEST_URL ?? "https://api.telemetry-tracker.com",
app: process.env.NEXT_PUBLIC_TELEMETRY_APP ?? "my-next-app",
apiKey: process.env.NEXT_PUBLIC_TELEMETRY_API_KEY,
// Must match the release used for the source-map upload (e.g. the commit SHA).
release: process.env.NEXT_PUBLIC_TELEMETRY_RELEASE,
});For page views, add a small client component that calls useTrackPage with usePathname(). Import init from @telemetry-tracker/next (not core) so useTrackPage sees the initialized SDK.
// app/layout.tsx — no provider needed when init() runs in instrumentation-client.ts
import { TrackPageView } from "./track-page-view";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<TrackPageView />
{children}
</body>
</html>
);
}// app/track-page-view.tsx
"use client";
import { usePathname } from "next/navigation";
import { useTrackPage } from "@telemetry-tracker/next";
export function TrackPageView() {
const pathname = usePathname();
useTrackPage(pathname);
return null;
}Next.js 14 to 15.2: there is no instrumentation-client.ts, so use TelemetryProvider in the root layout as in the Next.js docs and wrap children in TelemetryErrorBoundary inside it. Do not combine the provider with instrumentation-client.ts init. Known limitation in @telemetry-tracker/next 1.3.3: the provider shuts the SDK down when it unmounts, so a crash that replaces the root layout with global-error.tsx or the built-in error screen, or a crash during hydration, is not reported with provider-only init.
// app/layout.tsx
import { TelemetryProvider } from "@telemetry-tracker/next";
import { TrackPageView } from "./track-page-view";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<TelemetryProvider
config={{
ingestUrl:
process.env.NEXT_PUBLIC_TELEMETRY_INGEST_URL ??
"https://api.telemetry-tracker.com",
app: process.env.NEXT_PUBLIC_TELEMETRY_APP ?? "my-next-app",
apiKey: process.env.NEXT_PUBLIC_TELEMETRY_API_KEY,
// Must match the release used for the source-map upload (e.g. the commit SHA).
release: process.env.NEXT_PUBLIC_TELEMETRY_RELEASE,
}}
>
<TrackPageView />
{children}
</TelemetryProvider>
</body>
</html>
);
}Which Next.js errors are reported
A Next.js app fails in the browser and on the server, and not every failure reaches the same handler. With init() in instrumentation-client.ts:
| Error | How it is reported |
|---|---|
Client render error caught by your error.tsx | Not automatic. Next.js only calls console.error in production; call trackError in error.tsx |
Client render error caught by your global-error.tsx | Not automatic. Call trackError in global-error.tsx |
| Render or hydration crash with no error file of yours (built-in error screen) | Automatic. Next.js passes it to reportError and the SDK’s window.onerror handler reports it |
| Throw in an event handler or timeout | Automatic through window.onerror (error boundaries do not catch these) |
| Rejected promise nobody handles | Automatic through unhandledrejection |
| Server Components, Route Handlers, Server Actions | createOnRequestError in instrumentation.ts (Next.js 15+); the browser only gets a digest |
| Error you catch yourself (try/catch, failed fetch) | Call trackError(error, context) in the catch block |
We checked these paths on a Next.js 16.4 production build with @telemetry-tracker/next 1.3.3. Next.js 15.5 handles caught errors the same way.
Report errors caught by error.tsx and global-error.tsx
error.tsx wraps a route segment in a React error boundary and shows your fallback instead of a blank page. In production, Next.js then treats the error as handled and only logs it with console.error, so no global handler sees it. Report it from a useEffect in the file. If error.digest is set, the error happened on the server and onRequestError has already sent the real message and stack, so record a server_error_shown event instead of a second, stackless error. The Server Components render error guide explains the digest in detail.
// app/error.tsx (or any route segment's error.tsx)
"use client";
import { useEffect } from "react";
import { trackError, trackEvent } from "@telemetry-tracker/next";
export default function Error({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
if (error.digest) {
// Server error: onRequestError (instrumentation.ts) already sent the real
// message and stack. Record that a user saw it.
trackEvent("server_error_shown", { digest: error.digest, path: window.location.pathname });
} else {
// Browser render error: Next.js only logs it to the console in production.
trackError(error, { boundary: "app/error.tsx" });
}
}, [error]);
return (
<div>
<h2>Something went wrong.</h2>
{error.digest && <p>Reference: {error.digest}</p>}
<button onClick={() => reset()}>Try again</button>
</div>
);
}global-error.tsx catches errors in the root layout and anything no closer error.tsx handles. It replaces the root layout, so it renders its own <html> and <body>. With init() in instrumentation-client.ts the SDK is still running when it renders.
// app/global-error.tsx — replaces the root layout, so it renders <html> and <body>
"use client";
import { useEffect } from "react";
import { trackError, trackEvent } from "@telemetry-tracker/next";
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
useEffect(() => {
if (error.digest) {
trackEvent("server_error_shown", { digest: error.digest, path: window.location.pathname });
} else {
trackError(error, { boundary: "app/global-error.tsx" });
}
}, [error]);
return (
<html lang="en">
<body>
<h2>Something went wrong.</h2>
{error.digest && <p>Reference: {error.digest}</p>}
</body>
</html>
);
}The SDK ignores a second report of the same Error object, so an error that also reaches window.onerror is sent once. Next.js 16 also passes retry; the samples keep reset so they typecheck on Next.js 15.
Verify your first error
Not required for production. Temporarily call trackError(new Error("docs-check")) from a client button, then open Issues. Delete the verification helper afterward.
// app/docs-check-button.tsx (optional — delete after verifying ingest)
"use client";
import { trackError } from "@telemetry-tracker/next";
export function DocsCheckButton() {
return (
<button
type="button"
onClick={() => {
trackError(new Error("docs-check"), { page: "/" });
}}
>
Send docs-check error
</button>
);
}import { trackError } from "@telemetry-tracker/next";
trackError(new Error("docs-check"), { page: "/" });To report render errors in one part of a page without an error.tsx, wrap it in TelemetryErrorBoundary:
import { TelemetryErrorBoundary } from "@telemetry-tracker/next";
<TelemetryErrorBoundary fallback={<div>Something went wrong</div>}>
<YourComponent />
</TelemetryErrorBoundary>Server-side error tracking with Next.js App Router
Skip this section for browser-only setup. The browser SDK does not capture uncaught errors in Server Components, Route Handlers, or Server Actions. Add instrumentation.ts with createOnRequestError from @telemetry-tracker/next/server and the server-only variables below. That hook requires Next.js 15+. Use TELEMETRY_API_KEY — do not expose a server-only secret via NEXT_PUBLIC_*. Seeing An error occurred in the Server Components render
? Find the real error behind the digest. Limits of the hook are on the Next.js docs. Replacing @sentry/nextjs is covered in Migrate from Sentry.
# Optional — only if you add instrumentation.ts for App Router server errors
TELEMETRY_INGEST_URL=https://api.telemetry-tracker.com
TELEMETRY_API_KEY=tt_live_<publicId>_<secret>
TELEMETRY_APP=my-next-app// instrumentation.ts
import { createOnRequestError } from "@telemetry-tracker/next/server";
export const onRequestError = createOnRequestError({
ingestUrl: process.env.TELEMETRY_INGEST_URL ?? "https://api.telemetry-tracker.com",
apiKey: process.env.TELEMETRY_API_KEY,
app: process.env.TELEMETRY_APP ?? "my-next-app",
environment: process.env.NODE_ENV,
});Source maps
Set productionBrowserSourceMaps: true, keep the SDK release in sync with your upload, and follow Source maps (same guidance as /docs/nextjs). Grouping still uses the minified stack; maps improve the frames you read in Issues.
What you will see
Open Issues in the dashboard. Matching stack traces are grouped into one issue with occurrences, release, and context. Optional spike alerts live under Alerts.
The free hosted plan is €0 with no credit card: 250K ingest units per month, 14-day retention, one project. See pricing.
FAQ
Does Telemetry Tracker catch Next.js render errors automatically?
Only the ones no error file of yours catches. Next.js passes those to the browser's reportError, and the SDK's window.onerror handler reports them as long as the SDK is still running, which is why init() belongs in instrumentation-client.ts. Errors that your error.tsx or global-error.tsx catches are only logged to the console in production builds, so call trackError there.
Why initialize in instrumentation-client.ts instead of TelemetryProvider?
instrumentation-client.ts runs before hydration and is not part of the React tree. In @telemetry-tracker/next 1.3.3 TelemetryProvider shuts the SDK down when it unmounts, and it unmounts when global-error.tsx or Next.js's built-in error screen replaces the root layout, so those crashes are dropped. A crash during hydration happens before the provider initializes at all.
Will a server error be reported twice, by onRequestError and by error.tsx?
Not with the snippets on this page. A server error reaches the browser with a digest and no real message, and onRequestError has already sent the original error. The error.tsx snippet records a server_error_shown event with the digest instead of a second error.
Are errors in event handlers and promises reported?
Yes, if nothing catches them. Error boundaries, including error.tsx, do not catch errors in onClick handlers, timeouts or promises, so they reach window.onerror or the unhandledrejection handler. If you catch an error yourself, call trackError in the catch block.
Does this work on Next.js 14 or 15.0–15.2?
The browser SDK does. instrumentation-client.ts needs Next.js 15.3 and onRequestError needs Next.js 15, so on older versions use TelemetryProvider, wrap the app in TelemetryErrorBoundary inside it, and call trackError in your error.tsx files.
Full documentation
Custom events, identify, and more setup notes: Next.js SDK docs. Hosted account steps: Hosted cloud.
Start tracking errors for free
No credit card. Create a project, install the SDK, and the first error shows up in Issues.
Related
- React error tracking@telemetry-tracker/core for SPAs and Vite apps.
- Node.js error trackingUncaught exceptions on the server.
- Next.js docsProvider, error boundary, verify step, and server capture.
- Source mapsReadable stacks for Next.js webpack and Turbopack builds.
- Migrate from SentryReplace @sentry/nextjs with this SDK.
- Sentry alternativeWhen Telemetry Tracker is a better fit.