Skip to content

Commit

Permalink
ref: Apply user field from scope to transaction event (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Jul 10, 2023
1 parent 3e687f1 commit 6ef6d97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sentry-core/src/scope/real.rs
Expand Up @@ -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())));
Expand Down
5 changes: 5 additions & 0 deletions sentry-types/src/protocol/v7.rs
Expand Up @@ -1958,6 +1958,9 @@ pub struct Transaction<'a> {
/// An optional environment identifier.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub environment: Option<Cow<'a, str>>,
/// Optionally user data to be sent along.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub user: Option<User>,
/// Optional tags to be attached to the event.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub tags: Map<String, String>,
Expand Down Expand Up @@ -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(),
Expand All @@ -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())),
Expand Down

0 comments on commit 6ef6d97

Please sign in to comment.