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

Give access to is_sampled to allow users to dodge work in unsampled case #669

Merged
merged 1 commit into from
Jul 15, 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
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
Loading