Skip to content

Group captured warnings under separate issues#1324

Merged
sl0thentr0py merged 10 commits into
getsentry:masterfrom
mnito:refine_captured_warnings_issue_grouping
Feb 15, 2022
Merged

Group captured warnings under separate issues#1324
sl0thentr0py merged 10 commits into
getsentry:masterfrom
mnito:refine_captured_warnings_issue_grouping

Conversation

@mnito

@mnito mnito commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

Prior to https://bugs.python.org/issue46557 being addressed, warnings captured by logging.captureWarnings(True) were logged with logger.warning("%s", s) which caused them to be grouped under the sameissue. This change adds special handling for creating separate issues for captured warnings arriving with the %s format string by using args[0] as the message instead of the msg arg.

Refer to: https://docs.python.org/3/library/logging.html#logging.captureWarnings

@sl0thentr0py
sl0thentr0py self-requested a review January 31, 2022 13:08
@mnito
mnito force-pushed the refine_captured_warnings_issue_grouping branch 2 times, most recently from d08cfb1 to 31df6c5 Compare February 3, 2022 13:53
@antonpirker

antonpirker commented Feb 4, 2022

Copy link
Copy Markdown
Contributor

Hey @mnito thanks for the easy to review PR!

As I understand it: this PR makes sure, that our LoggingIntegration catches warnings issued by the warnings python module when logging.captureWarnings(True) is set. Which makes sense.

Comment thread sentry_sdk/integrations/logging.py Outdated
Comment thread tests/integrations/logging/test_logging.py
@mnito
mnito force-pushed the refine_captured_warnings_issue_grouping branch from 31df6c5 to 1bf01ad Compare February 5, 2022 13:08
@mnito
mnito requested a review from antonpirker February 5, 2022 13:10
Prior to https://bugs.python.org/issue46557 being addressed, warnings
captured by logging.captureWarnings(True) were logged with
logger.warning("%s", s) which caused them to be grouped under the same
issue. This change adds special handling for creating separate issues
for captured warnings arriving with the %s format string by using
args[0] as the message instead of the msg arg.

Refer to:
https://docs.python.org/3/library/logging.html#logging.captureWarnings
@mnito
mnito force-pushed the refine_captured_warnings_issue_grouping branch from 1bf01ad to dc1c7fd Compare February 5, 2022 13:26
@antonpirker

Copy link
Copy Markdown
Contributor

@mnito I have made some cosmetic changes to your branch to make it more readable

@antonpirker

Copy link
Copy Markdown
Contributor

I have one question @mnito can we check for messages from warnings module in another way other than record.msg == "%s"? This feels a little bit unstable to check for "%s" in the message

@mnito

mnito commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

I have one question @mnito can we check for messages from warnings module in another way other than record.msg == "%s"? This feels a little bit unstable to check for "%s" in the message

Maybe the intent isn’t clear here, but the check for “%s” is important to this change. Even before this change, logged warnings were always captured by the Sentry SDK — however they are grouped under a single issue due to “%s” always being the logged string and the actual message being the first arg (this behavior is within CPython’s logging library). I changed that behavior in an approved change to CPython itself, but this change is a workaround for Python versions that won’t have that change since it likely won’t be backported.

@antonpirker

Copy link
Copy Markdown
Contributor

Thanks for the clarification @mnito! Now I get it! If all the checks pass we can merge this!

@antonpirker antonpirker self-assigned this Feb 9, 2022
@antonpirker

Copy link
Copy Markdown
Contributor

@mnito could you format the logging.py file so our CI won't complain? Thanks!

See:
https://github.com/getsentry/sentry-python/runs/5126865254?check_suite_focus=true

@mnito

mnito commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

Yeah I can take care of it at lunchtime. If you are motivated to get it through now you should just be able to run black on the file to reformat it which will prevent black —check from failing in that lint task

@mnito

mnito commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

@mnito could you format the logging.py file so our CI won't complain? Thanks!

See: https://github.com/getsentry/sentry-python/runs/5126865254?check_suite_focus=true

Done ✅

@mnito

mnito commented Feb 10, 2022

Copy link
Copy Markdown
Contributor Author

@mnito could you format the logging.py file so our CI won't complain? Thanks!
See: https://github.com/getsentry/sentry-python/runs/5126865254?check_suite_focus=true

Done ✅

Fixed the mypy failure as well ✅

@antonpirker

Copy link
Copy Markdown
Contributor

Uh yeah! 👍
Thanks a lot!

@sl0thentr0py
sl0thentr0py enabled auto-merge (squash) February 15, 2022 11:11
@sl0thentr0py
sl0thentr0py merged commit c927d34 into getsentry:master Feb 15, 2022
@antonpirker

Copy link
Copy Markdown
Contributor

This is merged now @mnito Thanks for your contribution! It will be released with the next version of the SDK (probably in 1-2 weeks)

@mnito

mnito commented Feb 18, 2022

Copy link
Copy Markdown
Contributor Author

Sounds good. Thanks!

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