|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | +# Integrations Guide |
| 7 | + |
| 8 | +## Integration Categories |
| 9 | + |
| 10 | +The Sentry Python SDK includes integrations for popular frameworks, libraries, and services: |
| 11 | + |
| 12 | +### Web Frameworks |
| 13 | +- [sentry_sdk/integrations/django/](mdc:sentry_sdk/integrations/django) - Django web framework |
| 14 | +- [sentry_sdk/integrations/flask/](mdc:sentry_sdk/integrations/flask) - Flask microframework |
| 15 | +- [sentry_sdk/integrations/fastapi/](mdc:sentry_sdk/integrations/fastapi) - FastAPI framework |
| 16 | +- [sentry_sdk/integrations/starlette/](mdc:sentry_sdk/integrations/starlette) - Starlette ASGI framework |
| 17 | +- [sentry_sdk/integrations/sanic/](mdc:sentry_sdk/integrations/sanic) - Sanic async framework |
| 18 | +- [sentry_sdk/integrations/tornado/](mdc:sentry_sdk/integrations/tornado) - Tornado web framework |
| 19 | +- [sentry_sdk/integrations/pyramid/](mdc:sentry_sdk/integrations/pyramid) - Pyramid framework |
| 20 | +- [sentry_sdk/integrations/bottle/](mdc:sentry_sdk/integrations/bottle) - Bottle microframework |
| 21 | +- [sentry_sdk/integrations/chalice/](mdc:sentry_sdk/integrations/chalice) - AWS Chalice |
| 22 | +- [sentry_sdk/integrations/quart/](mdc:sentry_sdk/integrations/quart) - Quart async framework |
| 23 | +- [sentry_sdk/integrations/falcon/](mdc:sentry_sdk/integrations/falcon) - Falcon framework |
| 24 | +- [sentry_sdk/integrations/litestar/](mdc:sentry_sdk/integrations/litestar) - Litestar framework |
| 25 | +- [sentry_sdk/integrations/starlite/](mdc:sentry_sdk/integrations/starlite) - Starlite framework |
| 26 | + |
| 27 | +### Task Queues and Background Jobs |
| 28 | +- [sentry_sdk/integrations/celery/](mdc:sentry_sdk/integrations/celery) - Celery task queue |
| 29 | +- [sentry_sdk/integrations/rq/](mdc:sentry_sdk/integrations/rq) - Redis Queue |
| 30 | +- [sentry_sdk/integrations/huey/](mdc:sentry_sdk/integrations/huey) - Huey task queue |
| 31 | +- [sentry_sdk/integrations/arq/](mdc:sentry_sdk/integrations/arq) - Arq async task queue |
| 32 | +- [sentry_sdk/integrations/dramatiq/](mdc:sentry_sdk/integrations/dramatiq) - Dramatiq task queue |
| 33 | + |
| 34 | +### Databases and Data Stores |
| 35 | +- [sentry_sdk/integrations/sqlalchemy/](mdc:sentry_sdk/integrations/sqlalchemy) - SQLAlchemy ORM |
| 36 | +- [sentry_sdk/integrations/asyncpg/](mdc:sentry_sdk/integrations/asyncpg) - AsyncPG PostgreSQL |
| 37 | +- [sentry_sdk/integrations/pymongo/](mdc:sentry_sdk/integrations/pymongo) - PyMongo MongoDB |
| 38 | +- [sentry_sdk/integrations/redis/](mdc:sentry_sdk/integrations/redis) - Redis client |
| 39 | +- [sentry_sdk/integrations/clickhouse_driver/](mdc:sentry_sdk/integrations/clickhouse_driver) - ClickHouse driver |
| 40 | + |
| 41 | +### Cloud and Serverless |
| 42 | +- [sentry_sdk/integrations/aws_lambda/](mdc:sentry_sdk/integrations/aws_lambda) - AWS Lambda |
| 43 | +- [sentry_sdk/integrations/gcp/](mdc:sentry_sdk/integrations/gcp) - Google Cloud Platform |
| 44 | +- [sentry_sdk/integrations/serverless/](mdc:sentry_sdk/integrations/serverless) - Serverless framework |
| 45 | + |
| 46 | +### HTTP and Networking |
| 47 | +- [sentry_sdk/integrations/requests/](mdc:sentry_sdk/integrations/requests) - Requests HTTP library |
| 48 | +- [sentry_sdk/integrations/httpx/](mdc:sentry_sdk/integrations/httpx) - HTTPX async HTTP client |
| 49 | +- [sentry_sdk/integrations/aiohttp/](mdc:sentry_sdk/integrations/aiohttp) - aiohttp async HTTP |
| 50 | +- [sentry_sdk/integrations/grpc/](mdc:sentry_sdk/integrations/grpc) - gRPC framework |
| 51 | + |
| 52 | +### AI and Machine Learning |
| 53 | +- [sentry_sdk/integrations/openai/](mdc:sentry_sdk/integrations/openai) - OpenAI API |
| 54 | +- [sentry_sdk/integrations/anthropic/](mdc:sentry_sdk/integrations/anthropic) - Anthropic Claude |
| 55 | +- [sentry_sdk/integrations/cohere/](mdc:sentry_sdk/integrations/cohere) - Cohere AI |
| 56 | +- [sentry_sdk/integrations/huggingface_hub/](mdc:sentry_sdk/integrations/huggingface_hub) - Hugging Face Hub |
| 57 | +- [sentry_sdk/integrations/langchain/](mdc:sentry_sdk/integrations/langchain) - LangChain framework |
| 58 | + |
| 59 | +### GraphQL |
| 60 | +- [sentry_sdk/integrations/graphene/](mdc:sentry_sdk/integrations/graphene) - Graphene GraphQL |
| 61 | +- [sentry_sdk/integrations/ariadne/](mdc:sentry_sdk/integrations/ariadne) - Ariadne GraphQL |
| 62 | +- [sentry_sdk/integrations/strawberry/](mdc:sentry_sdk/integrations/strawberry) - Strawberry GraphQL |
| 63 | +- [sentry_sdk/integrations/gql/](mdc:sentry_sdk/integrations/gql) - GQL GraphQL client |
| 64 | + |
| 65 | +### Feature Flags and Configuration |
| 66 | +- [sentry_sdk/integrations/launchdarkly/](mdc:sentry_sdk/integrations/launchdarkly) - LaunchDarkly |
| 67 | +- [sentry_sdk/integrations/unleash/](mdc:sentry_sdk/integrations/unleash) - Unleash |
| 68 | +- [sentry_sdk/integrations/statsig/](mdc:sentry_sdk/integrations/statsig) - Statsig |
| 69 | +- [sentry_sdk/integrations/openfeature/](mdc:sentry_sdk/integrations/openfeature) - OpenFeature |
| 70 | + |
| 71 | +### Other Integrations |
| 72 | +- [sentry_sdk/integrations/logging/](mdc:sentry_sdk/integrations/logging) - Python logging |
| 73 | +- [sentry_sdk/integrations/loguru/](mdc:sentry_sdk/integrations/loguru) - Loguru logging |
| 74 | +- [sentry_sdk/integrations/opentelemetry/](mdc:sentry_sdk/integrations/opentelemetry) - OpenTelemetry |
| 75 | +- [sentry_sdk/integrations/ray/](mdc:sentry_sdk/integrations/ray) - Ray distributed computing |
| 76 | +- [sentry_sdk/integrations/spark/](mdc:sentry_sdk/integrations/spark) - Apache Spark |
| 77 | +- [sentry_sdk/integrations/beam/](mdc:sentry_sdk/integrations/beam) - Apache Beam |
| 78 | + |
| 79 | +## Integration Usage |
| 80 | + |
| 81 | +### Basic Integration Setup |
| 82 | +```python |
| 83 | +import sentry_sdk |
| 84 | +from sentry_sdk.integrations.django import DjangoIntegration |
| 85 | +from sentry_sdk.integrations.celery import CeleryIntegration |
| 86 | + |
| 87 | +sentry_sdk.init( |
| 88 | + dsn="your-dsn", |
| 89 | + integrations=[ |
| 90 | + DjangoIntegration(), |
| 91 | + CeleryIntegration(), |
| 92 | + ], |
| 93 | + traces_sample_rate=1.0, |
| 94 | +) |
| 95 | +``` |
| 96 | + |
| 97 | +### Integration Configuration |
| 98 | +Most integrations accept configuration parameters: |
| 99 | +```python |
| 100 | +from sentry_sdk.integrations.django import DjangoIntegration |
| 101 | +from sentry_sdk.integrations.redis import RedisIntegration |
| 102 | + |
| 103 | +sentry_sdk.init( |
| 104 | + dsn="your-dsn", |
| 105 | + integrations=[ |
| 106 | + DjangoIntegration( |
| 107 | + transaction_style="url", # Customize transaction naming |
| 108 | + ), |
| 109 | + RedisIntegration( |
| 110 | + cache_prefixes=["myapp:"], # Filter cache operations |
| 111 | + ), |
| 112 | + ], |
| 113 | +) |
| 114 | +``` |
| 115 | + |
| 116 | +### Integration Testing |
| 117 | +Each integration has corresponding tests in [tests/integrations/](mdc:tests/integrations): |
| 118 | +- [tests/integrations/django/](mdc:tests/integrations/django) - Django integration tests |
| 119 | +- [tests/integrations/flask/](mdc:tests/integrations/flask) - Flask integration tests |
| 120 | +- [tests/integrations/celery/](mdc:tests/integrations/celery) - Celery integration tests |
| 121 | + |
| 122 | +## Integration Development |
| 123 | + |
| 124 | +### Creating New Integrations |
| 125 | +1. **Create integration file** in [sentry_sdk/integrations/](mdc:sentry_sdk/integrations) |
| 126 | +2. **Inherit from Integration base class** |
| 127 | +3. **Implement setup_once() method** |
| 128 | +4. **Add to integration registry** |
| 129 | + |
| 130 | +### Integration Base Class |
| 131 | +```python |
| 132 | +from sentry_sdk.integrations import Integration |
| 133 | + |
| 134 | +class MyIntegration(Integration): |
| 135 | + identifier = "my_integration" |
| 136 | + |
| 137 | + def __init__(self, param=None): |
| 138 | + self.param = param |
| 139 | + |
| 140 | + @staticmethod |
| 141 | + def setup_once(): |
| 142 | + # Install hooks, monkey patches, etc. |
| 143 | + pass |
| 144 | +``` |
| 145 | + |
| 146 | +### Common Integration Patterns |
| 147 | +- **Monkey patching**: Replace functions with instrumented versions |
| 148 | +- **Middleware**: Add middleware to web frameworks |
| 149 | +- **Signal handlers**: Hook into framework signals |
| 150 | +- **Exception handlers**: Catch and process exceptions |
| 151 | +- **Context managers**: Add context to operations |
| 152 | + |
| 153 | +### Integration Best Practices |
| 154 | +- **Zero configuration**: Work without user setup |
| 155 | +- **Check integration status**: Use `sentry_sdk.get_client().get_integration()` |
| 156 | +- **No side effects**: Don't alter library behavior |
| 157 | +- **Graceful degradation**: Handle missing dependencies |
| 158 | +- **Comprehensive testing**: Test all integration features |
0 commit comments