跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 sentry-react-sdk

Sentry React Sdk

全面哨兵SDK设置回放. 被请求用于“ 添加哨兵重播”、“ 安装 @ 哨兵/ 重播” , 或配置错误监测、 跟踪、 会话重播、 剖析或记录重播应用程序 。 支持React 16+,React Router v5-v7,TanStack路由器,Redux,Vite,以及网络包装.

535 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

React 的全部 SDK 监视器设置

何时用

请求添加 Sentry 到 React , “ 安装 @ sentry/ react ”, 或配置错误监测、 跟踪、 会话重放、 剖析或记录 react 应用程序 。 支持 React 16+, React router v5-v7, TanStack 路由器, Redux, Vite, 和网络包

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Sentry React SDK、Invoke This Skill When、Phase 1: Detect、Detect React version、Check for existing Sentry、Detect router。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/error-monitoring.md、references/tracing.md、references/session-replay.md、references/logging.md、references/profiling.md、references/react-features.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Full Sentry SDK setup for React. Use when asked to "add Sentry to React", "install @sentry/react", or configure error monitoring, tracing, session replay, profiling, or logging for React applications. Supports React 16+, React Router v5-v7, TanStack Router, Redux, Vite, and webpack.

Sentry React SDKInvoke This Skill WhenPhase 1: DetectDetect React versionCheck for existing SentryDetect routerDetect state managementDetect build toolDetect logging librariesCheck for companion backend in adjacent directoriesPhase 2: RecommendPhase 3: Guide

· 许可:Apache-2.0

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
sentry-react-sdk
description
Full Sentry SDK setup for React. Use when asked to "add Sentry to React", "install @sentry/react", or configure error monitoring, tracing, session replay, profiling, or logging for React applications. Supports React 16+, React Router v5-v7, TanStack Router, Redux, Vite, and webpack.
许可
Apache-2.0
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 6
  • references/error-monitoring.md
  • references/tracing.md
  • references/session-replay.md
  • references/logging.md
  • references/profiling.md
  • references/react-features.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「sentry-react-sdk」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-cef3c9f074bd5f62-%E5%93%A8%E5%85%B5%E9%87%8D%E7%8E%B0-Sdk.html
请存为 .cursor/skills/sentry-react-sdk/SKILL.md 或 .claude/skills/sentry-react-sdk/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/getsentry/sentry-agent-skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/getsentry/sentry-agent-skills' --list

npx skills add 'https://github.com/getsentry/sentry-agent-skills' --skill 'sentry-react-sdk'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: sentry-react-sdk description: Full Sentry SDK setup for React. Use when asked to "add Sentry to React", "install @sentry/react", or configure error monitoring, tracing, session replay, profiling, or logging for React applications. Supports React 16+, React Router v5-v7, TanStack Router, Redux, Vite, and webpack. license: Apache-2.0 --- # Sentry React SDK Opinionated wizard that scans your React project and guides you through complete Sentry setup. ## Invoke This Skill When - User asks to "add Sentry to React" or "set up Sentry" in a React app - User wants error monitoring, tracing, session replay, profiling, or logging in React - User mentions `@sentry/react`, React Sentry SDK, or Sentry error boundaries - User wants to monitor React Router navigation, Redux state, or component performance > **Note:** SDK versions and APIs below reflect current Sentry docs at time of writing (`@sentry/react` ≥8.0.0). > Always verify against [docs.sentry.io/platforms/javascript/guides/react/](https://docs.sentry.io/platforms/javascript/guides/react/) before implementing. --- ## Phase 1: Detect Run these commands to understand the project before making any recommendations: ```bash # Detect React version cat package.json | grep -E '"react"|"react-dom"' # Check for existing Sentry cat package.json | grep '"@sentry/' # Detect router cat package.json | grep -E '"react-router-dom"|"@tanstack/react-router"' # Detect state management cat package.json | grep -E '"redux"|"@reduxjs/toolkit"' # Detect build tool ls vite.config.ts vite.config.js webpack.config.js craco.config.js 2>/dev/null cat package.json | grep -E '"vite"|"react-scripts"|"webpack"' # Detect logging libraries cat package.json | grep -E '"pino"|"winston"|"loglevel"' # Check for companion backend in adjacent directories ls ../backend ../server ../api 2>/dev/null cat ../go.mod ../requirements.txt ../Gemfile ../pom.xml 2>/dev/null | head -3 ``` **What to determine:** | Question | Impact | |----------|--------| | React 19+? | Use `reactErrorHandler()` hook pattern | | React <19? | Use `Sentry.ErrorBoundary` | | `@sentry/react` already present? | Skip install, go straight to feature config | | `react-router-dom` v5 / v6 / v7? | Determines which router integration to use | | `@tanstack/react-router`? | Use `tanstackRouterBrowserTracingIntegration()` | | Redux in use? | Recommend `createReduxEnhancer()` | | Vite detected? | Source maps via `sentryVitePlugin` | | CRA (`react-scripts`)? | Source maps via `@sentry/webpack-plugin` in CRACO | | Backend directory found? | Trigger Phase 4 cross-link suggestion | --- ## Phase 2: Recommend Present a concrete recommendation based on what you found. Don't ask open-ended questions — lead with a proposal: **Recommended (core coverage):** - ✅ **Error Monitoring** — always; captures unhandled errors, React error boundaries, React 19 hooks - ✅ **Tracing** — React SPAs benefit from page load, navigation, and API call tracing - ✅ **Session Replay** — recommended for user-facing apps; records sessions around errors **Optional (enhanced observability):** - ⚡ **Logging** — structured logs via `Sentry.logger.*`; recommend when structured log search is needed - ⚡ **Profiling** — JS Self-Profiling API (⚠️ experimental; requires cross-origin isolation headers) **Recommendation logic:** | Feature | Recommend when... | |---------|------------------| | Error Monitoring | **Always** — non-negotiable baseline | | Tracing | **Always for React SPAs** — page load + navigation spans are high-value | | Session Replay | User-facing app, login flows, or checkout pages | | Logging | App needs structured log search or log-to-trace correlation | | Profiling | Performance-critical app; server sends `Document-Policy: js-profiling` header | **React-specific extras:** - React 19 detected → set up `reactErrorHandler()` on `createRoot` - React Router detected → configure matching router integration (see Phase 3) - Redux detected → add `createReduxEnhancer()` to Redux store - Vite detected → configure `sentryVitePlugin` for source maps (essential for readable stack traces) Propose: *"I recommend setting up Error Monitoring + Tracing + Session Replay. Want me to also add Logging or Profiling?"* --- ## Phase 3: Guide ### Install ```bash npm install @sentry/react --save ``` ### Create `src/instrument.ts` Sentry must initialize **before any other code runs**. Put `Sentry.init()` in a dedicated sidecar file: ```typescript import * as Sentry from "@sentry/react"; Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN, // Adjust per build tool (see table below) environment: import.meta.env.MODE, release: import.meta.env.VITE_APP_VERSION, // inject at build time sendDefaultPii: true, integrations: [ Sentry.browserTracingIntegration(), Sentry.replayIntegration({ maskAllText: true, blockAllMedia: true, }), ], // Tracing tracesSampleRate: 1.0, // lower to 0.1–0.2 in production tracePropagationTargets: ["localhost", /^https:\/\/yourapi\.io/], // Session Replay replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0, enableLogs: true, }); ``` **DSN environment variable by build tool:** | Build Tool | Variable Name | Access in code | |------------|--------------|----------------| | Vite | `VITE_SENTRY_DSN` | `import.meta.env.VITE_SENTRY_DSN` | | Create React App | `REACT_APP_SENTRY_DSN` | `process.env.REACT_APP_SENTRY_DSN` | | Custom webpack | `SENTRY_DSN` | `process.env.SENTRY_DSN` | ### Entry Point Setup Import `instrument.ts` as the **very first import** in your entry file: ```tsx // src/main.tsx (Vite) or src/index.tsx (CRA/webpack) import "./instrument"; // ← MUST be first import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App"; createRoot(document.getElementById("root")!).render( ); ``` ### React Version-Specific Error Handling **React 19+** — use `reactErrorHandler()` on `createRoot`: ```tsx import { reactErrorHandler } from "@sentry/react"; createRoot(document.getElementById("root")!, { onUncaughtError: reactErrorHandler(), onCaughtError: reactErrorHandler(), onRecoverableError: reactErrorHandler(), }).render(); ``` **React <19** — wrap your app in `Sentry.ErrorBoundary`: ```tsx import * as Sentry from "@sentry/react"; createRoot(document.getElementById("root")!).render( Something went wrong

} showDialog> ); ``` Use `` for any sub-tree that should catch errors independently (route sections, widgets, etc.). ### Router Integration Configure the matching integration for your router: | Router | Integration | Notes | |--------|------------|-------| | React Router v7 | `reactRouterV7BrowserTracingIntegration` | `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren`, `matchRoutes` from `react-router` | | React Router v6 | `reactRouterV6BrowserTracingIntegration` | `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren`, `matchRoutes` from `react-router-dom` | | React Router v5 | `reactRouterV5BrowserTracingIntegration` | Wrap routes in `withSentryRouting(Route)` | | TanStack Router | `tanstackRouterBrowserTracingIntegration(router)` | Pass router instance — no hooks required | | No router / custom | `browserTracingIntegration()` | Names transactions by URL path | **React Router v6/v7 setup:** ```typescript // in instrument.ts integrations array: import React from "react"; import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType, } from "react-router-dom"; // or "react-router" for v7 import * as Sentry from "@sentry/react"; import { reactRouterV6BrowserTracingIntegration } from "@sentry/react"; import { createBrowserRouter } from "react-router-dom"; // Option A — createBrowserRouter (recommended for v6.4+): const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV6(createBrowserRouter); const router = sentryCreateBrowserRouter([...routes]); // Option B — createBrowserRouter for React Router v7: // const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV7(createBrowserRouter); // Option C — integration with hooks (v6 without data APIs): Sentry.init({ integrations: [ reactRouterV6BrowserTracingIntegration({ useEffect: React.useEffect, useLocation, useNavigationType, matchRoutes, createRoutesFromChildren, }), ], }); ``` **TanStack Router setup:** ```typescript import { tanstackRouterBrowserTracingIntegration } from "@sentry/react"; // Pass your TanStack router instance: Sentry.init({ integrations: [tanstackRouterBrowserTracingIntegration(router)], }); ``` ### Redux Integration (when detected) ```typescript import * as Sentry from "@sentry/react"; import { configureStore } from "@reduxjs/toolkit"; const store = configureStore({ reducer: rootReducer, enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(Sentry.createReduxEnhancer()), }); ``` ### Source Maps Setup (strongly recommended) Without source maps, stack traces show minified code. Set up the build plugin to upload source maps automatically: **Vite (`vite.config.ts`):** ```typescript import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { sentryVitePlugin } from "@sentry/vite-plugin"; export default defineConfig({ build: { sourcemap: "hidden" }, plugins: [ react(), sentryVitePlugin({ org: process.env.SENTRY_ORG, project: process.env.SENTRY_PROJECT, authToken: process.env.SENTRY_AUTH_TOKEN, }), ], }); ``` Add to `.env` (never commit): ```bash SENTRY_AUTH_TOKEN=sntrys_... SENTRY_ORG=my-org-slug SENTRY_PROJECT=my-project-slug ``` **Create React App (via CRACO):** ```bash npm install @craco/craco @sentry/webpack-plugin --save-dev ``` ```javascript // craco.config.js const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); module.exports = { webpack: { plugins: { add: [ sentryWebpackPlugin({ org: process.env.SENTRY_ORG, project: process.env.SENTRY_PROJECT, authToken: process.env.SENTRY_AUTH_TOKEN, }), ], }, }, }; ``` ### For Each Agreed Feature Walk through features one at a time. Load the reference file, follow its steps, verify before moving on: | Feature | Reference | Load when... | |---------|-----------|-------------| | Error Monitoring | `${SKILL_ROOT}/references/error-monitoring.md` | Always (baseline) | | Tracing | `${SKILL_ROOT}/references/tracing.md` | SPA navigation / API call tracing | | Session Replay | `${SKILL_ROOT}/references/session-replay.md` | User-facing app | | Logging | `${SKILL_ROOT}/references/logging.md` | Structured log search / log-to-trace | | Profiling | `${SKILL_ROOT}/references/profiling.md` | Performance-critical app | | React Features | `${SKILL_ROOT}/references/react-features.md` | Redux, component tracking, source maps, integrations catalog | For each feature: `Read ${SKILL_ROOT}/references/.md`, follow steps exactly, verify it works. --- ## Configuration Reference ### Key `Sentry.init()` Options | Option | Type | Default | Notes | |--------|------|---------|-------| | `dsn` | `string` | — | **Required.** SDK disabled when empty | | `environment` | `string` | `"production"` | e.g., `"staging"`, `"development"` | | `release` | `string` | — | e.g., `"[email protected]"` or git SHA — links errors to releases | | `sendDefaultPii` | `boolean` | `false` | Includes IP addresses and request headers | | `tracesSampleRate` | `number` | — | 0–1; `1.0` in dev, `0.1–0.2` in prod | | `tracesSampler` | `function` | — | Per-transaction sampling; overrides rate | | `tracePropagationTargets` | `(string\|RegExp)[]` | — | Outgoing URLs that receive distributed tracing headers | | `replaysSessionSampleRate` | `number` | — | Fraction of all sessions recorded | | `replaysOnErrorSampleRate` | `number` | — | Fraction of error sessions recorded | | `enableLogs` | `boolean` | `false` | Enable `Sentry.logger.*` API | | `attachStacktrace` | `boolean` | `false` | Stack traces on `captureMessage()` calls | | `maxBreadcrumbs` | `number` | `100` | Breadcrumbs stored per event | | `debug` | `boolean` | `false` | Verbose SDK output to console | | `tunnel` | `string` | — | Proxy URL to bypass ad blockers | ### React Compatibility Matrix | React Version | Error handling approach | SDK minimum | |---------------|------------------------|-------------| | React 19+ | `reactErrorHandler()` on `createRoot` | `@sentry/react` ≥8.0.0 | | React 16–18 | `Sentry.ErrorBoundary` component | `@sentry/react` ≥7.0.0 | | React 16 | `componentDidCatch` class boundaries | `@sentry/react` ≥6.0.0 | --- ## Verification Trigger test events to confirm Sentry is receiving data: ```tsx // Add a temporary test button anywhere in your app import * as Sentry from "@sentry/react"; function SentryTest() { return ( <> { throw new Error("Sentry React test error"); }}> Test Error Sentry.captureMessage("Sentry test message", "info")}> Test Message ); } ``` Check the Sentry dashboard: - **Issues** → error appears within seconds - **Traces** → page load and navigation transactions visible - **Replays** → session recording visible after page interaction - **Logs** → structured log entries if logging enabled Set `debug: true` in `Sentry.init()` and check the browser console if nothing appears. --- ## Phase 4: Cross-Link After completing React setup, check for a companion backend missing Sentry coverage: ```bash ls ../backend ../server ../api ../go ../python 2>/dev/null cat ../go.mod 2>/dev/null | head -3 cat ../requirements.txt ../pyproject.toml 2>/dev/null | head -3 cat ../Gemfile 2>/dev/null | head -3 cat ../pom.xml 2>/dev/null | grep '' | head -3 ``` If a backend exists without Sentry configured, suggest the matching skill: | Backend detected | Suggest skill | |-----------------|--------------| | Go (`go.mod`) | `sentry-go-sdk` | | Python (`requirements.txt`, `pyproject.toml`) | `sentry-python-sdk` | | Ruby (`Gemfile`) | `sentry-ruby-sdk` | | Java (`pom.xml`, `build.gradle`) | Use `@sentry/java` — see [docs.sentry.io/platforms/java/](https://docs.sentry.io/platforms/java/) | | Node.js (Express, Fastify) | Use `@sentry/node` — see [docs.sentry.io/platforms/javascript/guides/express/](https://docs.sentry.io/platforms/javascript/guides/express/) | --- ## Troubleshooting | Issue | Solution | |-------|----------| | Events not appearing | Set `debug: true`, check DSN, open browser console for SDK errors | | Source maps not working | Build in production mode (`npm run build`); verify `SENTRY_AUTH_TOKEN` is set | | Minified stack traces | Source maps not uploading — check plugin config and auth token | | `instrument.ts` not running first | Verify it's the first import in entry file before React/app imports | | React 19 errors not captured | Confirm `reactErrorHandler()` is passed to all three `createRoot` options | | React <19 errors not captured | Ensure `` wraps the component tree | | Router transactions named `` | Add router integration matching your router version | | `tracePropagationTargets` not matching | Check regex escaping; default is `localhost` and your DSN origin only | | Session replay not recording | Confirm `replayIntegration()` is in init; check `replaysSessionSampleRate` | | Redux actions not in breadcrumbs | Add `Sentry.createReduxEnhancer()` to store enhancers | | Ad blockers dropping events | Set `tunnel: "/sentry-tunnel"` and add server-side relay endpoint | | High replay storage costs | Lower `replaysSessionSampleRate`; keep `replaysOnErrorSampleRate: 1.0` | | Profiling not working | Verify `Document-Policy: js-profiling` header is set on document responses |

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…