Flask-Request-ID-Header is a Python Flask middleware designed to ensure that all incoming requests to a Flask application include an `X-Request-ID` header, containing at least one unique value. This is particularly useful for request tracing and correlation in distributed systems and logging. The current version is 0.1.1, and the project has not seen active development since its last release in March 2019, indicating a maintenance-only status.
pip install flask-request-id-headerVerified import paths — ran on the pinned version, not inferred.
Initializes a Flask app and applies the RequestID middleware. It then defines a simple route to demonstrate how to retrieve the `X-Request-ID` header from the request.
No direct fix needed for current functionality, but be aware of evolving HTTP header conventions.
Set `app.config['REQUEST_ID_UNIQUE_VALUE_PREFIX'] = 'YOUR_PREFIX-'` to prevent modification of headers starting with 'YOUR_PREFIX-'.
Manually configure a `logging.Filter` to inject `request.headers.get('X-Request-ID')` into log records.Ensure the package is installed: `pip install flask-request-id-header`. Verify the import statement matches the correct path.
Access the header within a request context (e.g., inside a route function, a `before_request` handler, or using `app.test_request_context()`). Use `request.headers.get('X-Request-ID', 'default_value')` to safely retrieve the header without raising a `KeyError` if it might be missing in certain scenarios.Access the request ID directly from the request headers dictionary: `request.headers.get('X-Request-ID')`.