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

Allow settings tags directly on transactions/spans #699

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading