Skip to main content

Flask-Log-Request-Id

Flask-Log-Request-Id is an extension for Flask that can parse and handle the request-id sent by request processors like Amazon ELB, Heroku Request-ID or any multi-tier infrastructure as the one used at microservices. A common usage scenario is to inject the request_id in the logging system so that all log records, even those emitted by third party libraries, have attached the request_id that initiated their call. This can greatly improve tracing and debugging of problems.

Features

Flask-Log-Request-Id provides the current_request_id() function which can be used at any time to get the request id of the initiated execution chain. It also comes with log filter to inject this information on log events as also an extension to forward the current request id into Celery’s workers.

Example: Parse request id and send it to to logging

In the following example, we will use the RequestIDLogFilter to inject the request id on all log events, and a custom formatter to print this information. If all these sounds unfamiliar please take a look at python logging system

import logging
import logging.config
from random import randint
from flask import Flask
from flask_log_request_id import RequestID, RequestIDLogFilter

def generic_add(a, b):
    """Simple function to add two numbers that is not aware of the request id"""
    logging.debug('Called generic_add({}, {})'.format(a, b))
    return a + b

app = Flask(__name__)
RequestID(app)

# Setup logging
handler = logging.StreamHandler()
handler.setFormatter(
    logging.Formatter("%(asctime)s - %(name)s - level=%(levelname)s - request_id=%(request_id)s - %(message)s"))
handler.addFilter(RequestIDLogFilter())  # << Add request id contextual filter
logging.getLogger().addHandler(handler)


@app.route('/')
def index():
    a, b = randint(1, 15), randint(1, 15)
    logging.info('Adding two random numbers {} {}'.format(a, b))
    return str(generic_add(a, b))

Installation

The easiest way to install it is using pip from PyPI

pip install flask-log-request-id

License

See the LICENSE file for license rights and limitations (MIT).

Metadata

Release files for Flask-3-Log-Request-ID 0.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-3-Log-Request-ID 0.11.1
File Size Uploaded Provenance Actions
flask_3_log_request_id-0.11.1.tar.gz 9.6 kB Without provenance Details for flask_3_log_request_id-0.11.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Flask-3-Log-Request-ID 0.11.1
File Interpreter ABI Platform Actions
Flask_3_Log_Request_ID-0.11.1-py3-none-any.whl Python 3 none any Details for Flask_3_Log_Request_ID-0.11.1-py3-none-any.whl

Total release size: 17.9 kB

Release files / flask_3_log_request_id-0.11.1.tar.gz

Download URL flask_3_log_request_id-0.11.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
13ac27ff4c36c2d5e15ce634ce56cfee7dbf56e119d46e12fb1f86f6b428296a
BLAKE2b-256 checksum
How to use checksums
e3e68c390f1ed4762767f7024704a39afcbf023457915b1e2db90b33447f07ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / Flask_3_Log_Request_ID-0.11.1-py3-none-any.whl

Download URL Flask_3_Log_Request_ID-0.11.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d95b4d009f5b504200d4fdeb60f37fa3232d693f6f991653707ecbccd6e8283
BLAKE2b-256 checksum
How to use checksums
a635c1fd02fceb60e870e8a6266dd7ff3eb1e41401b4e9031bb9269e33b4d9ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Security for Flask-3-Log-Request-ID 0.11.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page