Tracing FastAPI and agents with @observe
Tracing FastAPI and agents with @observe
The drop-in from the last lesson gives you generations with no parent. @observe() gives them a family. Put the decorator on a function and the call becomes an observation: the outermost observed call in a request becomes the trace, every observed function it calls becomes a nested span, and any OpenAI call made through the drop-in attaches itself to whatever span is current. You describe the structure once, with decorators, and the tree assembles itself at run time.
Here is Relay's answer path with two observed functions. The retrieval step becomes a span under answer, and the model call becomes a generation under it too, because the drop-in looks up the current span through the same context the decorator sets.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.