From 10611445dc1d8732ce29bb87a13b656de16cd717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Mon, 10 Jul 2023 13:43:30 +0200 Subject: [PATCH] ref: Apply user field from scope to transaction event --- sentry-core/src/scope/real.rs | 6 ++++++ sentry-types/src/protocol/v7.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/sentry-core/src/scope/real.rs b/sentry-core/src/scope/real.rs index 38ef3e6b..31c55b0d 100644 --- a/sentry-core/src/scope/real.rs +++ b/sentry-core/src/scope/real.rs @@ -304,6 +304,12 @@ impl Scope { /// Applies the contained scoped data to fill a transaction. pub fn apply_to_transaction(&self, transaction: &mut Transaction<'static>) { + if transaction.user.is_none() { + if let Some(user) = self.user.as_deref() { + transaction.user = Some(user.clone()); + } + } + transaction .extra .extend(self.extra.iter().map(|(k, v)| (k.to_owned(), v.to_owned()))); diff --git a/sentry-types/src/protocol/v7.rs b/sentry-types/src/protocol/v7.rs index 71863e60..a75197d3 100644 --- a/sentry-types/src/protocol/v7.rs +++ b/sentry-types/src/protocol/v7.rs @@ -1958,6 +1958,9 @@ pub struct Transaction<'a> { /// An optional environment identifier. #[serde(default, skip_serializing_if = "Option::is_none")] pub environment: Option>, + /// Optionally user data to be sent along. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub user: Option, /// Optional tags to be attached to the event. #[serde(default, skip_serializing_if = "Map::is_empty")] pub tags: Map, @@ -2002,6 +2005,7 @@ impl<'a> Default for Transaction<'a> { Transaction { event_id: event::default_id(), name: Default::default(), + user: Default::default(), tags: Default::default(), extra: Default::default(), release: Default::default(), @@ -2028,6 +2032,7 @@ impl<'a> Transaction<'a> { Transaction { event_id: self.event_id, name: self.name, + user: self.user, tags: self.tags, extra: self.extra, release: self.release.map(|x| Cow::Owned(x.into_owned())),