A lightweight, high-performance Application Performance Monitoring (APM) solution for FastAPI, designed to catch, log, and report errors in real-time to Telex. This integration ensures that unhandled exceptions are immediately logged and reported, facilitating faster debugging and improved system reliability.
- Global Error Handling: Captures unhandled exceptions across all FastAPI routes.
- Real-time Reporting: Sends instant notifications to Telex upon error occurrence.
- Asynchronous Logging: Utilizes background tasks for non-blocking error logging.
- Detailed Error Information: Logs comprehensive error details, including stack traces and request metadata.
- Easy Deployment: Docker and Nginx configurations for seamless production deployment.
fastapi-apm/
├── .github/
│ └── workflows/
│ ├── deploy.yml # GitHub Actions deployment configuration
│ └── keepalive.yml # Keepalive Deployment configuration for Render
├── api/
│ ├── __init__.py
│ └── routes/
│ ├── __init__.py
│ ├── integration_config.py # Integration configuration for Telex
│ └── routes.py # Example route handlers to trigger error
├── apm/
│ ├── __init__.py
│ ├── background_worker.py # Asynchronous error logging
│ └── error_handler.py # Global error handler
├── core/
│ ├── __init__.py
│ └── config.py # Application configuration settings
├── nginx/
│ └── default.conf # Nginx configuration file
├── .gitignore
├── Dockerfile # Docker image configuration
├── README.md
├── docker-compose.yml # Docker Compose configuration
├── main.py # Application entry point
├── requirements.txt # Python dependencies
├── start.sh # Startup script
└── vercel.json # Vercel deployment configuration
-
Clone the repository:
git clone https://github.com/telexintegrations/fastapi-apm.git cd fastapi-apm
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.env
file in the root directory with the following content:TELEX_WEBHOOK_URL=https://ping.telex.im/v1/webhooks/YOUR-WEBHOOK-ID
Replace
YOUR-WEBHOOK-ID
with your actual Telex webhook ID. -
Ensure log directory exists:
Before running the application, ensure that the
apm/logs
directory exists:mkdir -p apm/logs
Start the server:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
To trigger an error, you can send a GET request to https://fastapi-apm.onrender.com/test-fail and the error will be caught and get logged in the fastapi-apm
channel on Telex test organization
-
Build and run the container:
docker-compose up -d --build
-
Check logs:
docker logs -f fastapi-apm
- Deploy the application to Vercel using the provided
vercel.json
configuration.
GET /test-fail
- Example endpoint
The application includes a global error handler that:
- Catches unhandled exceptions across all routes.
- Logs error details asynchronously.
- Sends error notifications to the configured Telex channel.
-
Fork the repository.
-
Create a feature branch:
git checkout -b feature/YourFeatureName
-
Commit your changes:
git commit -m 'Add YourFeatureName'
-
Push to the branch:
git push origin feature/YourFeatureName
-
Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
For support, please open an issue in the GitHub repository.