Installation
Install Metlo from PyPI:Quick Start
Integrate Metlo by wrapping your Flask app:Configuration
Required Parameters
TheMetloFlask class takes the following required parameters:
Your Flask application instance
The URL of your Metlo collector instance (e.g.,
https://collector.metlo.com)Must be a valid HTTP or HTTPS URL.Your Metlo API key for authentication with the collector
Optional Parameters
You can pass additional configuration as keyword arguments:Maximum number of worker threads for asynchronous communication with Metlo
Disable Metlo without removing the initialization code
Example with Optional Parameters
How It Works
Metlo registers anafter_request hook that:
- Executes after your view - Captures the final response
- Extracts request/response data - Headers, body, query parameters
- Asynchronous transmission - Sends data to Metlo using ThreadPoolExecutor
- Returns response unchanged - Your application continues normally
Captured Data
For each request, Metlo captures: Request:- URL (host, path, query 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/flask - Request/response timestamp
Full Example Application
Environment Variables
For security, store your API key in environment variables:Flask Blueprints
Metlo works seamlessly with Flask Blueprints:Flask-RESTful Integration
Request Body Parsing
Metlo captures request bodies fromrequest.data. For JSON requests, Flask automatically makes the parsed data available via request.get_json(), but Metlo captures the raw body.
Troubleshooting
Metlo not capturing requests
Metlo not capturing requests
Verify that:
MetloFlask()is called with your Flask app instance- Your collector URL is correct and accessible
- Your API key is valid
- Check Flask logs for Metlo warnings
Invalid host scheme error
Invalid host scheme error
The collector URL must start with
http:// or https://. Example: https://collector.metlo.com (not collector.metlo.com)Missing parameter errors
Missing parameter errors
Ensure all three required parameters are provided:
- Flask app instance
- Metlo collector URL (string)
- Metlo API key (string)
Performance impact
Performance impact
Metlo uses ThreadPoolExecutor for asynchronous communication. Increase the
workers parameter if you have high traffic volume.Host Detection
Metlo attempts to detect the destination host from multiple sources:HTTP_HOSTheaderHTTP_X_FORWARDED_FORheader (for proxied requests)REMOTE_ADDRenvironment variable
Requirements
- Python >= 3.6
- Flask >= 0.10
Performance Considerations
- Non-blocking - Metlo uses ThreadPoolExecutor for asynchronous transmission
- After request hook - Runs after your view, doesn’t slow down processing
- Configurable workers - Adjust based on traffic volume
Next Steps
View APIs
Discover your Flask API endpoints
Security Testing
Run automated security tests