跳到主内容
智客 ZICQ

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

Sentry Python Sdk

Python的SDK全监视装置 用于被请求"添加哨兵到Python","安装哨兵-sdk","设置哨兵到Python",或者配置错误监测,追踪,剖析,记录,度量衡,克仑或用于Python应用的AI监测. 支持Django,Flask,FastAPI,Celery,Starlette,AIOHTTP,"旋风"等.

354 安装量

官方网址:skills.sh

技能介绍

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

做什么

Python 的全部 SDK 监视器设置

何时用

请求添加 Sentry 到 Python , “ 安装 sentry- sdk ”, “ 设置 Sentry in Python ”, 或配置错误监测, 跟踪, 剖析, 日志, 度量衡, crons, 或 Python 应用程序的 AI 监视 。 支持Django、Flask、FastAPI、Celery、Starlette、AIOHTTP、旋风等

代理如何加载

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

文件分析

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

官方 description(原文)

Full Sentry SDK setup for Python. Use when asked to "add Sentry to Python", "install sentry-sdk", "setup Sentry in Python", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for Python applications. Supports Django, Flask, FastAPI, Celery, Starlette, AIOHTTP, Tornado, and more.

Sentry Python SDKInvoke This Skill WhenPhase 1: DetectCheck existing SentryDetect web frameworkDetect task queuesDetect logging librariesDetect AI librariesDetect schedulers / cronsCheck for companion frontendPhase 2: RecommendPhase 3: Guide

· 许可:Apache-2.0

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
sentry-python-sdk
description
Full Sentry SDK setup for Python. Use when asked to "add Sentry to Python", "install sentry-sdk", "setup Sentry in Python", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for Python applications. Supports Django, Flask, FastAPI, Celery, Starlette, AIOHTTP, Tornado, and more.
许可
Apache-2.0
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 7
  • references/error-monitoring.md
  • references/tracing.md
  • references/profiling.md
  • references/logging.md
  • references/metrics.md
  • references/crons.md
  • references/ai-monitoring.md

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

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

安装这个技能

Skills CLI ↗

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

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

交给 Agent 安装

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

把 Agent Skill「sentry-python-sdk」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-aff4e0aa48156c84-%E5%93%A8%E5%85%B5%E9%87%91%E5%AD%97%E5%A1%94-%E7%BC%A9%E5%86%99.html
请存为 .cursor/skills/sentry-python-sdk/SKILL.md 或 .claude/skills/sentry-python-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-python-sdk'

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

阅读排版
--- name: sentry-python-sdk description: Full Sentry SDK setup for Python. Use when asked to "add Sentry to Python", "install sentry-sdk", "setup Sentry in Python", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for Python applications. Supports Django, Flask, FastAPI, Celery, Starlette, AIOHTTP, Tornado, and more. license: Apache-2.0 --- # Sentry Python SDK Opinionated wizard that scans your Python project and guides you through complete Sentry setup. ## Invoke This Skill When - User asks to "add Sentry to Python" or "setup Sentry" in a Python app - User wants error monitoring, tracing, profiling, logging, metrics, or crons in Python - User mentions `sentry-sdk`, `sentry_sdk`, or Sentry + any Python framework - User wants to monitor Django views, Flask routes, FastAPI endpoints, Celery tasks, or scheduled jobs > **Note:** SDK versions and APIs below reflect Sentry docs at time of writing (sentry-sdk 2.x). > Always verify against [docs.sentry.io/platforms/python/](https://docs.sentry.io/platforms/python/) before implementing. --- ## Phase 1: Detect Run these commands to understand the project before making recommendations: ```bash # Check existing Sentry grep -i sentry requirements.txt pyproject.toml setup.cfg setup.py 2>/dev/null # Detect web framework grep -rE "django|flask|fastapi|starlette|aiohttp|tornado|quart|falcon|sanic|bottle" \ requirements.txt pyproject.toml 2>/dev/null # Detect task queues grep -rE "celery|rq|huey|arq|dramatiq" requirements.txt pyproject.toml 2>/dev/null # Detect logging libraries grep -E "loguru" requirements.txt pyproject.toml 2>/dev/null # Detect AI libraries grep -rE "openai|anthropic|langchain|huggingface|google-genai|pydantic-ai|litellm" \ requirements.txt pyproject.toml 2>/dev/null # Detect schedulers / crons grep -rE "celery|apscheduler|schedule|crontab" requirements.txt pyproject.toml 2>/dev/null # Check for companion frontend ls frontend/ web/ client/ ui/ static/ templates/ 2>/dev/null ``` **What to note:** - Is `sentry-sdk` already in requirements? If yes, check if `sentry_sdk.init()` is present — may just need feature config. - Which framework? (Determines where to place `sentry_sdk.init()`.) - Which task queue? (Celery needs dual-process init; RQ needs a settings file.) - AI libraries? (OpenAI, Anthropic, LangChain are auto-instrumented.) - Companion frontend? (Triggers Phase 4 cross-link.) --- ## Phase 2: Recommend Based on what you found, present a concrete proposal. Don't ask open-ended questions — lead with a recommendation: **Always recommended (core coverage):** - ✅ **Error Monitoring** — captures unhandled exceptions, supports `ExceptionGroup` (Python 3.11+) - ✅ **Logging** — Python `logging` stdlib auto-captured; enhanced if Loguru detected **Recommend when detected:** - ✅ **Tracing** — HTTP framework detected (Django/Flask/FastAPI/etc.) - ✅ **AI Monitoring** — OpenAI/Anthropic/LangChain/etc. detected (auto-instrumented, zero config) - ⚡ **Profiling** — production apps where performance matters - ⚡ **Crons** — Celery Beat, APScheduler, or cron patterns detected - ⚡ **Metrics** — business KPIs, SLO tracking **Recommendation matrix:** | Feature | Recommend when... | Reference | |---------|------------------|-----------| | Error Monitoring | **Always** — non-negotiable baseline | `${SKILL_ROOT}/references/error-monitoring.md` | | Tracing | Django/Flask/FastAPI/AIOHTTP/etc. detected | `${SKILL_ROOT}/references/tracing.md` | | Profiling | Production + performance-sensitive workload | `${SKILL_ROOT}/references/profiling.md` | | Logging | Always (stdlib); enhanced for Loguru | `${SKILL_ROOT}/references/logging.md` | | Metrics | Business events or SLO tracking needed | `${SKILL_ROOT}/references/metrics.md` | | Crons | Celery Beat, APScheduler, or cron patterns | `${SKILL_ROOT}/references/crons.md` | | AI Monitoring | OpenAI/Anthropic/LangChain/etc. detected | `${SKILL_ROOT}/references/ai-monitoring.md` | Propose: *"I recommend Error Monitoring + Tracing [+ Logging if applicable]. Want Profiling, Crons, or AI Monitoring too?"* --- ## Phase 3: Guide ### Install ```bash # Core SDK (always required) pip install sentry-sdk # Optional extras (install only what matches detected framework): pip install "sentry-sdk[django]" pip install "sentry-sdk[flask]" pip install "sentry-sdk[fastapi]" pip install "sentry-sdk[celery]" pip install "sentry-sdk[aiohttp]" pip install "sentry-sdk[tornado]" # Multiple extras: pip install "sentry-sdk[django,celery]" ``` > Extras are optional — plain `sentry-sdk` works for all frameworks. Extras install complementary packages. ### Quick Start — Recommended Init Full init enabling the most features with sensible defaults. Place **before** any app/framework code: ```python import sentry_sdk sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], environment=os.environ.get("SENTRY_ENVIRONMENT", "production"), release=os.environ.get("SENTRY_RELEASE"), # e.g. "[email protected]" send_default_pii=True, # Tracing (lower to 0.1–0.2 in high-traffic production) traces_sample_rate=1.0, # Profiling — continuous, tied to active spans profile_session_sample_rate=1.0, profile_lifecycle="trace", # Structured logs (SDK ≥ 2.35.0) enable_logs=True, ) ``` ### Where to Initialize Per Framework | Framework | Where to call `sentry_sdk.init()` | Notes | |-----------|-----------------------------------|-------| | **Django** | Top of `settings.py`, before any imports | No middleware needed — Sentry patches Django internally | | **Flask** | Before `app = Flask(__name__)` | Must precede app creation | | **FastAPI** | Before `app = FastAPI()` | `StarletteIntegration` + `FastApiIntegration` auto-enabled together | | **Starlette** | Before `app = Starlette(...)` | Same auto-integration as FastAPI | | **AIOHTTP** | Module level, before `web.Application()` | | | **Tornado** | Module level, before app setup | No integration class needed | | **Quart** | Before `app = Quart(__name__)` | | | **Falcon** | Module level, before `app = falcon.App()` | | | **Sanic** | Inside `@app.listener("before_server_start")` | Sanic's lifecycle requires async init | | **Celery** | `@signals.celeryd_init.connect` in worker AND in calling process | Dual-process init required | | **RQ** | `mysettings.py` loaded by worker via `rq worker -c mysettings` | | | **ARQ** | Both worker module and enqueuing process | | **Django example** (`settings.py`): ```python import sentry_sdk sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], send_default_pii=True, traces_sample_rate=1.0, profile_session_sample_rate=1.0, profile_lifecycle="trace", enable_logs=True, ) # rest of Django settings... INSTALLED_APPS = [...] ``` **FastAPI example** (`main.py`): ```python import sentry_sdk sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], send_default_pii=True, traces_sample_rate=1.0, profile_session_sample_rate=1.0, profile_lifecycle="trace", enable_logs=True, ) from fastapi import FastAPI app = FastAPI() ``` ### Auto-Enabled vs Explicit Integrations Most integrations activate automatically when their package is installed — no `integrations=[...]` needed: | Auto-enabled | Explicit required | |-------------|-------------------| | Django, Flask, FastAPI, Starlette, AIOHTTP, Tornado, Quart, Falcon, Sanic, Bottle | `DramatiqIntegration` | | Celery, RQ, Huey, ARQ | `GRPCIntegration` | | SQLAlchemy, Redis, asyncpg, pymongo | `StrawberryIntegration` | | Requests, HTTPX, aiohttp-client | `AsyncioIntegration` | | OpenAI, Anthropic, LangChain, Pydantic AI, MCP | `OpenTelemetryIntegration` | | Python `logging`, Loguru | `WSGIIntegration` / `ASGIIntegration` | ### For Each Agreed Feature Walk through features one at a time. Load the reference, follow its steps, verify before moving on: | Feature | Reference file | Load when... | |---------|---------------|-------------| | Error Monitoring | `${SKILL_ROOT}/references/error-monitoring.md` | Always (baseline) | | Tracing | `${SKILL_ROOT}/references/tracing.md` | HTTP handlers / distributed tracing | | Profiling | `${SKILL_ROOT}/references/profiling.md` | Performance-sensitive production | | Logging | `${SKILL_ROOT}/references/logging.md` | Always; enhanced for Loguru | | Metrics | `${SKILL_ROOT}/references/metrics.md` | Business KPIs / SLO tracking | | Crons | `${SKILL_ROOT}/references/crons.md` | Scheduler / cron patterns detected | | AI Monitoring | `${SKILL_ROOT}/references/ai-monitoring.md` | AI library detected | For each feature: `Read ${SKILL_ROOT}/references/.md`, follow steps exactly, verify it works. --- ## Configuration Reference ### Key `sentry_sdk.init()` Options | Option | Type | Default | Purpose | |--------|------|---------|---------| | `dsn` | `str` | `None` | SDK disabled if empty; env: `SENTRY_DSN` | | `environment` | `str` | `"production"` | e.g., `"staging"`; env: `SENTRY_ENVIRONMENT` | | `release` | `str` | `None` | e.g., `"[email protected]"`; env: `SENTRY_RELEASE` | | `send_default_pii` | `bool` | `False` | Include IP, headers, cookies, auth user | | `traces_sample_rate` | `float` | `None` | Transaction sample rate; `None` disables tracing | | `traces_sampler` | `Callable` | `None` | Custom per-transaction sampling (overrides rate) | | `profile_session_sample_rate` | `float` | `None` | Continuous profiling session rate | | `profile_lifecycle` | `str` | `"manual"` | `"trace"` = auto-start profiler with spans | | `profiles_sample_rate` | `float` | `None` | Transaction-based profiling rate | | `enable_logs` | `bool` | `False` | Send logs to Sentry (SDK ≥ 2.35.0) | | `sample_rate` | `float` | `1.0` | Error event sample rate | | `attach_stacktrace` | `bool` | `False` | Stack traces on `capture_message()` | | `max_breadcrumbs` | `int` | `100` | Max breadcrumbs per event | | `debug` | `bool` | `False` | Verbose SDK debug output | | `before_send` | `Callable` | `None` | Hook to mutate/drop error events | | `before_send_transaction` | `Callable` | `None` | Hook to mutate/drop transaction events | | `ignore_errors` | `list` | `[]` | Exception types or regex patterns to suppress | | `auto_enabling_integrations` | `bool` | `True` | Set `False` to disable all auto-detection | ### Environment Variables | Variable | Maps to | Notes | |----------|---------|-------| | `SENTRY_DSN` | `dsn` | | | `SENTRY_RELEASE` | `release` | Also auto-detected from git SHA, Heroku, CircleCI, CodeBuild, GAE | | `SENTRY_ENVIRONMENT` | `environment` | | | `SENTRY_DEBUG` | `debug` | | --- ## Verification Test that Sentry is receiving events: ```python # Trigger a real error event — check dashboard within seconds division_by_zero = 1 / 0 ``` Or for a non-crashing check: ```python sentry_sdk.capture_message("Sentry Python SDK test") ``` If nothing appears: 1. Set `debug=True` in `sentry_sdk.init()` — prints SDK internals to stdout 2. Verify the DSN is correct 3. Check `SENTRY_DSN` env var is set in the running process 4. For Celery/RQ: ensure init runs in the **worker** process, not just the calling process --- ## Phase 4: Cross-Link After completing Python setup, check for a companion frontend missing Sentry: ```bash ls frontend/ web/ client/ ui/ 2>/dev/null cat frontend/package.json web/package.json client/package.json 2>/dev/null \ | grep -E '"react"|"svelte"|"vue"|"next"|"nuxt"' ``` If a frontend exists without Sentry, suggest the matching skill: | Frontend detected | Suggest skill | |-------------------|--------------| | React / Next.js | `sentry-react-sdk` | | Svelte / SvelteKit | `sentry-svelte-sdk` | | Vue / Nuxt | Use `@sentry/vue` — see [docs.sentry.io/platforms/javascript/guides/vue/](https://docs.sentry.io/platforms/javascript/guides/vue/) | | Other JS/TS | `sentry-react-sdk` (covers generic browser JS patterns) | --- ## Troubleshooting | Issue | Solution | |-------|----------| | Events not appearing | Set `debug=True`, verify DSN, check env vars in the running process | | Malformed DSN error | Format: `https://@o.ingest.sentry.io/` | | Django exceptions not captured | Ensure `sentry_sdk.init()` is at the **top** of `settings.py` before other imports | | Flask exceptions not captured | Init must happen **before** `app = Flask(__name__)` | | FastAPI exceptions not captured | Init before `app = FastAPI()`; both `StarletteIntegration` and `FastApiIntegration` auto-enabled | | Celery task errors not captured | Must call `sentry_sdk.init()` in the **worker process** via `celeryd_init` signal | | Sanic init not working | Init must be inside `@app.listener("before_server_start")`, not module level | | uWSGI not capturing | Add `--enable-threads --py-call-uwsgi-fork-hooks` to uWSGI command | | No traces appearing | Verify `traces_sample_rate` is set (not `None`); check that the integration is auto-enabled | | Profiling not starting | Requires `traces_sample_rate > 0` + either `profile_session_sample_rate` or `profiles_sample_rate` | | `enable_logs` not working | Requires SDK ≥ 2.35.0; for direct structured logs use `sentry_sdk.logger`; for stdlib bridging use `LoggingIntegration(sentry_logs_level=...)` | | Too many transactions | Lower `traces_sample_rate` or use `traces_sampler` to drop health checks | | Cross-request data leaking | Don't use `get_global_scope()` for per-request data — use `get_isolation_scope()` | | RQ worker not reporting | Pass `--sentry-dsn=""` to disable RQ's own Sentry shortcut; init via settings file instead |

相关技能

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)完成一个功…