
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
flask-header-log-request-id
Advanced tools
Python Flask Middleware to log and set Request ID in the HTTP header
A Flask middleware to log and set Request ID in the HTTP header.
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.
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
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)
The middleware can be configured using the following settings:
REQUEST_ID_UNIQUE_VALUE_PREFIX
: a prefix that indicates a request ID should be considered uniqueThe 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())
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.
FAQs
Python Flask Middleware to log and set Request ID in the HTTP header
We found that flask-header-log-request-id demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.