Python Flask Middleware to log and set Request ID in the HTTP header
Project description
Flask Header Log Request ID
A Flask middleware to log and set Request ID in the HTTP header.
Overview
This project provides a Flask middleware that ensures a unique Request ID is generated and logged for each incoming request. The Request ID is also included in the response back to the client.
Features
Generates a unique Request ID for each incoming request Logs the Request ID using a log filter Includes the Request ID in the response back to the client Installation To install the middleware, run the following command:
pip install flask_header_log_request_id
Usage
To use the middleware in your Flask application, simply import and initialize it:
from flask import Flask
from flask_header_log_request_id import RequestID
app = Flask(__name__)
RequestID(app)
Configuration
The middleware can be configured using the following settings:
REQUEST_ID_UNIQUE_VALUE_PREFIX: a prefix that indicates a request ID should be considered unique
Logging
The middleware uses a log filter to inject the current request ID into log records. To use the log filter, add it to your logging configuration:
from flask_header_log_request_id.log_filter import RequestIDLogFilter
logging.basicConfig()
logger = logging.getLogger()
logger.addFilter(RequestIDLogFilter())
Example
Here is an example of how to use the middleware in a Flask application:
from flask import Flask
from flask_header_log_request_id import RequestID
app = Flask(__name__)
RequestID(app)
@app.route("/")
def index():
return "Hello, World!"
if __name__ == "__main__":
app.run()
In this example, the middleware will generate a unique Request ID for each incoming request and log it using the log filter. The Request ID will also be included in the response back to the client.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_header_log_request_id-0.1.0.tar.gz.
File metadata
- Download URL: flask_header_log_request_id-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04325902c11445191a8f022bb229445ab6dc05bbac4144fc7f648435d3d7988b
|
|
| MD5 |
696832995214efcc65e078cd02b119c8
|
|
| BLAKE2b-256 |
06b5f2be7e89d812974d7cc41ff017858989aaa4dab4ee0d77aa90fd26066fca
|
File details
Details for the file flask_header_log_request_id-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flask_header_log_request_id-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4860b2429e6abb9332031c85eb9d7f880247db9e964024039937a6631117d702
|
|
| MD5 |
b5a032f094a044c2c17b59f06bfb9fca
|
|
| BLAKE2b-256 |
d373fc96a720f7e55db7da526c2502963b9b78b0f3baaa9654a18c44e072e2df
|