Skip to content

Log formatting with %s now can't output dicts #4267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thatch opened this issue Apr 9, 2025 · 3 comments · Fixed by #4291
Closed

Log formatting with %s now can't output dicts #4267

thatch opened this issue Apr 9, 2025 · 3 comments · Fixed by #4291
Assignees
Labels

Comments

@thatch
Copy link

thatch commented Apr 9, 2025

How do you use Sentry?

Self-hosted/on-premise

Version

2.23.0+

Steps to Reproduce

We've observed cases in open source where a dict is passed positionally to a logging call. A recent change in sentry means that params loses its dict-ness and is only keys by the time it gets to before_send. This can result in "format requires a mapping" or "not all arguments converted during string formatting" exceptions.

Use the following script: repro.txt

We're fairly certain that this comes from the change in 4c9731b which iterates the dict giving only the keys.

Examples where this pattern is used:

Expected Result

Run it with sentry-sdk==2.22.0 and it works fine:

$ python repro.py                  
INFO:test-logger:test {'hello': 'world', 'foo': 'bar'}
INFO:test-logger:test world

Actual Result

If you run it with sentry-sdk==2.23.1 or newer, it's broken:

$ python repro.py
INFO:test-logger:test {'hello': 'world', 'foo': 'bar'}
WARNING:sentrybugrepro:Failed to set formatted message for '{'message': 'test %s', 'params': ['hello', 'foo']}'. exception: TypeError('not all arguments converted during string formatting')
INFO:test-logger:test world
WARNING:sentrybugrepro:Failed to set formatted message for '{'message': 'test %(hello)s', 'params': ['hello', 'foo']}'. exception: TypeError('format requires a mapping')
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 9, 2025
@thatch
Copy link
Author

thatch commented Apr 9, 2025

@szokeasaurusrex
Copy link
Member

Thanks for the report, we will investigate

@szokeasaurusrex
Copy link
Member

@thatch thanks for the report.

It indeed looks like the Python SDK stopped sending dictionary values with logging events sometime after 2.22.0. I agree, 4c9731b seems like the likeliest cause.

@szokeasaurusrex szokeasaurusrex added the Bug label Apr 14, 2025 — with Linear
@szokeasaurusrex szokeasaurusrex self-assigned this Apr 14, 2025
szokeasaurusrex added a commit that referenced this issue Apr 14, 2025
This reverts commit 4c9731b.

That commit caused a regression when `record.args` contains a dictionary. Because we iterate over `record.args`, that change caused us to only send the dictionary's keys, not the values.

A more robust fix for #3660 will be to send the formatted message in the [`formatted` field](https://develop.sentry.dev/sdk/data-model/event-payloads/message/) (which we have not been doing yet). I will open a follow-up PR to do this.

Fixes #4267
@stephanie-anderson stephanie-anderson added the Python SDK label Apr 25, 2025 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants