FastAPI Project Guide
Complete rollout strategy for FastAPI services and async workloads
Use this guide for FastAPI services where async request handling and dependency injection are central.
Architecture Scope
- API endpoints and dependency graph.
- Async DB calls and background tasks.
- Exception handling and response serialization.
Setup
The middleware auto-captures every request as a span with method, path, status, and duration. All logging.* calls are captured automatically.
Environment Variables
Validation Checklist
- Synthetic request emits log + span + metric
- Error responses include correlated trace context
-
logging.error()calls appear in Obtrace as error logs - Shutdown flush emits final queue successfully
Production Hardening
- Restrict sensitive fields before emission.
- Tune queue and flush interval for async workloads.
- Register
atexitor FastAPI shutdown event for clean flush.
Troubleshooting
- Startup works but no data: inspect middleware order (obtrace middleware should be first).
- Drops under load: tune queue backpressure settings.
- Trace gaps: instrument manual spans around async boundaries.