
Sentry React Sdk
Wire Sentry into a React app so uncaught errors, promise rejections, and render failures are captured in production without ad-hoc logging.
Overview
Sentry React SDK is an agent skill for the Operate phase that explains how @sentry/react automatically and manually captures browser and React errors in production.
Install
npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-react-sdkWhat is this skill?
- Documents automatic capture via GlobalHandlers, BrowserApiErrors, and React ErrorBoundary vs reactErrorHandler for React
- Spells out minimum SDK versions: @sentry/react ≥8.0.0, captureReactException ≥9.8.0, reactErrorHandler ≥8.6.0
- Tables five capture layers from window.onerror through optional CaptureConsole
- Lists what still needs manual captureMessage/captureException: try/catch, router boundaries, and swallowed async chains
- Notes optional customization for disabling or tailoring default integrations
- 5 automatic capture layers tabulated
- 3 minimum SDK version gates documented
Adoption & trust: 1.6k installs on skills.sh; 197 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You shipped a React app but crashes inside try/catch, routers, or async chains never show up in your error dashboard.
Who is it for?
Indie builders adding or fixing Sentry in a React 18/19 SPA who need a clear map of default auto-capture vs manual instrumentation.
Skip if: Teams that only need backend Node/Python Sentry setup with no browser React surface, or apps that already have audited, complete Sentry wiring.
When should I use this skill?
Integrating or debugging @sentry/react capture in a shipped or shipping React application.
What do I get? / Deliverables
After following the skill, your agent can place ErrorBoundary or reactErrorHandler correctly and add manual capture where global handlers cannot see failures.
- Sentry init and boundary placement plan
- List of manual capture points for swallowed errors
Recommended Skills
Journey fit
Error monitoring belongs on the Operate shelf because it matters after you ship, when real users hit edge cases in the browser. The errors subphase is the canonical home for exception capture, boundaries, and SDK instrumentation—not launch SEO or pre-ship unit tests.
How it compares
Use this procedural SDK guide instead of guessing which errors Sentry catches by default in a generic chat answer.
Common Questions / FAQ
Who is sentry-react-sdk for?
Solo and indie builders shipping React frontends who want their coding agent to configure Sentry capture layers, version gates, and manual exception points accurately.
When should I use sentry-react-sdk?
Use it in Operate when triaging missing events in Sentry, during Ship security and launch prep to turn monitoring on before release, or in Build frontend work when you first add @sentry/react to the repo.
Is sentry-react-sdk safe to install?
Review the Security Audits panel on this Prism page for install risk and license signals; the skill describes instrumentation only and does not run Sentry on its own.
SKILL.md
READMESKILL.md - Sentry React Sdk
# Error Monitoring — Sentry React SDK > Minimum SDK: `@sentry/react` ≥8.0.0+ > `captureReactException()` requires `@sentry/react` ≥9.8.0 > `reactErrorHandler()` requires `@sentry/react` ≥8.6.0 --- ## How Automatic Capture Works The React SDK hooks into the browser environment and captures errors automatically from multiple layers: | Layer | Mechanism | Integration | |-------|-----------|-------------| | Uncaught JS exceptions | `window.onerror` | `GlobalHandlers` (default on) | | Unhandled promise rejections | `window.onunhandledrejection` | `GlobalHandlers` (default on) | | Errors in `setTimeout` / `setInterval` / `requestAnimationFrame` | Patched browser APIs | `BrowserApiErrors` (default on) | | React render errors (React <19) | `componentDidCatch` via `<ErrorBoundary>` | `Sentry.ErrorBoundary` | | React render errors (React 19+) | `createRoot` hooks | `Sentry.reactErrorHandler()` | | Console errors (optional) | Patched `console.error` | `CaptureConsole` (opt-in) | ### What Requires Manual Instrumentation The global handlers only catch errors that **escape** your code. These are silently swallowed without manual calls: - Errors caught by your own `try/catch` blocks - Errors swallowed by React Router's default error boundary - Business-logic failures (validation errors, unexpected states) - Async errors inside `Promise.then()` chains where `.catch()` is attached - User-visible conditions that aren't exceptions (use `captureMessage`) ### Disabling or Customizing Automatic Capture ```javascript Sentry.init({ integrations: [ Sentry.globalHandlersIntegration({ onerror: true, onunhandledrejection: false, // handle rejections manually }), ], }); // Manual rejection handler: window.addEventListener("unhandledrejection", (event) => { Sentry.captureException(event.reason); }); ``` --- ## React Error Boundaries ### Strategy: React 19+ vs. React ≤18 | | React ≤18 | React 19+ | |---|---|---| | **Global error reporting** | `window.onerror` + `Sentry.ErrorBoundary` | `Sentry.reactErrorHandler()` on `createRoot` | | **Scoped fallback UI** | `<Sentry.ErrorBoundary>` | `<Sentry.ErrorBoundary>` (still required) | | **Complementary?** | N/A | ✅ Use both together | --- ### React 19+ — `Sentry.reactErrorHandler()` with `createRoot` React 19 exposes three hooks on `createRoot` and `hydrateRoot`. Pass `Sentry.reactErrorHandler()` to each one. Requires `@sentry/react` ≥8.6.0. ```jsx // src/main.tsx import { createRoot } from "react-dom/client"; import * as Sentry from "@sentry/react"; Sentry.init({ dsn: "___PUBLIC_DSN___" }); const container = document.getElementById("app")!; createRoot(container, { // Fires for errors that bubble up WITHOUT any ErrorBoundary catching them. // These are fatal — the entire React tree unmounts. onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => { // Optional: runs AFTER Sentry has already captured the error console.warn("Uncaught React error:", error.message); console.warn("Component stack:", errorInfo.componentStack); }), // Fires for errors caught BY an ErrorBoundary (React 19 re-routes caught errors here). // The boundary still renders its fallback UI — this is just the reporting hook. onCaughtError: Sentry.reactErrorHandler(), // Fires when React recovers from an error automatically (e.g. hydration mismatch). onRecoverableError: Sentry.reactErrorHandler(), }).render(<App />); ``` **SSR / `hydrateRoot`:** ```jsx import { hydrateRoot } from "react-dom/client"; import * as Sentry from "@sentry/react"; hydrateRoot(document.getElementById("app")!, <App />, { onUncaughtError: Sentry.reactErrorHandler(), onCaughtError: Sentry.reactErrorHandler(), onRecoverableError: Sentry.reactErrorHandler(), }); ``` **Key behavior differences between the three hooks:** | Hook | Fires when... | Tree state after | |------|--------------|-----------------| | `onUncaughtError` | Error escapes all boundaries | Tree unmounts (fatal)