chore(core): Implement disabled tracing semantics - #1286
Conversation
3287209 to
0392622
Compare
0392622 to
3b583f6
Compare
3b583f6 to
08ed195
Compare
08ed195 to
9ed110b
Compare
9ed110b to
0c73e73
Compare
PR #1227 enabled us to represent disabled tracing differently from a 0.0 sample rate when the SDK is initialized but left the behavior for the two cases largely the same. This change fundemantally alters the semantics around how disabled tracing is handled. Spans/Transactions now keep track of a so-called `TracingState` which keeps track of both whether tracing is enabled and what the sampling decision is. When tracing is enabled, there will always be a sampling decision (including a corresponding sample rate); when tracing is disabled, a sampling decision may be available if the trace was continued from an incoming trace with a sampling decision. Traces started in the SDK when tracing is disabled never have a sampling decision. We then separate the concepts of sampling decision and whether to capture traces. The sampling decision now can correctly represent the case where the decision has been deferred. Span/Transaction tracing headers will always include this sampling decision, regardless of whetehr the SDK is capturing the corresponding the Span/Transaction. For whether to capture traces, we now use a `FinishAction` with three possibilities: `Send` and `Discard` are both used when tracing is enabled and are used for sampled and unsampled traces, respectively, while `Ignore` is used for all traces when tracing is disabled. Both `Discard` and `Ignore` result in spans/transactions not being sent to Sentry, but only `Discard` sends a client report. Resolves [#1289](#1289) Resolves [RUST-273](https://linear.app/getsentry/issue/RUST-273) Resolves [#1282](#1282) Resolves [RUST-272](https://linear.app/getsentry/issue/RUST-272)
Deprecate the `is_sampled` methods on `Transaction`, `Span`, and `TransactionOrSpan` because these methods no longer faithfully represent the sampling state of these objects now that the SDK can properly represent the tracing-disabled state. This will be even more true after the follow up PR #1286 is merged; that's because that PR changes these struct's internal `sampled` representation to accurately represent the disabled-tracing states. This PR also removes `is_sampled` assertions from the trace continuation tests. These assertions are not needed because the tests' purpose is to check trace continuation, not sampling decision propagation. These `is_sampled` checks should probably never have been added there. We are not adding a replacement for `is_sampled` because a review of code in the `getsentry` org and public GitHub repos did not reveal any usecases of `is_sampled` that could not be replaced with another reasonable existing alternative, e.g. the functions that return the trace propagation headers. In `getsentry`, no usages of these methods could be found outside the SDK itself.
152813a to
ca9bbe7
Compare
| .with_sample_rate(sample_rate) | ||
| .with_sampled(true); |
There was a problem hiding this comment.
If we are sending the transaction, that means that the transaction is sampled.
|
@giortzisg in case you took at this PR earlier, just a heads up that I have fundamentally changed it. The previous implementation conflated sampling decision and tracing enabled/disabled by assuming that a deferred sampling decision is equivalent to tracing being disabled. This is true when we are the SDK starting the trace, but if we are continuing an incoming trace, we need to be able to correctly represent that tracing is disabled, but that there is still a sampling decision that needs to be propagated outwards. |
| /// Set the `sampled` field, accepting `Option` values. | ||
| pub(crate) fn with_maybe_sampled(self, sampled: Option<bool>) -> Self { |
There was a problem hiding this comment.
l: found the name a bit confusing. Maybe with_sampled_option is a better one.
PR #1227 enabled us to represent disabled tracing differently from a 0.0 sample rate when the SDK is initialized but left the behavior for the two cases largely the same.
This change fundamentally alters the semantics around how disabled tracing is handled.
Spans/Transactions now keep track of a so-called
TracingStatewhich keeps track of both whether tracing is enabled and what the sampling decision is. When tracing is enabled, there will always be a sampling decision (including a corresponding sample rate); when tracing is disabled, a sampling decision may be available if the trace was continued from an incoming trace with a sampling decision. Traces started in the SDK when tracing is disabled never have a sampling decision.We then separate the concepts of sampling decision and whether to capture traces. The sampling decision now can correctly represent the case where the decision has been deferred. Span/Transaction tracing headers will always include this sampling decision, regardless of whetehr the SDK is capturing the corresponding the Span/Transaction. For whether to capture traces, we now use a
FinishActionwith three possibilities:SendandDiscardare both used when tracing is enabled and are used for sampled and unsampled traces, respectively, whileIgnoreis used for all traces when tracing is disabled. BothDiscardandIgnoreresult in spans/transactions not being sent to Sentry, but onlyDiscardsends a client report.