Overview
Phoenix tracing provides:- Request tracking - Trace every agent interaction
- Performance monitoring - Measure latency and bottlenecks
- Debugging - Inspect agent decisions and tool calls
- Analytics - Understand usage patterns and model behavior
Configuration
Environment Variables
Enable Phoenix tracing. Set to
true to activate.API key for authenticating with Phoenix/Arize.
Phoenix trace collection endpoint URL.
Project name for organizing traces in Phoenix dashboard.
Setup Process
1. Installation
Phoenix tracing requires thephoenix package:
If the
phoenix package is not installed, tracing will be automatically disabled with a warning.2. Enable Tracing
Set environment variables in your.env file:
3. Initialization
Tracing is initialized automatically on startup (agent/agent_factory.py:42-44):
Implementation Details
Lazy Initialization
Phoenix is initialized lazily to avoid loading heavy dependencies when tracing is disabled:core/observability.py:7-15
Environment Setup
Phoenix client headers and collector endpoint are configured automatically:core/observability.py:28-31
Tracer Registration
The Phoenix tracer is registered with performance optimizations:core/observability.py:34-39
Parameters:
project_name- Organizes traces by project in Phoenix UIendpoint- Where traces are sentauto_instrument=True- Automatically captures LLM API callsbatch=True- Reduces overhead by batching trace exports
Error Handling
Missing API Key
IfPHOENIX_API_KEY is not set:
core/observability.py:21-25
Missing Package
Ifphoenix package is not installed:
core/observability.py:46-50
Initialization Failure
Any other initialization errors are caught and logged:core/observability.py:51-55
Performance Optimization
Batching
Traces are batched before export to reduce network overhead:Conditional Import
Phoenix is only imported when tracing is enabled:Singleton Pattern
Tracer is initialized once and cached:What Gets Traced
Withauto_instrument=True, Phoenix automatically traces:
- LLM API calls - All requests to OpenAI-compatible APIs
- Model responses - Completions, token usage, latency
- Tool calls - Agent tool invocations and results
- Errors - Exceptions and failures in agent operations
Viewing Traces
Access traces through the Phoenix dashboard:- Navigate to your Phoenix endpoint
- Select your project (configured via
PHOENIX_PROJECT_NAME) - View traces organized by:
- Timestamp
- Agent/model
- Latency
- Token usage
- Success/error status
Example Configurations
Troubleshooting
Tracing Not Working
Check the following:-
Environment variable is set correctly:
-
API key is configured:
-
Phoenix package is installed:
-
Check logs for warnings:
Look for messages like:
"PHOENIX_API_KEY not set, skipping Phoenix tracing""Phoenix package not installed""Failed to initialize Phoenix tracing"
High Overhead
If tracing adds too much latency:- Ensure
batch=Trueis enabled (it is by default) - Consider using a sampling strategy (not currently implemented)
- Disable tracing for high-frequency operations
Tracing adds minimal overhead when batching is enabled, typically less than 50ms per request.
Best Practices
-
Use different projects for different environments:
- Enable tracing in development for debugging
- Monitor token usage through traces to optimize costs
- Review error traces to identify and fix issues
- Keep tracing disabled in local development unless debugging