8000 ref(logging): Clarify separate warnings case is for Python <3.11 by szokeasaurusrex · Pull Request #4296 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

ref(logging): Clarify separate warnings case is for Python <3.11 #4296

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

szokeasaurusrex
Copy link
Member

The way the code was written before this change made it look like log records from the warnings module were always being handled by a separate code path. In fact, this separate path is only used for Python 3.10 and below.

This change makes it clear that the branch is version specific. That way, when we eventually stop supporting 3.10, it is clear that we can delete this separate block.

Depends on:

@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner April 15, 2025 08:54
@szokeasaurusrex szokeasaurusrex requested review from antonpirker and sentrivana and removed request for a team April 15, 2025 08:54
Copy link
codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.52%. Comparing base (296e288) to head (caa7c3a).
Report is 3 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4296      +/-   ##
==========================================
- Coverage   79.54%   79.52%   -0.03%     
==========================================
  Files         142      142              
  Lines       15907    15907              
  Branches     2722     2721       -1     
==========================================
- Hits        12654    12650       -4     
- Misses       2389     2391       +2     
- Partials      864      866       +2     
Files with missing lines Coverage Δ
sentry_sdk/integrations/logging.py 83.11% <100.00%> (+0.22%) ⬆️

... and 3 files with indirect coverage changes

}

if (
sys.version_info < (3, 11)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this additional version check does not change actual behavior. In Python 3.11+, record.msg contains the actual warning message, so the later on record.msg == "%s" check would fail. Adding this version check just makes it more obvious that this code path only exists for older Python versions

Base automatically changed from szokeasaurusrex/formatted-logging to master April 15, 2025 09:17
Copy link
Contributor
@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it's risky to touch old working code because we might end up breaking unexpected things -- can we maybe instead of updating the logic rename the record_captured_from_warnings_module and/or add a comment?

The way the code was written before this change made it look like log records from the `warnings` module were always being handled by a separate code path. In fact, this separate path is only used for Python 3.10 and below.

This change makes it clear that the branch is version specific. That way, when we eventually stop supporting 3.10, it is clear that we can delete this separate block.

Depends on:
  - #4292
  - #4291
8000
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/logging-warnings-refactor branch from 0501ee7 to caa7c3a Compare April 15, 2025 10:15
@szokeasaurusrex
Copy link
Member Author

In general it's risky to touch old working code because we might end up breaking unexpected things

Generally agree with your point here, but after removing the len(record.args) == 1 check, I think this should be okay to do.

Besides removing the record_captured_from_warnings_module and adding a comment, effectively there are only two behavioral changes in this PR:

  • The explicit Python version check. This should be a safe change, since we can trace back the change in Python's behavior to bpo-46557: Log captured warnings without format string (GH-30975) python/cpython#30975 and we have tests which verify logging warnings work.
    • I suppose this change is in CPython, maybe other Python interpreters would not have it, but I am not sure whether we typically consider that use case
  • Calling to_string on record.msg for warning messages: Likely we should have been doing this anyways to ensure that the value we send to Sentry is a string.

@antonpirker antonpirker merged commit b2693f4 into master Apr 15, 2025
138 checks passed
@antonpirker antonpirker deleted the szokeasaurusrex/logging-warnings-refactor branch April 15, 2025 10:43
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.

3 participants
0