React error tracking
React error tracking, including what your error boundaries catch
Error boundaries keep your UI alive but swallow the error. ErrorLens records every render error — caught or not — with the component stack, the user's clicks and readable source.
Initialize before rendering
npm install @errorlenshq/browserimport * as ErrorLens from "@errorlenshq/browser";
import { createRoot } from "react-dom/client";
ErrorLens.init({ dsn: "https://<key>@errorlens.io/<project-id>", tracesSampleRate: 0.1 });
createRoot(document.getElementById("root")!, {
// errors caught by your error boundaries
onCaughtError: (error, info) =>
ErrorLens.withScope((scope) => {
scope.setContext("react", { componentStack: info.componentStack });
ErrorLens.captureException(error);
}),
}).render(<App />);React 18: report from your error boundary
class ErrorBoundary extends React.Component {
state = { failed: false };
static getDerivedStateFromError() { return { failed: true }; }
componentDidCatch(error, info) {
ErrorLens.withScope((scope) => {
scope.setContext("react", { componentStack: info.componentStack });
ErrorLens.captureException(error);
});
}
render() { return this.state.failed ? <p>Something went wrong.</p> : this.props.children; }
}Also captured
- Uncaught render errors and errors in event handlers and effects
- Clicks, route changes and API calls as breadcrumbs
- A transaction per route change in single-page apps
- Original source lines once you upload source maps
Frequently asked questions
Does it work with React Router?
Yes. Route changes through the History API are recorded as navigation breadcrumbs and, with tracing on, as navigation transactions.
What about React Native?
This SDK is for browsers. React Native apps can use any SDK that speaks the standard error-envelope protocol.
Keep reading
JavaScript error tracking for real users' browsers
Track JavaScript errors in the browser with breadcrumbs, source maps, page-load timing and web vitals. 12 KB gzipped, works with any frontend. Open source.
Next.js error tracking on the server and in the browser
Track Next.js errors on the server and in the browser: route handlers, server components and client errors in one trace. Setup with instrumentation.ts.
Releases and source maps
Open-source APM that links slow requests to their errors and logs
Open-source application performance monitoring: p50/p95 latency, throughput, failure rate and distributed traces linked to errors and logs. Self-host free.
Start tracking errors in minutes
Free hosted plan with 5,000 errors a month, or self-host with no limits. No credit card.