Skip to content

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

Closed

Description

@thatch

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')

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 9, 2025
  2. szokeasaurusrex commented on Apr 11, 2025

    @szokeasaurusrex
    Member

    Thanks for the report, we will investigate

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 11, 2025
  4. szokeasaurusrex commented on Apr 14, 2025

    @szokeasaurusrex
    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.

  5. added 2 commits that reference this issue on Apr 14, 2025
    f327c77
    e71ccbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions