Repository navigation
Treat logfire.tags passed through logging and loguru as log tags - #2550
Merged
Merged
Conversation
LogfireLoggingHandler passed every extra field to Logfire.log as an attribute, so `logfire.tags` given via loguru kwargs, `logger.bind()` or stdlib `extra=` was exported as a JSON string and overwritten by the instance's own tags. Pass it as `tags=` instead. Fixes pydantic#524
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
|
Thanks! |
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.
Fixes #524
What
LogfireLoggingHandler(and therefore the loguru handler) now passes alogfire.tagsvalue from the log record toLogfire.log(tags=...), so it is recorded the same way aslogfire.info(..., _tags=[...]).Why
As noted in #524,
logger.info('Hello {name}', name='World', **{'logfire.tags': ['foo', 'bar']})was expected to work, but the value was treated as an ordinary attribute: it was exported as the JSON string'["foo","bar"]', listed inlogfire.json_schema, and overwritten by any tags on the handler'slogfire_instance. The same happened withlogger.bind(**{'logfire.tags': [...]})and stdlibloggingwithextra={'logfire.tags': [...]}.How
emit()popslogfire.tagsfrom the filled attributes and passes it astags=, so it is merged with the instance's tags and exported as a string array. A single string is treated as one tag, as theLogfireSpan.tagssetter already does; other malformed values behave the same as they do for_tags.Before / After
logfire.tagsfor the loguru call above:'["foo","bar"]', plus alogfire.tagsentry inlogfire.json_schema('foo', 'bar'), no schema entryWith
logfire_instance=logfire.with_tags('instance'): before('instance',), after('instance', 'foo').Tests:
test_loguru_tags(kwargs andbind),test_loguru_single_string_tag,test_stdlib_logging_tags,test_stdlib_logging_single_string_tagandtest_stdlib_logging_tags_merged_with_instance_tags; all fail onmain.The structlog integration calls
Logfire.logdirectly, so it isn't covered here; happy to do that in a follow-up if you'd like.This change was written with Claude Opus 5.5 (via Claude Code) under my direction, then checked with a separate AI review pass and the relevant tests, ruff and pyright run locally. I'm responsible for it and will follow up on review.