The following functionality is now implemented:
- Middleware configuration options (header name, generator, validator, etc.).
- Header retrieval and whitespace normalization.
- Trusted source IP/CIDR matching.
- Default UUIDv7 generator implementation.
- Automatic correlation ID generation for requests without valid incoming IDs.
- Custom generator injection support.
- Default UUID validator for incoming ID format validation.
- Validation integration into request processing: incoming IDs from trusted
sources are validated (when a validator is configured) before acceptance, with
DEBUG-level logging of failures. - Context variables (
correlation_id_varanduser_id_var) for request-scoped storage viacontextvars. - Correlation ID context variable lifecycle management:
correlation_id_varis set during request processing and reset during response cleanup. - Dual access to the correlation ID via
req.context.correlation_idandcorrelation_id_var.get(), both always in sync during request handling. ContextualLogFilterfor injecting correlation ID and user ID into standard library log records, with"-"placeholder when context is not set. Pre-existing record attributes (e.g. fromextra=) are preserved.RECOMMENDED_LOG_FORMATconstant providing a ready-made format string for use withlogging.FormatterordictConfig.- Structlog integration documentation with custom processor and
bind_contextvarsbridging approaches (task 3.2). - httpx propagation wrapper functions (
request_with_correlation_idandasync_request_with_correlation_id) for injecting the correlation ID into outgoing HTTP requests (task 4.1.1). - httpx transport classes (
CorrelationIDTransportandAsyncCorrelationIDTransport) for shared client configuration that injects the correlation ID into outgoing HTTP requests (task 4.1.2). - Celery publish propagation via
propagate_correlation_id_to_celery, which injects the ambient request correlation ID into outgoing task message properties (task 4.2.1).
See the roadmap for the full implementation plan.