litellm/test_json_logs_proxy_startup.py
Claude 8955e579c7
Add comprehensive reproducers for json_logs issue
Investigation findings:
- JSON logging WORKS correctly in single-process mode
- All test scripts show proper JSON formatting with stacktraces
- Issue likely caused by multi-worker setup where _turn_on_json()
  is only called in main process, not worker processes

Test scripts added:
- test_json_logs_reproducer.py: Basic JSON logging with env var
- test_json_logs_late_enable.py: Tests late JSON logs enablement
- test_logging_handlers.py: Analyzes logger handler hierarchy
- test_proxy_json_logs_reproducer.py: Simulates exact proxy startup
- test_json_logs_config.yaml: Minimal proxy config for testing

Documentation:
- JSON_LOGS_REPRODUCTION.md: Comprehensive investigation findings,
  reproduction steps, and recommended solutions

Root cause: When using multiple workers (gunicorn/uvicorn), each
worker process has its own logging configuration. The _turn_on_json()
call in main process doesn't propagate to workers.

Recommended fix: Ensure _turn_on_json() is called in each worker
process during initialization, or set JSON_LOGS env var before import.
2026-01-19 22:35:17 +00:00

12 lines
403 B
Python

#!/usr/bin/env python3
"""
Reproducer that simulates EXACT proxy startup sequence.
This simulates what happens when:
1. Proxy starts without JSON_LOGS env var
2. Logging module is imported and initialized with default formatters
3. Config is loaded with json_logs: true
4. _turn_on_json() is called
5. Errors are logged
This should reproduce the bug if there's an issue with the initialization order.