Loading...
Loading...
Setup Sentry in Python apps. Use when asked to add Sentry to Python, install sentry-sdk, or configure error monitoring, profiling, or logging for Python applications, Django, Flask, FastAPI.
npx skill4agent add jaffrepaul/agent-skills sentry-python-setuppip install sentry-sdkimport sentry_sdk
sentry_sdk.init(
dsn="YOUR_SENTRY_DSN",
send_default_pii=True,
# Tracing
traces_sample_rate=1.0,
# Profiling
profile_session_sample_rate=1.0,
profile_lifecycle="trace",
# Logs
enable_logs=True,
)import asyncio
import sentry_sdk
async def main():
sentry_sdk.init(
dsn="YOUR_SENTRY_DSN",
send_default_pii=True,
traces_sample_rate=1.0,
enable_logs=True,
)
# ... rest of app
asyncio.run(main())sentry_sdk.init()| Framework | Where to Init | Notes |
|---|---|---|
| Django | Top of | Auto-detects Django, no extra install |
| Flask | Before | Auto-detects Flask |
| FastAPI | Before | Auto-detects FastAPI |
| Celery | In Celery worker config | Auto-detects Celery |
| AIOHTTP | Before app creation | Auto-detects AIOHTTP |
| Option | Description | Default | Min SDK |
|---|---|---|---|
| Sentry DSN | | — |
| Include user data | | — |
| % of transactions traced | | — |
| % of sessions profiled | | 2.24.1+ |
| Profiling mode ( | | 2.24.1+ |
| Send logs to Sentry | | 2.35.0+ |
| Environment name | | — |
| Release version | Auto-detected | — |
SENTRY_DSN=https://xxx@o123.ingest.sentry.io/456
SENTRY_ENVIRONMENT=production
SENTRY_RELEASE=1.0.0sentry-cliSENTRY_AUTH_TOKEN=sntrys_xxx
SENTRY_ORG=my-org
SENTRY_PROJECT=my-projectimport os
import sentry_sdk
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
# ...
)# Intentional error to test
division_by_zero = 1 / 0sentry_sdk.capture_message("Test message from Python")| Issue | Solution |
|---|---|
| Errors not appearing | Ensure |
| No traces | Set |
| IPython errors not captured | Run from file, not interactive shell |
| Async errors missing | Initialize inside async function |