0

๐Ÿ” Tutorial 8: Tracing & Observability

awesome-llm-apps10_tracing_observability

Master monitoring and debugging with built-in tracing! This tutorial teaches you how to use the OpenAI Agents SDK's comprehensive tracing system to visualize, debug, and monitor your agent workflows during development and production.

Sign in to save downloads to your library and vote.

Preview

๐Ÿ” Tutorial 8: Tracing & Observability

Master monitoring and debugging with built-in tracing! This tutorial teaches you how to use the OpenAI Agents SDK's comprehensive tracing system to visualize, debug, and monitor your agent workflows during development and production.

๐ŸŽฏ What You'll Learn

  • Built-in Tracing: Automatic capture of LLM generations, tool calls, handoffs
  • Traces & Spans: Understanding workflow structure and execution flow
  • Custom Tracing: Creating custom traces and spans for complex workflows
  • Production Monitoring: Debugging and performance optimization

๐Ÿง  Core Concept: What Is Tracing?

Tracing provides comprehensive workflow monitoring that automatically captures every event during agent execution:

  • LLM Generations: Model calls, inputs, outputs, and performance
  • Tool Calls: Function executions, parameters, and results
  • Handoffs: Agent-to-agent delegations and context transfer
  • Guardrails: Input/output validation events
  • Custom Events: Your own monitoring points
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    TRACING ARCHITECTURE                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                             โ”‚
โ”‚  AGENT WORKFLOW                                             โ”‚
โ”‚       โ”‚                                                     โ”‚
โ”‚       โ–ผ                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    AUTOMATIC CAPTURE                       โ”‚
โ”‚  โ”‚    TRACE    โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚ (Workflow)  โ”‚                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                          โ”‚ โ”‚
โ”‚       โ”‚                                                   โ”‚ โ”‚
โ”‚       โ–ผ                                                   โ”‚ โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚ โ”‚
โ”‚  โ”‚    SPAN     โ”‚    โ”‚    SPAN     โ”‚    โ”‚    SPAN     โ”‚    โ”‚ โ”‚
โ”‚  โ”‚ (LLM Call)  โ”‚    โ”‚ (Tool Call) โ”‚    โ”‚ (Handoff)   โ”‚    โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚ โ”‚
โ”‚       โ”‚                    โ”‚                    โ”‚         โ”‚ โ”‚
โ”‚       โ–ผ                    โ–ผ                    โ–ผ         โ”‚ โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚ โ”‚
โ”‚  โ”‚         OPENAI TRACES DASHBOARD                     โ”‚  โ”‚ โ”‚
โ”‚  โ”‚    โ€ข Execution Visualization                        โ”‚  โ”‚ โ”‚
โ”‚  โ”‚    โ€ข Performance Metrics                            โ”‚__| โ”‚ 
โ”‚  โ”‚    โ€ข Debug Information                              โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Tutorial Overview

This tutorial demonstrates three key tracing patterns:

1. Default Tracing (default_tracing.py)

  • Built-in automatic tracing (enabled by default)
  • Understanding traces and spans structure
  • Basic workflow monitoring

2. Custom Tracing (custom_tracing.py)

  • Creating custom traces for multi-step workflows
  • Adding custom spans for monitoring points
  • Grouping multiple agent runs in single trace

3. Advanced Observability (advanced_observability.py)

  • Sensitive data handling and configuration
  • Custom trace processors for external systems
  • Production monitoring patterns

๐Ÿ“ Project Structure

8_tracing_observability/
โ”œโ”€โ”€ README.md                    # This file - concept explanation
โ”œโ”€โ”€ requirements.txt             # Dependencies  
โ”œโ”€โ”€ default_tracing.py           # Built-in tracing basics (35 lines)
โ”œโ”€โ”€ custom_tracing.py            # Custom traces and spans (45 lines)
โ”œโ”€โ”€ advanced_observability.py    # Production tracing patterns (40 lines)
โ”œโ”€โ”€ app.py                      # Streamlit tracing dashboard (optional)
โ””โ”€โ”€ env.example                 # Environment variables template

๐ŸŽฏ Learning Objectives

By the end of this tutorial, you'll understand:

  • โœ… How built-in tracing captures agent workflow events
  • โœ… Difference between traces (workflows) and spans (operations)
  • โœ… Creating custom traces for complex multi-step workflows
  • โœ… Monitoring and debugging agent performance in production
  • โœ… Integrating with external observability systems

๐Ÿš€ Getting Started

  1. Install OpenAI Agents SDK:

    pip install openai-agents
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

    cp env.example .env
    # Edit .env and add your OpenAI API key
    
  4. Test default tracing:

    python default_tracing.py
    
  5. Try custom tracing:

    python custom_tracing.py
    
  6. Explore advanced patterns:

    python advanced_observability.py
    

๐Ÿงช Sample Use Cases

Default Tracing

  • Monitor basic agent workflows automatically
  • Debug tool call failures and LLM generation issues
  • Track performance metrics for optimization

Custom Tracing

  • Group related agent runs in complex workflows
  • Add custom monitoring points in business logic
  • Create hierarchical span structures for debugging

Advanced Observability

  • Configure sensitive data handling for compliance
  • Export traces to external monitoring systems
  • Set up production alerting and dashboards

๐Ÿ”ง Key Tracing Patterns

1. Default Tracing (Automatic)

from agents import Agent, Runner

agent = Agent(name="Assistant")
# Tracing happens automatically - no setup required!
result = await Runner.run(agent, "Hello")
# View traces at: https://platform.openai.com/traces

2. Custom Trace Creation

from agents import Agent, Runner, trace

with trace("Multi-step Workflow") as my_trace:
    result1 = await Runner.run(agent, "Step 1")
    result2 = await Runner.run(agent, "Step 2")
    # Both runs are part of the same trace

3. Custom Spans

from agents import custom_span

with custom_span("Data Processing") as span:
    # Your custom logic here
    data = process_data()
    span.add_event("Processing complete", {"records": len(data)})

๐Ÿ’ก Tracing Design Best Practices

  1. Meaningful Names: Use descriptive trace and span names
  2. Logical Grouping: Group related operations in single traces
  3. Custom Events: Add key business events as custom spans
  4. Sensitive Data: Configure data handling for compliance
  5. Performance Monitoring: Track execution time and resource usage

๐Ÿšจ Important Notes

  • Enabled by Default: Tracing is automatically enabled
  • Zero Data Retention: Tracing unavailable for ZDR policy organizations
  • Free Dashboard: View traces at OpenAI Traces dashboard
  • Disable if Needed: Set OPENAI_AGENTS_DISABLE_TRACING=1 to disable

๐Ÿ”— Next Steps

After completing this tutorial, you'll be ready for:

๐Ÿšจ Troubleshooting

  • No Traces Visible: Check OpenAI API key and internet connectivity
  • Missing Spans: Ensure operations are within trace context
  • Performance Issues: Configure sensitive data filtering
  • ZDR Policy: Tracing unavailable - disable or use custom processors

๐Ÿ’ก Pro Tips

  • Start Simple: Use default tracing first, add custom traces as needed
  • Strategic Naming: Use consistent naming conventions for traces/spans
  • Monitor Performance: Track execution time trends over time
  • External Integration: Consider custom processors for your monitoring stack
  • Development vs Production: Different tracing strategies for each environment

Ingestion metadata

Source catalog
awesome-llm-apps
Repository
Shubhamsaboo/awesome-llm-apps ยท main
File path
ai_agent_framework_crash_course/openai_sdk_crash_course/10_tracing_observability/README.md
Last refreshed
7/24/2026, 3:00:13 AM (51m ago)
Refresh schedule
Daily ยท 03:00 UTC
Dedupe status
Unique ยท deduped by (source, url)