Skip to content

Commit

Permalink
Give access to is_sampled to allow users to dodge work in unsampled c…
Browse files Browse the repository at this point in the history
…ase (#669)
  • Loading branch information
Ten0 authored Jul 15, 2024
1 parent 36f1384 commit 8cc4848
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl TransactionContext {
/// can be used for distributed tracing.
#[must_use = "this must be used with `start_transaction`"]
pub fn new(name: &str, op: &str) -> Self {
Self::continue_from_headers(name, op, vec![])
Self::continue_from_headers(name, op, std::iter::empty())
}

/// Creates a new Transaction Context based on the distributed tracing `headers`.
Expand Down Expand Up @@ -200,7 +200,8 @@ impl TransactionContext {
///
/// If the context did not have this key present, None is returned.
///
/// If the context did have this key present, the value is updated, and the old value is returned.
/// If the context did have this key present, the value is updated, and the old value is
/// returned.
pub fn custom_insert(
&mut self,
key: String,
Expand Down Expand Up @@ -301,6 +302,14 @@ impl TransactionOrSpan {
}
}

/// Get the sampling decision for this Transaction/Span.
pub fn is_sampled(&self) -> bool {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.is_sampled(),
TransactionOrSpan::Span(span) => span.is_sampled(),
}
}

/// Starts a new child Span with the given `op` and `description`.
///
/// The span must be explicitly finished via [`Span::finish`], as it will
Expand Down Expand Up @@ -483,7 +492,8 @@ impl Transaction {
}
}

/// Returns an iterating accessor to the transaction's [`extra` field](protocol::Transaction::extra).
/// Returns an iterating accessor to the transaction's
/// [`extra` field](protocol::Transaction::extra).
///
/// # Concurrency
/// In order to obtain any kind of reference to the `extra` field,
Expand Down Expand Up @@ -536,6 +546,11 @@ impl Transaction {
}
}

/// Get the sampling decision for this Transaction.
pub fn is_sampled(&self) -> bool {
self.inner.lock().unwrap().sampled
}

/// Finishes the Transaction.
///
/// This records the end timestamp and sends the transaction together with
Expand Down Expand Up @@ -708,6 +723,11 @@ impl Span {
}
}

/// Get the sampling decision for this Span.
pub fn is_sampled(&self) -> bool {
self.sampled
}

/// Finishes the Span.
///
/// This will record the end timestamp and add the span to the transaction
Expand Down

0 comments on commit 8cc4848

Please sign in to comment.