Skip to content

Commit

Permalink
allow custom tags on transactions
Browse files Browse the repository at this point in the history
currently the only tags added to transactions are on the scope at the
time of finish, but sometimes it is useful to have tags that aren't
for the scope but just for the transaction
  • Loading branch information
nrxus committed Oct 18, 2024
1 parent 91de703 commit 55485cd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ impl TransactionOrSpan {
}
}

/// Sets a tag to a specific value.
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.set_tag(key, value),
TransactionOrSpan::Span(span) => span.set_tag(key, value),
}
}

/// Get the TransactionContext of the Transaction/Span.
///
/// Note that this clones the underlying value.
Expand Down Expand Up @@ -492,6 +500,14 @@ impl Transaction {
}
}

/// Sets a tag to a specific value.
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.tags.insert(key.into(), value.to_string());
}
}

/// Returns an iterating accessor to the transaction's
/// [`extra` field](protocol::Transaction::extra).
///
Expand Down Expand Up @@ -645,6 +661,12 @@ impl Span {
span.data.insert(key.into(), value);
}

/// Sets a tag to a specific value.
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
let mut span = self.span.lock().unwrap();
span.tags.insert(key.into(), value.to_string());
}

/// Returns a smart pointer to the span's [`data` field](protocol::Span::data).
///
/// Since [`Data`] implements `Deref` and `DerefMut`, this can be used to read and mutate
Expand Down

0 comments on commit 55485cd

Please sign in to comment.