fix(log): preserve loguru context in stdlib intercept - #112
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
olivermeyer
marked this pull request as ready for review
July 28, 2026 08:50
Codecov Report✅ All modified and coverable lines are covered by tests.
|
|
idelsink
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why?
Stdlib log records emitted inside
logger.contextualize()were silently losing all bound context fields — including base-config keys likeproject_nameandversion— becauseInterceptHandler.emitoverwrote loguru's assembledextradict with the stdlib record's own (usually empty)extra. This meant Stargate internal log lines could not be correlated to a pvizjob_ideven when emitted in the correct contextualize scope.How?
Changed the patcher body from assignment (
record_dict["extra"] = ...) torecord_dict["extra"].update(...), preserving loguru's assembled context and layering stdlib's ownextraon top (stdlib-wins on key collision). Updated theInterceptHandlerdocstring to document the contextvars propagation behaviour acrossasyncio.to_threadvs bare threads. Three regression tests cover the core fix, the base-context guard, and native/stdlib parity.