Correlation API Reference

Correlation Context for LogEverything.

Provides async-safe, thread-safe correlation ID propagation using contextvars. This is the foundation for request tracing across middleware, transports, and dashboards.

Key Features: - ContextVar-based correlation IDs (async-safe, same pattern as indent_manager.py) - Request context propagation (method, path, client) - CorrelationFilter for automatic LogRecord injection - Thread propagation decorator for executor-based workloads

class logeverything.correlation.CorrelationFilter(name='')[source]

Bases: Filter

A logging filter that auto-injects correlation context into every LogRecord.

Adds the following attributes to each record: - correlation_id - request_method - request_path

Usage:

import logging
from logeverything.correlation import CorrelationFilter

handler = logging.StreamHandler()
handler.addFilter(CorrelationFilter())
logger = logging.getLogger("myapp")
logger.addHandler(handler)
filter(record)[source]

Inject correlation fields into the log record.

Return type:

bool

logeverything.correlation.clear_correlation()[source]

Reset all correlation state for the current context.

Return type:

None

logeverything.correlation.get_correlation_id()[source]

Get the current correlation ID.

Return type:

str

Returns:

The correlation ID, or empty string if unset.

logeverything.correlation.get_request_context()[source]

Get the current request context metadata.

Return type:

Dict[str, Any]

Returns:

Dictionary of request metadata, or empty dict if unset.

logeverything.correlation.propagate_context(func)[source]

Decorator that copies the current contextvars into a new thread.

Use this when dispatching work to concurrent.futures.ThreadPoolExecutor or threading.Thread to ensure correlation IDs follow the call.

Example:

from logeverything.correlation import propagate_context

@propagate_context
def background_task():
    # get_correlation_id() returns the caller's ID here
    ...

executor.submit(background_task)
Return type:

Callable

logeverything.correlation.set_correlation_id(cid=None)[source]

Set or auto-generate a correlation ID for the current context.

Parameters:

cid (Optional[str]) – An explicit correlation ID. If None, a 16-char hex ID is generated.

Return type:

str

Returns:

The correlation ID that was set.

logeverything.correlation.set_request_context(ctx)[source]

Set request context metadata for the current context.

Typical keys: method, path, client_ip.

Parameters:

ctx (Dict[str, Any]) – Dictionary of request metadata.

Return type:

None