From 55485cdb8e2e573d69a38fb0d33be078dc285bee Mon Sep 17 00:00:00 2001 From: Andres Medina Date: Fri, 18 Oct 2024 09:20:48 -0700 Subject: [PATCH] allow custom tags on transactions 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 --- sentry-core/src/performance.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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