Skip to content

fix(log): preserve loguru context in stdlib intercept - #112

Merged
olivermeyer merged 1 commit into
mainfrom
fix/intercept-extra-merge
Jul 28, 2026
Merged

fix(log): preserve loguru context in stdlib intercept#112
olivermeyer merged 1 commit into
mainfrom
fix/intercept-extra-merge

Conversation

@olivermeyer

Copy link
Copy Markdown
Collaborator

Why?
Stdlib log records emitted inside logger.contextualize() were silently losing all bound context fields — including base-config keys like project_name and version — because InterceptHandler.emit overwrote loguru's assembled extra dict with the stdlib record's own (usually empty) extra. This meant Stargate internal log lines could not be correlated to a pviz job_id even when emitted in the correct contextualize scope.

How?
Changed the patcher body from assignment (record_dict["extra"] = ...) to record_dict["extra"].update(...), preserving loguru's assembled context and layering stdlib's own extra on top (stdlib-wins on key collision). Updated the InterceptHandler docstring to document the contextvars propagation behaviour across asyncio.to_thread vs bare threads. Three regression tests cover the core fix, the base-context guard, and native/stdlib parity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@olivermeyer
olivermeyer marked this pull request as ready for review July 28, 2026 08:50
@olivermeyer
olivermeyer requested a review from a team as a code owner July 28, 2026 08:50
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
src/aignostics_foundry_core/log.py 93.18% <100.00%> (ø)

@sonarqubecloud

Copy link
Copy Markdown

@olivermeyer
olivermeyer merged commit ebdee11 into main Jul 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants