Skip to content

Commit a1481d4

Browse files
authored
allow custom tags on transactions (#699)
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
1 parent 91de703 commit a1481d4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sentry-core/src/performance.rs

+22
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ impl TransactionOrSpan {
260260
}
261261
}
262262

263+
/// Sets a tag to a specific value.
264+
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
265+
match self {
266+
TransactionOrSpan::Transaction(transaction) => transaction.set_tag(key, value),
267+
TransactionOrSpan::Span(span) => span.set_tag(key, value),
268+
}
269+
}
270+
263271
/// Get the TransactionContext of the Transaction/Span.
264272
///
265273
/// Note that this clones the underlying value.
@@ -492,6 +500,14 @@ impl Transaction {
492500
}
493501
}
494502

503+
/// Sets a tag to a specific value.
504+
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
505+
let mut inner = self.inner.lock().unwrap();
506+
if let Some(transaction) = inner.transaction.as_mut() {
507+
transaction.tags.insert(key.into(), value.to_string());
508+
}
509+
}
510+
495511
/// Returns an iterating accessor to the transaction's
496512
/// [`extra` field](protocol::Transaction::extra).
497513
///
@@ -645,6 +661,12 @@ impl Span {
645661
span.data.insert(key.into(), value);
646662
}
647663

664+
/// Sets a tag to a specific value.
665+
pub fn set_tag<V: ToString>(&self, key: &str, value: V) {
666+
let mut span = self.span.lock().unwrap();
667+
span.tags.insert(key.into(), value.to_string());
668+
}
669+
648670
/// Returns a smart pointer to the span's [`data` field](protocol::Span::data).
649671
///
650672
/// Since [`Data`] implements `Deref` and `DerefMut`, this can be used to read and mutate

0 commit comments

Comments
 (0)