All Skills > SDK Setup > Python SDK
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/ before implementing.
Phase 1: Detect
Run these commands to understand the project before making recommendations:
# 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|pyramid" \
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
# OpenTelemetry tracing — check for SDK + instrumentations
grep -rE "opentelemetry-sdk|opentelemetry-instrumentation|opentelemetry-distro" \
requirements.txt pyproject.toml 2>/dev/null
grep -rn "TracerProvider\|trace\.get_tracer\|start_as_current_span" \
--include="*.py" 2>/dev/null | head -5
# 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.)
- OpenTelemetry tracing? (Use OTLP path instead of native tracing.)
- 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:
Route from OTel detection:
- 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
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; not available with OTLP path
- ⚡ 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 |
| OTLP Integration |
OTel tracing detected — replaces native Tracing |
${SKILL_ROOT}/references/tracing.md |
| Tracing |
Django/Flask/FastAPI/AIOHTTP/etc. detected; skip if OTel tracing detected |
${SKILL_ROOT}/references/tracing.md |
| Profiling |
Production + performance-sensitive workload; skip if OTel tracing detected (requires traces_sample_rate, incompatible with OTLP) |
${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 |
OTel tracing detected: "I see OpenTelemetry tracing in the project. I recommend Sentry's OTLP integration for tracing (via your existing OTel setup) + Error Monitoring + Sentry Logging [+ Metrics/Crons/AI Monitoring if applicable]. Shall I proceed?"
No OTel: "I recommend Error Monitoring + Tracing [+ Logging if applicable]. Want Profiling, Crons, or AI Monitoring too?"
Phase 3: Guide
Install
# 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:
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. "myapp@1.0.0"
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() |
|
| Pyramid |
Module level, before config = Configurator() |
WSGI framework |
| 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):
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):
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, Pyramid, Sanic, Bottle |
DramatiqIntegration |
| Celery, RQ, Huey, ARQ |
GRPCIntegration |
| SQLAlchemy, Redis, asyncpg, pymongo |
StrawberryIntegration |
| Requests, HTTPX, httpx2, 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/<feature>.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., "myapp@1.0.0"; env: SENTRY_RELEASE |
send_default_pii |
bool |
False |
Include IP, headers, cookies, auth user, query strings (ASGI frameworks) |
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 |
OTLPIntegration Options (pass to constructor)
| Option |
Type |
Default |
Purpose |
setup_otlp_traces_exporter |
bool |
True |
Auto-configure OTLP exporter; set False if you send to your own Collector |
collector_url |
str |
None |
OTLP HTTP endpoint of an OTel Collector (e.g., http://localhost:4318/v1/traces); when set, spans are sent to the collector instead of directly to Sentry |
setup_propagator |
bool |
True |
Auto-configure Sentry propagator for distributed tracing |
capture_exceptions |
bool |
False |
Intercept exceptions recorded via OTel Span.record_exception |
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:
# Trigger a real error event — check dashboard within seconds
division_by_zero = 1 / 0
Or for a non-crashing check:
sentry_sdk.capture_message("Sentry Python SDK test")
If nothing appears:
- Set
debug=True in sentry_sdk.init() — prints SDK internals to stdout
- Verify the DSN is correct
- Check
SENTRY_DSN env var is set in the running process
- 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:
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/ |
| 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://<key>@o<org>.ingest.sentry.io/<project> |
| 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 |
| ASGI chained exceptions suppressed |
By default, Sentry's ASGI middleware strips exception chains (raise exc from None). To preserve chained exceptions, set _experiments={"suppress_asgi_chained_exceptions": False} in sentry_sdk.init() |
| 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 (native) |
Verify traces_sample_rate is set (not None); check that the integration is auto-enabled |
| No traces appearing (OTLP) |
Verify sentry-sdk[opentelemetry-otlp] is installed; do not set traces_sample_rate when using OTLPIntegration |
| Profiling not starting |
Requires traces_sample_rate > 0 + either profile_session_sample_rate or profiles_sample_rate; not compatible with OTLP path |
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() |
| Query strings not captured (ASGI) |
Query strings and client IP in ASGI frameworks (FastAPI, Starlette, etc.) require send_default_pii=True |
| RQ worker not reporting |
Pass --sentry-dsn="" to disable RQ's own Sentry shortcut; init via settings file instead |
1---2name: sentry-python-sdk3description: 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.4license: Apache-2.05---6
7> [All Skills](../../SKILL_TREE.md) > [SDK Setup](../sentry-sdk-setup/SKILL.md) > Python SDK
8
9# Sentry Python SDK
10
11Opinionated wizard that scans your Python project and guides you through complete Sentry setup.
12
13## Invoke This Skill When
14
15- User asks to "add Sentry to Python" or "setup Sentry" in a Python app
16- User wants error monitoring, tracing, profiling, logging, metrics, or crons in Python
17- User mentions `sentry-sdk`, `sentry_sdk`, or Sentry + any Python framework
18- User wants to monitor Django views, Flask routes, FastAPI endpoints, Celery tasks, or scheduled jobs
19
20> **Note:** SDK versions and APIs below reflect Sentry docs at time of writing (sentry-sdk 2.x).
21> Always verify against [docs.sentry.io/platforms/python/](https://docs.sentry.io/platforms/python/) before implementing.
22
23---
24
25## Phase 1: Detect
26
27Run these commands to understand the project before making recommendations:
28
29```bash
30# Check existing Sentry
31grep -i sentry requirements.txt pyproject.toml setup.cfg setup.py 2>/dev/null
32
33# Detect web framework
34grep -rE "django|flask|fastapi|starlette|aiohttp|tornado|quart|falcon|sanic|bottle|pyramid" \
35 requirements.txt pyproject.toml 2>/dev/null
36
37# Detect task queues
38grep -rE "celery|rq|huey|arq|dramatiq" requirements.txt pyproject.toml 2>/dev/null
39
40# Detect logging libraries
41grep -E "loguru" requirements.txt pyproject.toml 2>/dev/null
42
43# Detect AI libraries
44grep -rE "openai|anthropic|langchain|huggingface|google-genai|pydantic-ai|litellm" \
45 requirements.txt pyproject.toml 2>/dev/null
46
47# Detect schedulers / crons
48grep -rE "celery|apscheduler|schedule|crontab" requirements.txt pyproject.toml 2>/dev/null
49
50# OpenTelemetry tracing — check for SDK + instrumentations
51grep -rE "opentelemetry-sdk|opentelemetry-instrumentation|opentelemetry-distro" \
52 requirements.txt pyproject.toml 2>/dev/null
53grep -rn "TracerProvider\|trace\.get_tracer\|start_as_current_span" \
54 --include="*.py" 2>/dev/null | head -5
55
56# Check for companion frontend
57ls frontend/ web/ client/ ui/ static/ templates/ 2>/dev/null
58```
59
60**What to note:**
61- Is `sentry-sdk` already in requirements? If yes, check if `sentry_sdk.init()` is present — may just need feature config.
62- Which framework? (Determines where to place `sentry_sdk.init()`.)
63- Which task queue? (Celery needs dual-process init; RQ needs a settings file.)
64- AI libraries? (OpenAI, Anthropic, LangChain are auto-instrumented.)
65- OpenTelemetry tracing? (Use OTLP path instead of native tracing.)
66- Companion frontend? (Triggers Phase 4 cross-link.)
67
68---
69
70## Phase 2: Recommend
71
72Based on what you found, present a concrete proposal. Don't ask open-ended questions — lead with a recommendation:
73
74**Route from OTel detection:**
75- **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
76
77**Always recommended (core coverage):**
78- ✅ **Error Monitoring** — captures unhandled exceptions, supports `ExceptionGroup` (Python 3.11+)
79- ✅ **Logging** — Python `logging` stdlib auto-captured; enhanced if Loguru detected
80
81**Recommend when detected:**
82- ✅ **Tracing** — HTTP framework detected (Django/Flask/FastAPI/etc.)
83- ✅ **AI Monitoring** — OpenAI/Anthropic/LangChain/etc. detected (auto-instrumented, zero config)
84- ⚡ **Profiling** — production apps where performance matters; **not available with OTLP path**
85- ⚡ **Crons** — Celery Beat, APScheduler, or cron patterns detected
86- ⚡ **Metrics** — business KPIs, SLO tracking
87
88**Recommendation matrix:**
89
90| Feature | Recommend when... | Reference |
91|---------|------------------|-----------|
92| Error Monitoring | **Always** — non-negotiable baseline | `${SKILL_ROOT}/references/error-monitoring.md` |
93| OTLP Integration | OTel tracing detected — **replaces** native Tracing | `${SKILL_ROOT}/references/tracing.md` |
94| Tracing | Django/Flask/FastAPI/AIOHTTP/etc. detected; **skip if OTel tracing detected** | `${SKILL_ROOT}/references/tracing.md` |
95| Profiling | Production + performance-sensitive workload; **skip if OTel tracing detected** (requires `traces_sample_rate`, incompatible with OTLP) | `${SKILL_ROOT}/references/profiling.md` |
96| Logging | Always (stdlib); enhanced for Loguru | `${SKILL_ROOT}/references/logging.md` |
97| Metrics | Business events or SLO tracking needed | `${SKILL_ROOT}/references/metrics.md` |
98| Crons | Celery Beat, APScheduler, or cron patterns | `${SKILL_ROOT}/references/crons.md` |
99| AI Monitoring | OpenAI/Anthropic/LangChain/etc. detected | `${SKILL_ROOT}/references/ai-monitoring.md` |
100
101**OTel tracing detected:** *"I see OpenTelemetry tracing in the project. I recommend Sentry's OTLP integration for tracing (via your existing OTel setup) + Error Monitoring + Sentry Logging [+ Metrics/Crons/AI Monitoring if applicable]. Shall I proceed?"*
102
103**No OTel:** *"I recommend Error Monitoring + Tracing [+ Logging if applicable]. Want Profiling, Crons, or AI Monitoring too?"*
104
105---
106
107## Phase 3: Guide
108
109### Install
110
111```bash
112# Core SDK (always required)
113pip install sentry-sdk
114
115# Optional extras (install only what matches detected framework):
116pip install "sentry-sdk[django]"
117pip install "sentry-sdk[flask]"
118pip install "sentry-sdk[fastapi]"
119pip install "sentry-sdk[celery]"
120pip install "sentry-sdk[aiohttp]"
121pip install "sentry-sdk[tornado]"
122
123# Multiple extras:
124pip install "sentry-sdk[django,celery]"
125```
126
127> Extras are optional — plain `sentry-sdk` works for all frameworks. Extras install complementary packages.
128
129### Quick Start — Recommended Init
130
131Full init enabling the most features with sensible defaults. Place **before** any app/framework code:
132
133```python
134import sentry_sdk
135
136sentry_sdk.init(
137 dsn=os.environ["SENTRY_DSN"],
138 environment=os.environ.get("SENTRY_ENVIRONMENT", "production"),
139 release=os.environ.get("SENTRY_RELEASE"), # e.g. "myapp@1.0.0"
140 send_default_pii=True,
141
142 # Tracing (lower to 0.1–0.2 in high-traffic production)
143 traces_sample_rate=1.0,
144
145 # Profiling — continuous, tied to active spans
146 profile_session_sample_rate=1.0,
147 profile_lifecycle="trace",
148
149 # Structured logs (SDK ≥ 2.35.0)
150 enable_logs=True,
151)
152```
153
154### Where to Initialize Per Framework
155
156| Framework | Where to call `sentry_sdk.init()` | Notes |
157|-----------|-----------------------------------|-------|
158| **Django** | Top of `settings.py`, before any imports | No middleware needed — Sentry patches Django internally |
159| **Flask** | Before `app = Flask(__name__)` | Must precede app creation |
160| **FastAPI** | Before `app = FastAPI()` | `StarletteIntegration` + `FastApiIntegration` auto-enabled together |
161| **Starlette** | Before `app = Starlette(...)` | Same auto-integration as FastAPI |
162| **AIOHTTP** | Module level, before `web.Application()` | |
163| **Tornado** | Module level, before app setup | No integration class needed |
164| **Quart** | Before `app = Quart(__name__)` | |
165| **Falcon** | Module level, before `app = falcon.App()` | |
166| **Pyramid** | Module level, before `config = Configurator()` | WSGI framework |
167| **Sanic** | Inside `@app.listener("before_server_start")` | Sanic's lifecycle requires async init |
168| **Celery** | `@signals.celeryd_init.connect` in worker AND in calling process | Dual-process init required |
169| **RQ** | `mysettings.py` loaded by worker via `rq worker -c mysettings` | |
170| **ARQ** | Both worker module and enqueuing process | |
171
172**Django example** (`settings.py`):
173```python
174import sentry_sdk
175
176sentry_sdk.init(
177 dsn=os.environ["SENTRY_DSN"],
178 send_default_pii=True,
179 traces_sample_rate=1.0,
180 profile_session_sample_rate=1.0,
181 profile_lifecycle="trace",
182 enable_logs=True,
183)
184
185# rest of Django settings...
186INSTALLED_APPS = [...]
187```
188
189**FastAPI example** (`main.py`):
190```python
191import sentry_sdk
192
193sentry_sdk.init(
194 dsn=os.environ["SENTRY_DSN"],
195 send_default_pii=True,
196 traces_sample_rate=1.0,
197 profile_session_sample_rate=1.0,
198 profile_lifecycle="trace",
199 enable_logs=True,
200)
201
202from fastapi import FastAPI
203app = FastAPI()
204```
205
206### Auto-Enabled vs Explicit Integrations
207
208Most integrations activate automatically when their package is installed — no `integrations=[...]` needed:
209
210| Auto-enabled | Explicit required |
211|-------------|-------------------|
212| Django, Flask, FastAPI, Starlette, AIOHTTP, Tornado, Quart, Falcon, Pyramid, Sanic, Bottle | `DramatiqIntegration` |
213| Celery, RQ, Huey, ARQ | `GRPCIntegration` |
214| SQLAlchemy, Redis, asyncpg, pymongo | `StrawberryIntegration` |
215| Requests, HTTPX, httpx2, aiohttp-client | `AsyncioIntegration` |
216| OpenAI, Anthropic, LangChain, Pydantic AI, MCP | `OpenTelemetryIntegration` |
217| Python `logging`, Loguru | `WSGIIntegration` / `ASGIIntegration` |
218
219### For Each Agreed Feature
220
221Walk through features one at a time. Load the reference, follow its steps, verify before moving on:
222
223| Feature | Reference file | Load when... |
224|---------|---------------|-------------|
225| Error Monitoring | `${SKILL_ROOT}/references/error-monitoring.md` | Always (baseline) |
226| Tracing | `${SKILL_ROOT}/references/tracing.md` | HTTP handlers / distributed tracing |
227| Profiling | `${SKILL_ROOT}/references/profiling.md` | Performance-sensitive production |
228| Logging | `${SKILL_ROOT}/references/logging.md` | Always; enhanced for Loguru |
229| Metrics | `${SKILL_ROOT}/references/metrics.md` | Business KPIs / SLO tracking |
230| Crons | `${SKILL_ROOT}/references/crons.md` | Scheduler / cron patterns detected |
231| AI Monitoring | `${SKILL_ROOT}/references/ai-monitoring.md` | AI library detected |
232
233For each feature: `Read ${SKILL_ROOT}/references/<feature>.md`, follow steps exactly, verify it works.
234
235---
236
237## Configuration Reference
238
239### Key `sentry_sdk.init()` Options
240
241| Option | Type | Default | Purpose |
242|--------|------|---------|---------|
243| `dsn` | `str` | `None` | SDK disabled if empty; env: `SENTRY_DSN` |
244| `environment` | `str` | `"production"` | e.g., `"staging"`; env: `SENTRY_ENVIRONMENT` |
245| `release` | `str` | `None` | e.g., `"myapp@1.0.0"`; env: `SENTRY_RELEASE` |
246| `send_default_pii` | `bool` | `False` | Include IP, headers, cookies, auth user, query strings (ASGI frameworks) |
247| `traces_sample_rate` | `float` | `None` | Transaction sample rate; `None` disables tracing |
248| `traces_sampler` | `Callable` | `None` | Custom per-transaction sampling (overrides rate) |
249| `profile_session_sample_rate` | `float` | `None` | Continuous profiling session rate |
250| `profile_lifecycle` | `str` | `"manual"` | `"trace"` = auto-start profiler with spans |
251| `profiles_sample_rate` | `float` | `None` | Transaction-based profiling rate |
252| `enable_logs` | `bool` | `False` | Send logs to Sentry (SDK ≥ 2.35.0) |
253| `sample_rate` | `float` | `1.0` | Error event sample rate |
254| `attach_stacktrace` | `bool` | `False` | Stack traces on `capture_message()` |
255| `max_breadcrumbs` | `int` | `100` | Max breadcrumbs per event |
256| `debug` | `bool` | `False` | Verbose SDK debug output |
257| `before_send` | `Callable` | `None` | Hook to mutate/drop error events |
258| `before_send_transaction` | `Callable` | `None` | Hook to mutate/drop transaction events |
259| `ignore_errors` | `list` | `[]` | Exception types or regex patterns to suppress |
260| `auto_enabling_integrations` | `bool` | `True` | Set `False` to disable all auto-detection |
261
262#### `OTLPIntegration` Options (pass to constructor)
263
264| Option | Type | Default | Purpose |
265|--------|------|---------|---------|
266| `setup_otlp_traces_exporter` | `bool` | `True` | Auto-configure OTLP exporter; set `False` if you send to your own Collector |
267| `collector_url` | `str` | `None` | OTLP HTTP endpoint of an OTel Collector (e.g., `http://localhost:4318/v1/traces`); when set, spans are sent to the collector instead of directly to Sentry |
268| `setup_propagator` | `bool` | `True` | Auto-configure Sentry propagator for distributed tracing |
269| `capture_exceptions` | `bool` | `False` | Intercept exceptions recorded via OTel `Span.record_exception` |
270
271### Environment Variables
272
273| Variable | Maps to | Notes |
274|----------|---------|-------|
275| `SENTRY_DSN` | `dsn` | |
276| `SENTRY_RELEASE` | `release` | Also auto-detected from git SHA, Heroku, CircleCI, CodeBuild, GAE |
277| `SENTRY_ENVIRONMENT` | `environment` | |
278| `SENTRY_DEBUG` | `debug` | |
279
280---
281
282## Verification
283
284Test that Sentry is receiving events:
285
286```python
287# Trigger a real error event — check dashboard within seconds
288division_by_zero = 1 / 0
289```
290
291Or for a non-crashing check:
292```python
293sentry_sdk.capture_message("Sentry Python SDK test")
294```
295
296If nothing appears:
2971. Set `debug=True` in `sentry_sdk.init()` — prints SDK internals to stdout
2982. Verify the DSN is correct
2993. Check `SENTRY_DSN` env var is set in the running process
3004. For Celery/RQ: ensure init runs in the **worker** process, not just the calling process
301
302---
303
304## Phase 4: Cross-Link
305
306After completing Python setup, check for a companion frontend missing Sentry:
307
308```bash
309ls frontend/ web/ client/ ui/ 2>/dev/null
310cat frontend/package.json web/package.json client/package.json 2>/dev/null \
311 | grep -E '"react"|"svelte"|"vue"|"next"|"nuxt"'
312```
313
314If a frontend exists without Sentry, suggest the matching skill:
315
316| Frontend detected | Suggest skill |
317|-------------------|--------------|
318| React / Next.js | `sentry-react-sdk` |
319| Svelte / SvelteKit | `sentry-svelte-sdk` |
320| Vue / Nuxt | Use `@sentry/vue` — see [docs.sentry.io/platforms/javascript/guides/vue/](https://docs.sentry.io/platforms/javascript/guides/vue/) |
321| Other JS/TS | `sentry-react-sdk` (covers generic browser JS patterns) |
322
323---
324
325## Troubleshooting
326
327| Issue | Solution |
328|-------|----------|
329| Events not appearing | Set `debug=True`, verify DSN, check env vars in the running process |
330| Malformed DSN error | Format: `https://<key>@o<org>.ingest.sentry.io/<project>` |
331| Django exceptions not captured | Ensure `sentry_sdk.init()` is at the **top** of `settings.py` before other imports |
332| Flask exceptions not captured | Init must happen **before** `app = Flask(__name__)` |
333| FastAPI exceptions not captured | Init before `app = FastAPI()`; both `StarletteIntegration` and `FastApiIntegration` auto-enabled |
334| ASGI chained exceptions suppressed | By default, Sentry's ASGI middleware strips exception chains (`raise exc from None`). To preserve chained exceptions, set `_experiments={"suppress_asgi_chained_exceptions": False}` in `sentry_sdk.init()` |
335| Celery task errors not captured | Must call `sentry_sdk.init()` in the **worker process** via `celeryd_init` signal |
336| Sanic init not working | Init must be inside `@app.listener("before_server_start")`, not module level |
337| uWSGI not capturing | Add `--enable-threads --py-call-uwsgi-fork-hooks` to uWSGI command |
338| No traces appearing (native) | Verify `traces_sample_rate` is set (not `None`); check that the integration is auto-enabled |
339| No traces appearing (OTLP) | Verify `sentry-sdk[opentelemetry-otlp]` is installed; do **not** set `traces_sample_rate` when using `OTLPIntegration` |
340| Profiling not starting | Requires `traces_sample_rate > 0` + either `profile_session_sample_rate` or `profiles_sample_rate`; **not compatible with OTLP path** |
341| `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=...)` |
342| Too many transactions | Lower `traces_sample_rate` or use `traces_sampler` to drop health checks |
343| Cross-request data leaking | Don't use `get_global_scope()` for per-request data — use `get_isolation_scope()` |
344| Query strings not captured (ASGI) | Query strings and client IP in ASGI frameworks (FastAPI, Starlette, etc.) require `send_default_pii=True` |
345| RQ worker not reporting | Pass `--sentry-dsn=""` to disable RQ's own Sentry shortcut; init via settings file instead |