Skip to content

feat(logging): Add formatted message to log events #4292

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

Send the formatted log event to Sentry in the formatted field.

This builds on #4291, providing a more robust fix for #3660.

@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner April 14, 2025 16:23
@szokeasaurusrex szokeasaurusrex requested review from antonpirker and removed request for a team April 14, 2025 16:23
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.54%. Comparing base (e71ccbf) to head (296e288).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4292      +/-   ##
==========================================
+ Coverage   79.53%   79.54%   +0.01%     
==========================================
  Files         142      142              
  Lines       15907    15907              
  Branches     2722     2722              
==========================================
+ Hits        12652    12654       +2     
  Misses       2389     2389              
+ Partials      866      864       -2     
Files with missing lines Coverage Δ
sentry_sdk/integrations/logging.py 82.89% <ø> (ø)

... and 2 files with indirect coverage changes

Send the formatted log event to Sentry in the [`formatted` field](https://develop.sentry.dev/sdk/data-model/event-payloads/message/).

This builds on #4291, providing a more robust fix for #3660.
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/formatted-logging branch from f4fafea to 296e288 Compare April 15, 2025 07:44
szokeasaurusrex added a commit that referenced this pull request Apr 15, 2025
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
Base automatically changed from szokeasaurusrex/send-raw-logging-args to master April 15, 2025 08:56
@sentrivana
Copy link
Contributor

LGTM. If you haven't yet, please double check that the example from #3660 works with this fix and also that nothing changes in Sentry wrt to how log messages are shown (except for the buggy case from #3660).

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.

^ see comment above

@szokeasaurusrex
Copy link
Member Author

szokeasaurusrex commented Apr 15, 2025

@sentrivana good idea, I will check the example from #3660 before merging.

I believe this change might affect how issues are displayed in Sentry.
Edit: On further reflection, actually this should not affect how issues are displayed, since Relay will anyways attempt to backfill a missing "formatted" message by interpolating the "message" field with the "params". So, in most cases, the "formatted" that the SDK is now sending will be the same as what Relay was previously generating.

In any case, this should not be a breaking change, since we group issues based on the "message" field, so even if the issue is displayed differently, the grouping should be unaffected.

@szokeasaurusrex
Copy link
Member Author

I tested a log with a None value, similar to #3660. The log shows as expected in Sentry.

image

@szokeasaurusrex szokeasaurusrex merged commit 296e288 into master Apr 15, 2025
137 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/formatted-logging branch April 15, 2025 09:17
szokeasaurusrex added a commit that referenced this pull request Apr 15, 2025
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
antonpirker pushed a commit that referenced this pull request Apr 15, 2025
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
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.

2 participants