Troubleshooting Common Issues in Tiangolo Uvicorn-Gunicorn-FastAPI-Docker
Project Description
Tiangolo Uvicorn-Gunicorn is a pre-configured setup for running web applications using the Uvicorn web server and the Gunicorn application server. Uvicorn is a high-performance, pure-Python HTTP server based on the HTTP protocol specification, and Gunicorn is a Python WSGI HTTP Server for UNIX.
Tiangolo Uvicorn-Gunicorn is intended to be used as a production-ready web server for deploying Python web applications, such as those built with the FastAPI web framework. It is designed to be lightweight and efficient, with the goal of being able to handle high loads with minimal overhead.
To use Tiangolo Uvicorn-Gunicorn, you will need to install it in your Python environment and then specify it as the server when you deploy your application. You can then start the server using a command-line interface, and your application will be available at a specified URL.
Troubleshooting Tiangolo Uvicorn-Gunicorn-FastAPI-Docker with the Lightrun Developer Observability Platform
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
- Instantly add logs to, set metrics in, and take snapshots of live applications
- Insights delivered straight to your IDE or CLI
- Works where you do: dev, QA, staging, CI/CD, and production
Start for free today
How to do logging in a FastApi container, any logging does not appear
After much hard work and dedication, success was eventually found! To make it possible to access HTTP request info when running unicorn through gunicorn making just a few minor adjustments is all that’s needed. Append the corresponding snippet to your main.py file; then everything will be ready for use!
import logging
from fastapi.logger import logger as fastapi_logger
gunicorn_error_logger = logging.getLogger("gunicorn.error")
gunicorn_logger = logging.getLogger("gunicorn")
uvicorn_access_logger = logging.getLogger("uvicorn.access")
uvicorn_access_logger.handlers = gunicorn_error_logger.handlers
fastapi_logger.handlers = gunicorn_error_logger.handlers
if __name__ != "__main__":
fastapi_logger.setLevel(gunicorn_logger.level)
else:
fastapi_logger.setLevel(logging.DEBUG)
It has been established that our gunicorn.error logger can now handle uvicorn.access information from HTTP requests with no extra effort!
More issues from Tiangolo repos
Troubleshooting Tiangolo FastAPI | Troubleshooting Tiangolo Full Stack FastAPI and PostgreSQL | Troubleshooting Tiangolo Flask uWSGI Nginx with Docker
It’s Really not that Complicated.
You can actually understand what’s going on inside your live applications. It’s a registration form away.