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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

❌ 47 Tests Failed:

Tests completed Failed Passed Skipped
24190 47 24143 5821
View the top 3 failed test(s) by shortest run time
tests.integrations.asyncio.test_asyncio::test_exception
Stack Traces | 0.001s run time
async def functions are not natively supported.
You need to install a suitable plugin for your async framework, for example:
  - anyio
  - pytest-asyncio
  - pytest-tornasync
  - pytest-trio
  - pytest-twisted
tests.test_crons::test_contextmanager_error_async
Stack Traces | 0.001s run time
async def functions are not natively supported.
You need to install a suitable plugin for your async framework, for example:
  - anyio
  - pytest-asyncio
  - pytest-tornasync
  - pytest-trio
  - pytest-twisted
tests.test_crons::test_decorator_async
Stack Traces | 0.001s run time
async def functions are not natively supported.
You need to install a suitable plugin for your async framework, for example:
  - anyio
  - pytest-asyncio
  - pytest-tornasync
  - pytest-trio
  - pytest-twisted

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@@ -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 from 747f0f3 to a903eb6 Compare June 3, 2025 12:23
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/logs-user-attributes branch from a903eb6 to 285abb0 Compare June 3, 2025 12:25
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
2 participants