diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1c54b2..5df0fe57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Deprecated `ClientOptions::enable_logs`. The option no longer disables manually captured logs (via the logging APIs); it now only disables automatic log capture by the log-capturing integrations (`tracing` and `log` with the `logs` feature). To stop an integration from sending logs, configure it via its own options ([#1299](https://github.com/getsentry/sentry-rust/pull/1299)). - Deprecated `ClientOptions::enable_metrics`. The option is now a no-op; metrics are always enabled. To stop sending metrics, stop calling the metrics APIs ([#1300](https://github.com/getsentry/sentry-rust/pull/1300)). +- Deprecated [`Transaction::is_sampled`](https://docs.rs/sentry-core/0.49.2/sentry_core/struct.Transaction.html#method.is_sampled), [`Span::is_sampled`](https://docs.rs/sentry-core/0.49.2/sentry_core/struct.Span.html#method.is_sampled), and [`TransactionOrSpan::is_sampled`](https://docs.rs/sentry-core/0.49.2/sentry_core/enum.TransactionOrSpan.html#method.is_sampled). These methods cannot distinguish between an unsampled transaction or span and a deferred sampling decision when tracing is disabled ([#1293](https://github.com/getsentry/sentry-rust/pull/1293)). ## 0.49.1 diff --git a/sentry-core/src/performance/mod.rs b/sentry-core/src/performance/mod.rs index 090b5902..390c6081 100644 --- a/sentry-core/src/performance/mod.rs +++ b/sentry-core/src/performance/mod.rs @@ -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() + } } } @@ -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 } @@ -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 } diff --git a/sentry-core/tests/trace_continuation.rs b/sentry-core/tests/trace_continuation.rs index 78962c6a..ea7a5d81 100644 --- a/sentry-core/tests/trace_continuation.rs +++ b/sentry-core/tests/trace_continuation.rs @@ -71,7 +71,6 @@ 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. @@ -79,7 +78,6 @@ impl TraceContinuationScenario { 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()); } }