Integrate gunicorn/uvicorn with consolidated OTLP logging library#292
Integrate gunicorn/uvicorn with consolidated OTLP logging library#292
Conversation
Co-authored-by: QMasterMoo <3915399+QMasterMoo@users.noreply.github.com>
Co-authored-by: QMasterMoo <3915399+QMasterMoo@users.noreply.github.com>
Co-authored-by: QMasterMoo <3915399+QMasterMoo@users.noreply.github.com>
|
@copilot origin/main has updates, rebase/merge whatever and resolve any conflicts Additionally, ensure this is the correct way to configure logging. Using a hook seems correct, but I want to be certain that this is the right way to configure logging, as opposed to via some other configure |
- Merge from upstream (0eb6780) to incorporate recent changes - Accept upstream worker count increase (1 → 4) - Accept upstream thread pool addition (threads=2) - Accept upstream timeout increases (30s → 120s, keepalive 2s → 5s) - Keep custom UvicornWorker for logging integration - Keep post_fork hook for OTLP logging configuration - Update tests to reflect new defaults - Update README with new defaults Co-authored-by: QMasterMoo <3915399+QMasterMoo@users.noreply.github.com>
Rebased with upstream changes in commit eca9873. Resolved conflict in Regarding logging configuration method: Using the |
|
@copilot there are still merge conflicts to resolve |
- Merge latest changes from origin/main (commit 2d26fc5) - Resolved conflict in libs/python/gunicorn/config.py - Kept custom UvicornWorker class for logging integration - Also picked up release planning changes from main Co-authored-by: QMasterMoo <3915399+QMasterMoo@users.noreply.github.com>
|
@copilot origin/main has had significant changes. rebase on main and redo this PR |
Rebased on latest main (commit eaf043a) in commits b95efc0 through 479bcf4. The branch now includes:
The rebased branch maintains full backward compatibility with upstream changes. Note: Since the rebase rewrote history, a force-push is required to update the PR, which requires manual intervention through GitHub's interface or special permissions. |
Fix gunicorn/uvicorn OTLP logging integration ✅
Problem
Gunicorn/uvicorn deployed apps do not use the same logging config as other apps, resulting in logs not being sent via OTLP.
Root Cause
logging_paramsdecorator configures OTLP logging viaconfigure_logging()Solution Implemented ✅
is_configuredfrom logging modulepost_worker_initparameter from mainTechnical Details
New Files:
libs/python/gunicorn/uvicorn_worker.py- Custom worker that setslog_config=Nonelibs/python/gunicorn/test_config.py- Unit tests for configuration and integrationModified Files:
libs/python/gunicorn/config.py- Added_configure_worker_logginghook, integrated withpost_worker_initparameterlibs/python/gunicorn/__init__.py- Export new worker classlibs/python/gunicorn/BUILD.bazel- Added new files, test target, and logging dependencylibs/python/gunicorn/README.md- Updated documentation with new defaultslibs/python/logging/otel_handler.py- Fixed import to work when OTEL not installedlibs/python/logging/config.py- Import OTELContextHandler inside try/except blocklibs/python/logging/__init__.py- Exportis_configuredfunctionHow It Works:
log_config=Noneto disable uvicorn's logging setuppost_forkhook callsconfigure_logging()in each worker process after forkpost_worker_initparameter for app-specific initialization (e.g., database connections)Current Defaults:
Logging Configuration Method:
Using
post_forkhook is the correct and recommended approach:logconfig_dictorlogger_classalternativespost_worker_init: logging setup (post_fork) happens before app-specific initialization (post_worker_init)Impact
✅ Backward Compatible: Existing apps automatically benefit (default worker count increased)
✅ OTLP Logs: All logs now sent via OTLP when LOG_OTLP=true
✅ Consistent Logging: Gunicorn/uvicorn logs use same config as application logs
✅ Graceful Degradation: Works without OTEL dependencies installed
✅ Better Performance: Increased workers and threads for improved concurrency
✅ Up to Date: Rebased on latest main branch
✅ Extensible: Compatible with
post_worker_initfor app-specific initializationOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.