Logging, tracing, and observability
Managing agents does not only mean implementing guardrails; it also means having a good observability infrastructure to fully understand what your agent is doing. As we have seen in previous chapters, OpenAI Agents SDK comes with the powerful Traces module, which records the sequence of events (model calls, tool calls, handoffs, guardrail triggers, etc.) during an agent’s run.
Tracing is automatically enabled for all agent runs and can be accessed via the OpenAI dashboard (as we have seen throughout this book). This provides an out-of-the-box solution for debugging and monitoring, which captures a rich set of events. These recorded events are stored as spans within an overall trace for the run. It is useful to understand the difference between traces and spans:
- Trace: Represents one full execution flow of your agent system. It’s like a timeline of everything that happened from start to finish for a given user prompt...