Flask Request ID Middleware, fully customizable
This project is maintained by geoffreybauduin
A simple request id middleware for Flask.
pip install flask-request-id-middleware
from flask import Flask
from flask_request_id import RequestID
def init_app():
app = Flask(app)
RequestID(app)
return app
All your HTTP requests will include a header named (by default) “X-Request-ID” inside their responses.
def _get_request_id():
return request.environ.get("FLASK_REQUEST_ID")
RequestID(app, header_name="my-custom-header-name")
def _generate():
return "".join([random.choice("abcdef") for _ in range(12)])
RequestID(app, generator_func=_generator)
Feel free to open a PR or an issue if you feel like discussing about something.
To launch unit tests:
tox
MIT License
Copyright (c) 2017 Geoffrey Bauduin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.