Skip to content

refactor(logs): apply user attributes to log regardless of send_default_pii #843

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 3 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Breaking changes

- refactor(logs): apply user attributes to log regardless of `send_default_pii` (#843) by @lcian
- User attributes should be applied to logs regardless of `send_default_pii`. Therefore, that parameter was removed from `sentry_core::Scope::apply_to_log`.

### Features

- feat(tracing): add support for logs (#840) by @lcian
Expand All @@ -16,7 +21,6 @@
});
```


### Fixes

- fix(logs): send environment in `sentry.environment` default attribute (#837) by @lcian
Expand Down
2 changes: 1 addition & 1 deletion sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl Client {
/// processing it through `before_send_log`.
#[cfg(feature = "logs")]
fn prepare_log(&self, mut log: Log, scope: &Scope) -> Option<Log> {
scope.apply_to_log(&mut log, self.options.send_default_pii);
scope.apply_to_log(&mut log);

self.set_log_default_attributes(&mut log);

Expand Down
38 changes: 18 additions & 20 deletions sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl Scope {
/// Applies the contained scoped data to a log, setting the `trace_id` and certain default
/// attributes.
#[cfg(feature = "logs")]
pub fn apply_to_log(&self, log: &mut Log, send_default_pii: bool) {
pub fn apply_to_log(&self, log: &mut Log) {
if let Some(span) = self.span.as_ref() {
log.trace_id = Some(span.get_trace_context().trace_id);
} else {
Expand All @@ -373,29 +373,27 @@ impl Scope {
}
}

if send_default_pii {
if let Some(user) = self.user.as_ref() {
if !log.attributes.contains_key("user.id") {
if let Some(id) = user.id.as_ref() {
log.attributes
.insert("user.id".to_owned(), LogAttribute(id.to_owned().into()));
}
if let Some(user) = self.user.as_ref() {
if !log.attributes.contains_key("user.id") {
if let Some(id) = user.id.as_ref() {
log.attributes
.insert("user.id".to_owned(), LogAttribute(id.to_owned().into()));
}
}

if !log.attributes.contains_key("user.name") {
if let Some(name) = user.username.as_ref() {
log.attributes
.insert("user.name".to_owned(), LogAttribute(name.to_owned().into()));
}
if !log.attributes.contains_key("user.name") {
if let Some(name) = user.username.as_ref() {
log.attributes
.insert("user.name".to_owned(), LogAttribute(name.to_owned().into()));
}
}

if !log.attributes.contains_key("user.email") {
if let Some(email) = user.email.as_ref() {
log.attributes.insert(
"user.email".to_owned(),
LogAttribute(email.to_owned().into()),
);
}
if !log.attributes.contains_key("user.email") {
if let Some(email) = user.email.as_ref() {
log.attributes.insert(
"user.email".to_owned(),
LogAttribute(email.to_owned().into()),
);
}
}
}
Expand Down