diff --git a/sentry-core/src/performance.rs b/sentry-core/src/performance.rs index 08c33936..5f3a9a46 100644 --- a/sentry-core/src/performance.rs +++ b/sentry-core/src/performance.rs @@ -260,6 +260,14 @@ impl TransactionOrSpan { } } + /// Sets a tag to a specific value. + pub fn set_tag(&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. @@ -492,6 +500,14 @@ impl Transaction { } } + /// Sets a tag to a specific value. + pub fn set_tag(&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). /// @@ -645,6 +661,12 @@ impl Span { span.data.insert(key.into(), value); } + /// Sets a tag to a specific value. + pub fn set_tag(&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