Skip to content

feat(logs): Add user attributes to logs #4423

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
Jun 5, 2025

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review May 28, 2025 16:18
@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner May 28, 2025 16:18
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.64%. Comparing base (c2d5a76) to head (076e4d1).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/client.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4423      +/-   ##
==========================================
- Coverage   80.67%   80.64%   -0.03%     
==========================================
  Files         142      142              
  Lines       15982    15986       +4     
  Branches     2729     2732       +3     
==========================================
- Hits        12893    12892       -1     
- Misses       2232     2238       +6     
+ Partials      857      856       -1     
Files with missing lines Coverage Δ
sentry_sdk/client.py 79.49% <75.00%> (-0.04%) ⬇️

... and 4 files with indirect coverage changes

@@ -927,6 +927,20 @@ def _capture_experimental_log(self, current_scope, log):
elif propagation_context is not None:
log["trace_id"] = propagation_context.trace_id

if self.should_send_default_pii() and isolation_scope._user is not None:
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we also check the global and current scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should not be necessary. User should always only be set on the isolation scope:

def set_user(value):
# type: (Optional[Dict[str, Any]]) -> None
return get_isolation_scope().set_user(value)

I checked the (few) places we manually call set_user on a scope, these also use the isolation scope only.

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/logs-user-attributes branch 2 times, most recently from a903eb6 to 285abb0 Compare June 3, 2025 12:25
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/logs-user-attributes branch from 285abb0 to 076e4d1 Compare June 5, 2025 12:47
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

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

looks good.

@szokeasaurusrex szokeasaurusrex merged commit a662a9d into master Jun 5, 2025
136 of 137 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/logs-user-attributes branch June 5, 2025 13:39
szokeasaurusrex added a commit that referenced this pull request Jun 5, 2025
We are always just using the current scope anyway; it is less confusing
if we eliminate the parameter

Stacked on:
  - #4423
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.

Add user attributes to Python logs
3 participants