Skip to content
Open
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
47 changes: 45 additions & 2 deletions sentry-core/src/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,30 @@ impl TransactionOrSpan {
}

/// Get the sampling decision for this Transaction/Span.
///
/// The returned `bool` does not fully represent the sampling state of this
/// Transaction/Span. Although `true` reliably indicates that the
/// Transaction/Span is sampled, a value of `false` can mean either that the
/// Transaction/Span is not sampled, or that tracing is disabled and the
/// sampling decision is deferred. This method therefore should no longer be
/// used, especially not for trace continuation purposes.
///
/// For trace propagation, use [`Self::iter_headers`] or
/// [`crate::Scope::iter_trace_propagation_headers`] instead, to ensure
/// correct results.
#[deprecated = "the returned value may not accurately represent the sampling decision"]
pub fn is_sampled(&self) -> bool {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.is_sampled(),
TransactionOrSpan::Span(span) => span.is_sampled(),
TransactionOrSpan::Transaction(transaction) =>
{
#[expect(deprecated)]
transaction.is_sampled()
}
TransactionOrSpan::Span(span) =>
{
#[expect(deprecated)]
span.is_sampled()
}
}
}

Expand Down Expand Up @@ -930,6 +950,18 @@ impl Transaction {
}

/// Get the sampling decision for this Transaction.
///
/// The returned `bool` does not fully represent the Transaction's sampling
/// state. Although `true` reliably indicates that the Transaction is
/// sampled, a value of `false` can mean either that the Transaction is not
/// sampled, or that tracing is disabled and the sampling decision is
/// deferred. This method therefore should no longer be used, especially not
/// for trace continuation purposes.
///
/// For trace propagation, use [`Self::iter_headers`] or
/// [`crate::Scope::iter_trace_propagation_headers`] instead, to ensure
/// correct results.
#[deprecated = "the returned value may not accurately represent the sampling decision"]
pub fn is_sampled(&self) -> bool {
self.inner.lock().unwrap().sampled
}
Expand Down Expand Up @@ -1214,6 +1246,17 @@ impl Span {
}

/// Get the sampling decision for this Span.
///
/// The returned `bool` does not fully represent the Span's sampling state.
/// Although `true` reliably indicates that the Span is sampled, a value of
/// `false` can mean either that the Span is not sampled, or that tracing is
/// disabled and the sampling decision is deferred. This method therefore
/// should no longer be used, especially not for trace continuation purposes.
///
/// For trace propagation, use [`Self::iter_headers`] or
/// [`crate::Scope::iter_trace_propagation_headers`] instead, to ensure
/// correct results.
#[deprecated = "the returned value may not accurately represent the sampling decision"]
pub fn is_sampled(&self) -> bool {
self.sampled
}
Expand Down
2 changes: 0 additions & 2 deletions sentry-core/tests/trace_continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ impl TraceContinuationScenario {
let context = self.transaction.get_trace_context();
assert_eq!(context.trace_id, self.incoming_trace_id);
assert_eq!(context.parent_span_id, Some(self.incoming_parent_span_id));
assert!(self.transaction.is_sampled());
}

/// Asserts that the transaction rejected the incoming trace and parent sampling.
fn assert_rejected(&self) {
let context = self.transaction.get_trace_context();
assert_ne!(context.trace_id, self.incoming_trace_id);
assert_eq!(context.parent_span_id, None);
assert!(!self.transaction.is_sampled());
}
}

Expand Down
Loading