Skip to content
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

ref: Apply user field from scope to transaction event #596

Merged
merged 1 commit into from Jul 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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