Skip to main content
https://github.com/cjrh/aiologfields/workflows/Python%20application/badge.svg https://coveralls.io/repos/github/cjrh/aiologfields/badge.svg?branch=master https://img.shields.io/pypi/pyversions/aiologfields.svg https://img.shields.io/github/tag/cjrh/aiologfields.svg https://img.shields.io/badge/install-pip%20install%20aiologfields-ff69b4.svg https://img.shields.io/pypi/v/aiologfields.svg https://img.shields.io/badge/calver-YYYY.MM.MINOR-22bfda.svg Downloads This project uses the "black" style formatter for Python code

aiologfields

aiologfields makes it easy to include correlation IDs, as well as other contextual information into log messages, across await calls and loop.create_task() calls. Correlation IDs are critically important for accurate telemetry in monitoring and debugging distributed microservices.

Instructions

It couldn’t be easier:

aiologfields.install()

After this, every single task created will have a logging_fields attribute. To add a field to a LogRecord, simply apply it to any task:

t = loop.create_task(coro)
t.logging_fields.correlation_id = '12345'

If you’re using a logging handler that produces JSON output (like logjson!), or some other formatter that produces output with all fields in the LogRecord, you will find that each record within the context of the task will include an additional field called correlation_id with a value of 12345.

Demo

This is adapted from one of the tests:

aiologfields.install()
correlation_id = str(uuid4())
logger = logging.getLogger('blah')

async def cf2():
    logger.info('blah blah')

async def cf1():
    ct = asyncio.Task.current_task()
    ct.logging_fields.correlation_id = correlation_id
    await cf2()

loop.run_until_complete(cf1())

In the LogRecord produced inside cf2(), an additional field correlation_id is included, even though the field was set in coroutine function cf1().

It would also have worked if cf2() had been executed in a separate task itself, since the logging_fields namespace is copied between nested tasks.

Metadata

Release files for aiologfields 2019.12.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 aiologfields 2019.12.1
File Size Uploaded Provenance
aiologfields-2019.12.1.tar.gz 9.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiologfields 2019.12.1
File Interpreter ABI Platform
aiologfields-2019.12.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.9 kB

Release files / aiologfields-2019.12.1.tar.gz

Download URL aiologfields-2019.12.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5418c4d3abea53036e5cdcd6b4e18fac48f894c0b2294e4e5b25eed4fdb3d1c6
BLAKE2b-256 checksum
How to use checksums
0645a04e2fbd10a2abcbd1da685629966321aa22abcd72ae1636e1aa1c901237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / aiologfields-2019.12.1-py2.py3-none-any.whl

Download URL aiologfields-2019.12.1-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d11b0f9a074493741d02fb3aebac1dc0c8e7b0defd53da6babc0243545c95284
BLAKE2b-256 checksum
How to use checksums
f6a17479f08c643cf63708a44b70e028684a39e55c3ce80c695323a7a5e6263a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Security for aiologfields 2019.12.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.

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