sentry-react-setup
getsentry/sentry-agent-skills
Install and configure Sentry error monitoring, session replay, and tracing in React applications.
What is sentry-react-setup?
Sentry React Setup installs @sentry/react and configures error monitoring, error boundaries, session replay, and browser tracing for React apps. Use this when adding error tracking, performance monitoring, or crash reporting to a React project.
- Install @sentry/react package and initialize Sentry with DSN
- Configure error boundaries (React <19) or error hooks (React 19+) to catch unhandled errors
- Enable session replay to record user interactions before errors occur
- Set up browser tracing and performance monitoring with configurable sample rates
- Integrate with React Router (v4–v7) and Redux for enhanced error context
- Upload source maps for readable stack traces in error reports
How to install sentry-react-setup
npx skills add https://github.com/getsentry/sentry-agent-skills --skill sentry-react-setup- React project (any version)
- Sentry account and DSN (Data Source Name) from sentry.io
- npm or yarn package manager
How to use sentry-react-setup
- 1.Run `npm install @sentry/react --save` to install the Sentry package
- 2.Create `instrument.js` in your project root with Sentry.init() and your DSN
- 3.Import `instrument.js` as the first import in your app entry point (src/index.js or src/main.jsx)
- 4.For React 19+, add error handlers to createRoot; for React <19, wrap components with Sentry.ErrorBoundary
- 5.(Optional) Add router integration by including the appropriate `Sentry.reactRouterVxBrowserTracingIntegration()` for your React Router version
- 6.(Optional) Run `npx @sentry/wizard@latest -i sourcemaps` to upload source maps for readable stack traces
- 7.Test the setup by adding a button that throws an error and verify it appears in your Sentry dashboard
Use cases
- Add error monitoring to a new or existing React application to track production crashes
- Configure session replay to debug user-reported issues by replaying their session
- Set up performance tracing to identify slow page loads or API calls in React apps
- Integrate Sentry with React Router to track navigation and route-specific errors
- Enable Redux integration to capture application state in error reports
- React developers building production applications
- Teams needing real-time error monitoring and crash reporting
- Developers debugging user-reported issues with session replay
- Performance engineers optimizing React app load times and interactions
sentry-react-setup FAQ
React 19+ uses error hooks (onUncaughtError, onCaughtError, onRecoverableError) passed to createRoot, while React <19 requires wrapping components with the Sentry.ErrorBoundary component.
Source maps are optional but recommended for production. They make stack traces readable by mapping minified code back to original source. Use `npx @sentry/wizard@latest -i sourcemaps` to set them up.
Add your DSN directly in the Sentry.init() call in instrument.js, or set it via the SENTRY_DSN environment variable (REACT_APP_SENTRY_DSN for Create React App, VITE_SENTRY_DSN for Vite).
SENTRY_DSN is used by the browser SDK to send errors to Sentry. SENTRY_AUTH_TOKEN is used by sentry-cli for uploading source maps and is not read by the browser SDK.
Yes. Add `Sentry.createReduxEnhancer()` to your Redux store enhancers to capture application state in error reports.
Full instructions (SKILL.md)
Source of truth, from getsentry/sentry-agent-skills.
name: sentry-react-setup description: Setup Sentry in React apps. Use when asked to add Sentry to React, install @sentry/react, or configure error monitoring, error boundaries, session replay, or browser tracing for React applications. license: Apache-2.0
Sentry React Setup
Install and configure Sentry in React projects.
Invoke This Skill When
- User asks to "add Sentry to React" or "install Sentry" in a React app
- User wants error monitoring, logging, or tracing in React
- User mentions "@sentry/react" or React error boundaries
Important: The configuration options and code samples below are examples. Always verify against docs.sentry.io before implementing, as APIs and defaults may have changed.
Install
npm install @sentry/react --save
Configure
Create instrument.js in your project root (must be imported first in your app):
import * as Sentry from "@sentry/react";
Sentry.init({
dsn: "YOUR_SENTRY_DSN",
sendDefaultPii: true,
// Tracing + Session Replay
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration(),
],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//, /^https:\/\/yourserver\.io\/api/],
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
// Logs
enableLogs: true,
});
Import First in Entry Point
// src/index.js or src/main.jsx
import "./instrument"; // Must be first!
import App from "./App";
import { createRoot } from "react-dom/client";
const root = createRoot(document.getElementById("app"));
root.render(<App />);
Error Handling
React 19+
Use error hooks with createRoot:
import { createRoot } from "react-dom/client";
import * as Sentry from "@sentry/react";
const root = createRoot(document.getElementById("app"), {
onUncaughtError: Sentry.reactErrorHandler(),
onCaughtError: Sentry.reactErrorHandler(),
onRecoverableError: Sentry.reactErrorHandler(),
});
React <19
Use ErrorBoundary component:
import * as Sentry from "@sentry/react";
<Sentry.ErrorBoundary fallback={<p>An error occurred</p>}>
<MyComponent />
</Sentry.ErrorBoundary>
Router Integration
| Router | Integration |
|---|---|
| React Router v7 | Sentry.reactRouterV7BrowserTracingIntegration |
| React Router v6 | Sentry.reactRouterV6BrowserTracingIntegration |
| React Router v4/v5 | Sentry.reactRouterV5BrowserTracingIntegration (shared for both) |
| TanStack Router | See TanStack Router docs |
Redux Integration (Optional)
import * as Sentry from "@sentry/react";
import { configureStore } from "@reduxjs/toolkit";
const store = configureStore({
reducer,
enhancers: (getDefaultEnhancers) =>
getDefaultEnhancers().concat(Sentry.createReduxEnhancer()),
});
Source Maps
Upload source maps for readable stack traces:
npx @sentry/wizard@latest -i sourcemaps
Environment Variables
SENTRY_DSN=https://xxx@o123.ingest.sentry.io/456
SENTRY_AUTH_TOKEN=sntrys_xxx # Used by sentry-cli / source maps, not the SDK
SENTRY_ORG=my-org # Used by sentry-cli, not the SDK
SENTRY_PROJECT=my-project # Used by sentry-cli, not the SDK
Note: The SDK reads SENTRY_DSN automatically. If using Create React App, prefix with REACT_APP_; for Vite, use VITE_. SENTRY_AUTH_TOKEN/ORG/PROJECT are used by sentry-cli for source map uploads, not by the browser SDK.
Verification
Add test button to trigger error:
<button onClick={() => { throw new Error("Sentry Test Error"); }}>
Test Sentry
</button>
Troubleshooting
| Issue | Solution |
|---|---|
| Errors not captured | Ensure instrument.js is imported first |
| Source maps not working | Run sourcemaps wizard, verify auth token |
| React Router spans missing | Add correct router integration for your version |
Related skills
More from getsentry/sentry-agent-skills and the wider catalog.

sentry-android-sdk
Full Sentry SDK setup for Android with error monitoring, tracing, profiling, and session replay.

sentry-browser-sdk
Full Sentry SDK setup for browser JavaScript with error monitoring, tracing, and session replay.

sentry-cloudflare-sdk
Complete Sentry error monitoring, tracing, and logging setup for Cloudflare Workers, Pages, and Durable Objects.

sentry-cocoa-sdk
Full Sentry SDK setup for Apple platforms (iOS, macOS, tvOS, watchOS, visionOS).

sentry-code-review
Analyze and fix Sentry-identified issues in GitHub Pull Request comments.

sentry-create-alert
Create Sentry alerts and workflow automations via the workflow engine API.