Skip to content

Feature: async-safe context via contextvars, with a context manager #21

Closed

Description

@markbac

threading.local does not follow context across asyncio tasks. Switch to contextvars.ContextVar and offer a context manager:

with log_context(request_id="abc"):
    logger.info("handled")

The manager should restore the previous values on exit, including on exceptions. This also gives a clean replacement for the current with_context() behaviour.


Generated by Claude Code

Activity

  1. markbac commented on Oct 3, 2026

    @markbac
    OwnerAuthor

    Work started on branch feat/21-contextvars.


    Generated by Claude Code

  2. markbac commented on Oct 3, 2026

    @markbac
    OwnerAuthor

    Fixed in #52 and merged to main.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions