Skip to main content

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.
  1. Set appropriate batch size — Higher values reduce network calls
  2. Configure flush interval — Balance latency vs. data freshness
  3. Use PII redaction — Required for compliance
  4. Monitor flush endpoint — Useful for debugging trace delivery

See Also