$npx -y skills add getsentry/sentry-for-ai --skill sentry-python-sdkFull 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, Celer
| 1 | > [All Skills](../../SKILL_TREE.md) > [SDK Setup](../sentry-sdk-setup/SKILL.md) > Python SDK |
| 2 | |
| 3 | # Sentry Python SDK |
| 4 | |
| 5 | Opinionated wizard that scans your Python project and guides you through complete Sentry setup. |
| 6 | |
| 7 | ## Invoke This Skill When |
| 8 | |
| 9 | - User asks to "add Sentry to Python" or "setup Sentry" in a Python app |
| 10 | - User wants error monitoring, tracing, profiling, logging, metrics, or crons in Python |
| 11 | - User mentions `sentry-sdk`, `sentry_sdk`, or Sentry + any Python framework |
| 12 | - User wants to monitor Django views, Flask routes, FastAPI endpoints, Celery tasks, or scheduled jobs |
| 13 | |
| 14 | > **Note:** SDK versions and APIs below reflect Sentry docs at time of writing (sentry-sdk 2.x). |
| 15 | > Always verify against [docs.sentry.io/platforms/python/](https://docs.sentry.io/platforms/python/) before implementing. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Phase 1: Detect |
| 20 | |
| 21 | Run these commands to understand the project before making recommendations: |
| 22 | |
| 23 | ```bash |
| 24 | # Check existing Sentry |
| 25 | grep -i sentry requirements.txt pyproject.toml setup.cfg setup.py 2>/dev/null |
| 26 | |
| 27 | # Detect web framework |
| 28 | grep -rE "django|flask|fastapi|starlette|aiohttp|tornado|quart|falcon|sanic|bottle|pyramid" \ |
| 29 | requirements.txt pyproject.toml 2>/dev/null |
| 30 | |
| 31 | # Detect task queues |
| 32 | grep -rE "celery|rq|huey|arq|dramatiq" requirements.txt pyproject.toml 2>/dev/null |
| 33 | |
| 34 | # Detect logging libraries |
| 35 | grep -E "loguru" requirements.txt pyproject.toml 2>/dev/null |
| 36 | |
| 37 | # Detect AI libraries |
| 38 | grep -rE "openai|anthropic|langchain|huggingface|google-genai|pydantic-ai|litellm" \ |
| 39 | requirements.txt pyproject.toml 2>/dev/null |
| 40 | |
| 41 | # Detect schedulers / crons |
| 42 | grep -rE "celery|apscheduler|schedule|crontab" requirements.txt pyproject.toml 2>/dev/null |
| 43 | |
| 44 | # OpenTelemetry tracing — check for SDK + instrumentations |
| 45 | grep -rE "opentelemetry-sdk|opentelemetry-instrumentation|opentelemetry-distro" \ |
| 46 | requirements.txt pyproject.toml 2>/dev/null |
| 47 | grep -rn "TracerProvider\|trace\.get_tracer\|start_as_current_span" \ |
| 48 | --include="*.py" 2>/dev/null | head -5 |
| 49 | |
| 50 | # Check for companion frontend |
| 51 | ls frontend/ web/ client/ ui/ static/ templates/ 2>/dev/null |
| 52 | ``` |
| 53 | |
| 54 | **What to note:** |
| 55 | - Is `sentry-sdk` already in requirements? If yes, check if `sentry_sdk.init()` is present — may just need feature config. |
| 56 | - Which framework? (Determines where to place `sentry_sdk.init()`.) |
| 57 | - Which task queue? (Celery needs dual-process init; RQ needs a settings file.) |
| 58 | - AI libraries? (OpenAI, Anthropic, LangChain are auto-instrumented.) |
| 59 | - OpenTelemetry tracing? (Use OTLP path instead of native tracing.) |
| 60 | - Companion frontend? (Triggers Phase 4 cross-link.) |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## Phase 2: Recommend |
| 65 | |
| 66 | Based on what you found, present a concrete proposal. Don't ask open-ended questions — lead with a recommendation: |
| 67 | |
| 68 | **Route from OTel detection:** |
| 69 | - **OTel tracing detected** (`opentelemetry-sdk` / `opentelemetry-distro` in requirements, or `TracerProvider` in source) → use OTLP path: `OTLPIntegration()`; do **not** set `traces_sample_rate`; Sentry links errors to OTel traces automatically |
| 70 | |
| 71 | **Always recommended (core coverage):** |
| 72 | - ✅ **Error Monitoring** — captures unhandled exceptions, supports `ExceptionGroup` (Python 3.11+) |
| 73 | - ✅ **Logging** — Python `logging` stdlib auto-captured; enhanced if Loguru detected |
| 74 | |
| 75 | **Recommend when detected:** |
| 76 | - ✅ **Tracing** — HTTP framework detected (Django/Flask/FastAPI/etc.) |
| 77 | - ✅ **AI Monitoring** — OpenAI/Anthropic/LangChain/etc. detected (auto-instrumented, zero config) |
| 78 | - ⚡ **Profiling** — production apps where performance matters; **not available with OTLP path** |
| 79 | - ⚡ **Crons** — Celery Beat, APScheduler, or cron patterns detected |
| 80 | - ⚡ **Metrics** — business KPIs, SLO tracking |
| 81 | |
| 82 | **Recommendation matrix:** |
| 83 | |
| 84 | | Feature | Recommend when... | Reference | |
| 85 | |---------|------------------|-----------| |
| 86 | | Error Monitoring | **Always** — non-negotiable baseline | `${SKILL_ROOT}/references/error-monitoring.md` | |
| 87 | | OTLP Integration | OTel tracing detected — **replaces** native Tracing | `${SKILL_ROOT}/references/tracing.md` | |
| 88 | | Tracing | Django/Flask/FastAPI/AIOHTTP/etc. detected; **skip if OTel tracing detected** | `${SKILL_ROOT}/references/tracing.md` | |
| 89 | | Profiling | Production + performance-sensitive workload; **skip if OTel tracing detected** (requires `traces_sample_rate`, incompatible with OTLP) | `${SKILL_ROOT}/references/profiling.md` | |
| 90 | | Logging | Always (stdlib); enhanced for Loguru | `${SKILL_ROOT}/references/logging.md` | |
| 91 | | Metrics | Business events or SLO tracking needed | `${SKILL_ROOT}/references/metrics.md` | |
| 92 | | Crons | Celery Beat, APScheduler, or cron patterns | `${SKILL_ROOT}/references/crons.md` | |
| 93 | | AI Monitoring | |