Skip to content
Closed
Show file tree
Hide file tree
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
90 changes: 90 additions & 0 deletions sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, Mutex, MutexGuard};

use sentry_types::protocol::latest::Context;

#[cfg(all(feature = "profiling", target_family = "unix"))]
use crate::profiling;

Expand Down Expand Up @@ -265,6 +267,32 @@ impl TransactionOrSpan {
}
}

/// Removes extra information for a key.
pub fn remove_data(&self, key: &str) {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.remove_data(key),
TransactionOrSpan::Span(span) => span.remove_data(key),
}
}

/// 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),
}
}

/// Removes a tag.
///
/// If the tag is not set, does nothing.
pub fn remove_tag(&self, key: &str) {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.remove_tag(key),
TransactionOrSpan::Span(span) => span.remove_tag(key),
}
}

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

/// Removes extra information for a key.
pub fn remove_data(&self, key: &str) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.extra.remove(key);
}
}

/// 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.to_string(), value.to_string());
}
}

/// Removes a tag.
///
/// If the tag is not set, does nothing.
pub fn remove_tag(&self, key: &str) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.tags.remove(key);
}
}

/// Sets a context for a key.
pub fn set_context<C: Into<Context>>(&self, key: &str, value: C) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.contexts.insert(key.to_string(), value.into());
}
}

/// Removes a context for a key.
pub fn remove_context(&self, key: &str) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.contexts.remove(key);
}
}

/// Get the TransactionContext of the Transaction.
///
/// Note that this clones the underlying value.
Expand Down Expand Up @@ -666,6 +736,26 @@ impl Span {
span.data.insert(key.into(), value);
}

/// Removes data for the specified key.
pub fn remove_data(&self, key: &str) {
let mut span = self.span.lock().unwrap();
span.data.remove(key);
}

/// 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.to_string(), value.to_string());
}

/// Removes a tag.
///
/// If the tag is not set, does nothing.
pub fn remove_tag(&self, key: &str) {
let mut span = self.span.lock().unwrap();
span.tags.remove(key);
}

/// 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
33 changes: 29 additions & 4 deletions sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,58 @@ impl Scope {
/// Sets a tag to a specific value.
pub fn set_tag<V: ToString>(&mut self, key: &str, value: V) {
Arc::make_mut(&mut self.tags).insert(key.to_string(), value.to_string());

if let Some(ref transaction_or_span) = *self.span {
transaction_or_span.set_tag(key, value);
}
}

/// Removes a tag.
///
/// If the tag is not set, does nothing.
pub fn remove_tag(&mut self, key: &str) {
Arc::make_mut(&mut self.tags).remove(key);

if let Some(ref transaction_or_span) = *self.span {
transaction_or_span.remove_tag(key);
}
}

/// Sets a context for a key.
pub fn set_context<C: Into<Context>>(&mut self, key: &str, value: C) {
Arc::make_mut(&mut self.contexts).insert(key.to_string(), value.into());
let context = value.into();
Arc::make_mut(&mut self.contexts).insert(key.to_string(), context.clone());

if let Some(TransactionOrSpan::Transaction(ref transaction)) = *self.span {
transaction.set_context(key, context);
}
}

/// Removes a context for a key.
pub fn remove_context(&mut self, key: &str) {
Arc::make_mut(&mut self.contexts).remove(key);

if let Some(TransactionOrSpan::Transaction(ref transaction)) = *self.span {
transaction.remove_context(key);
}
}

/// Sets a extra to a specific value.
/// Sets an extra to a specific value.
pub fn set_extra(&mut self, key: &str, value: Value) {
Arc::make_mut(&mut self.extra).insert(key.to_string(), value);
Arc::make_mut(&mut self.extra).insert(key.to_string(), value.clone());

if let Some(ref transaction_or_span) = *self.span {
transaction_or_span.set_data(key, value);
}
}

/// Removes a extra.
/// Removes an extra.
pub fn remove_extra(&mut self, key: &str) {
Arc::make_mut(&mut self.extra).remove(key);

if let Some(ref transaction_or_span) = *self.span {
transaction_or_span.remove_data(key);
}
}

/// Add an event processor to the scope.
Expand Down