Skip to content

Fix missing user attributes on logs#1864

Merged
cleptric merged 2 commits intomasterfrom
user-log-attributes
Jun 20, 2025
Merged

Fix missing user attributes on logs#1864
cleptric merged 2 commits intomasterfrom
user-log-attributes

Conversation

@cleptric
Copy link
Copy Markdown
Member

@cleptric cleptric commented Jun 17, 2025

We didn't include various user attributes on log messages. If a user was set on the scope, the id, username and email are now being attached.

@cleptric cleptric self-assigned this Jun 17, 2025
@cleptric cleptric requested review from Copilot and stayallive June 17, 2025 01:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the missing user attributes on log messages by ensuring that, if a user is set on the event, the log payload now includes the user's id, email, and username. Furthermore, the change refactors the serializer to rely on event properties (such as environment, release, and server name) instead of duplicating these values in the log aggregator.

  • Updated test case to validate presence of new user attributes.
  • Enhanced the envelope serializer to attach environment, release, server, and user attributes.
  • Removed redundant attribute assignments from the LogsAggregator, relying on the event properties.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/Serializer/PayloadSerializerTest.php Updated test expectations to include the new user attributes in the log payload.
src/Serializer/EnvelopItems/LogsItem.php Refactored to map additional event properties (environment, release, server name) and user attributes.
src/Logs/LogsAggregator.php Removed explicit setting of several attributes now handled in the envelope serializer.
Comments suppressed due to low confidence (2)

src/Logs/LogsAggregator.php:75

  • Removal of explicit log attributes (release, environment, and server address) is intentional since these are now sourced from event properties in the serializer. Please confirm that omitting these in the aggregator does not remove any necessary context when event properties are not set.
->setAttribute('sentry.release', $options->getRelease())

src/Serializer/EnvelopItems/LogsItem.php:58

  • [nitpick] The user attribute key is set as 'user.name' based on getUsername(), which is acceptable; please ensure this naming convention is consistent with other parts of the codebase and documentation.
if ($user->getUsername() !== null) {

@cleptric cleptric force-pushed the user-log-attributes branch from 73a9c45 to d654cdd Compare June 20, 2025 00:35
@cleptric cleptric merged commit 28bf0ce into master Jun 20, 2025
38 checks passed
@cleptric cleptric deleted the user-log-attributes branch June 20, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants