Overview
Codex provides comprehensive tracing and logging capabilities to help you understand what’s happening under the hood. This is especially useful for:- Debugging unexpected behavior
- Troubleshooting integration issues
- Understanding performance characteristics
- Filing detailed bug reports
Quick Start
Enable verbose logging with theRUST_LOG environment variable:
RUST_LOG Environment Variable
TheRUST_LOG variable controls logging verbosity using the standard Rust tracing infrastructure.
Log Levels
Only critical errors that prevent operation
Warning messages about potential issues
High-level informational messages (default for Codex crates)
Detailed debugging information
Extremely verbose tracing output
Syntax
- Global Level
- Per-Module
- Pattern Matching
Set the same level for all modules:
Common Logging Scenarios
Debug API Requests
- Request URLs and headers
- Request body payloads
- Response status codes
- Response bodies
- Timing information
Debug File Operations
- Files being read
- Patches being applied
- File system operations
- Permission checks
Debug Command Execution
- Commands being executed
- Working directory
- Environment variables
- stdout/stderr output
- Exit codes
Debug Sandboxing
- Sandbox initialization
- Policy rules being applied
- Permission checks
- Blocked operations
Exec Mode Logging
In exec mode, logs are written to a file to avoid interfering with output:Log File Location
By default, logs are written to:Enable File Logging
Logs are automatically written to file when you setRUST_LOG:
Log Rotation
Log files are rotated automatically. Old logs are kept for debugging but can be safely deleted.
OpenTelemetry Integration
Codex supports OpenTelemetry for distributed tracing:Configuration
~/.codex/config.toml
Environment Variables
Alternatively, use standard OTEL env vars:Viewing Traces
Use Jaeger or another OTEL-compatible backend:Legacy TypeScript CLI
For the legacy TypeScript implementation, useDEBUG:
The TypeScript CLI is deprecated. Consider migrating to the Rust implementation for better performance and features.
Practical Examples
Debug slow performance
Debug slow performance
- API request latency
- File I/O timing
- Long-running operations
Debug authentication issues
Debug authentication issues
- Token acquisition
- Token refresh attempts
- Authentication errors
- API key validation
Debug MCP integration
Debug MCP integration
- MCP server initialization
- Tool calls and responses
- Connection errors
- Message parsing
Debug config loading
Debug config loading
- Config file locations checked
- Loaded configuration values
- Override application
- Validation errors
Full diagnostic logging
Full diagnostic logging
Performance Considerations
Log Level Impact
Higher log levels (trace/debug) can slow down execution by 10-50%
File I/O Overhead
Writing logs to disk adds latency, especially with trace level
Memory Usage
Verbose logging increases memory usage for buffering
Network Tracing
OTEL tracing adds ~5-10ms per span to network requests
Filtering Output
Grep for Specific Events
Focus on Specific Modules
Troubleshooting Logging
No logs appearing
No logs appearing
- Verify
RUST_LOGis set:echo $RUST_LOG - Check log file location:
ls -lh ~/.codex/logs/ - Try higher verbosity:
RUST_LOG=trace - Ensure Codex has write permissions to log directory
Too much output
Too much output
- Lower the log level:
RUST_LOG=infoinstead ofdebug - Filter to specific modules:
RUST_LOG=codex_core=debug - Use grep to filter:
RUST_LOG=debug codex 2>&1 | grep pattern
Logs missing expected info
Logs missing expected info
- Increase verbosity:
RUST_LOG=debugorRUST_LOG=trace - Check you’re targeting the right module
- Some modules may not have debug logging implemented
Sensitive data in logs
Sensitive data in logs
- Codex attempts to redact secrets automatically
- Review logs before sharing publicly
- Use
RUST_LOG=infoin production to minimize exposure - Set
otel.sampling_ratio = 0.1to reduce trace data
Filing Bug Reports
When reporting issues, include relevant logs:Redact Sensitive Data
Review the log file and remove:
- API keys
- Tokens
- Personal information
- Proprietary code
Attach to Issue
Include the redacted log file when filing a GitHub issue:https://github.com/openai/codex/issues/new
Advanced Configuration
Custom Log Format
Codex usestracing-subscriber for logging. You can customize the format:
Span Tracing
View function call spans:See Also
Exec Mode
Non-interactive execution for automation
Configuration
Configure Codex behavior
Troubleshooting
Common issues and solutions
Contributing
Help improve Codex