Overview
RDK integrates seamlessly with FastAPI. This guide shows how to set up tracing in a production FastAPI application.
Basic Setup
Use FastAPI’s lifespan handler to initialize and shutdown RDK:
Complete Example
Here’s a full FastAPI application with RDK tracing:
Agent Endpoint
Add an endpoint with tool calling:
Request Tracking
Add request IDs to traces for debugging:
Error Handling
RDK captures errors automatically, but you can add context:
Running the App
Testing
Disable tracing in tests using mode="test" or enabled=False:
Production Considerations
Always call shutdown() in your lifespan handler to flush pending traces before the app exits.
- Set appropriate batch size — Higher values reduce network calls
- Configure flush interval — Balance latency vs. data freshness
- Use PII redaction — Required for compliance
- Monitor flush endpoint — Useful for debugging trace delivery
See Also