Installation
Install Metlo from PyPI:Quick Start
Add middleware
Add Metlo’s middleware to your
MIDDLEWARE list in settings.py:The middleware can be placed anywhere in the list, but placing it last ensures it captures the final response.
Configuration
Required Settings
Your Metlo API key for authentication with the collector
The URL of your Metlo collector instance (e.g.,
https://collector.metlo.com)Must be a valid HTTP or HTTPS URL.Optional Settings
Maximum number of worker threads for asynchronous communication with Metlo
Disable Metlo middleware without removing it from settings
Example Configuration
How It Works
The Django middleware:- Processes each request - Django calls the middleware for every incoming request
- Captures request data - Headers, body, query parameters, method
- Calls view - Your view function executes normally
- Captures response data - Status code, headers, response body
- Asynchronous transmission - Sends data to Metlo using ThreadPoolExecutor
Captured Data
For each request, Metlo captures: Request:- URL (host, path, query/POST parameters)
- HTTP method
- Headers
- Request body (decoded as UTF-8)
- Source IP and port
- Status code
- Headers
- Response body (decoded as UTF-8)
- Destination IP and port
- Environment:
production - Source identifier:
python/django - Request/response timestamp
Example Django Project
settings.py
views.py
Environment Variables
For security, use environment variables for sensitive configuration:Django REST Framework
Metlo works seamlessly with Django REST Framework:Troubleshooting
Middleware not capturing requests
Middleware not capturing requests
Verify that:
metlo.django.MetloDjangois in yourMIDDLEWARElistMETLO_CONFIGis properly defined insettings.py- Both
API_KEYandMETLO_HOSTare set - Check Django logs for Metlo warnings
Invalid host scheme error
Invalid host scheme error
Ensure
METLO_HOST starts with http:// or https://. Example: https://collector.metlo.comMissing configuration error
Missing configuration error
If you see “METLO_CONFIG is missing…” errors, check that your
settings.py includes both API_KEY and METLO_HOST in the METLO_CONFIG dictionary.Source port detection
Source port detection
The middleware attempts multiple methods to detect the source port. In some deployment scenarios (e.g., behind proxies), this may not be available.
Performance Considerations
- ThreadPoolExecutor - Metlo uses Python’s
ThreadPoolExecutorfor asynchronous communication - Non-blocking - Request/response processing is not blocked by Metlo
- Configurable workers - Adjust the
workerssetting based on your traffic volume
Requirements
- Python >= 3.6
- Django >= 2.0
Next Steps
API Discovery
View your automatically discovered Django APIs
Sensitive Data
Detect PII and sensitive data in your APIs