Issue Description
Hello 👋
If a transaction has a parent which is sampled, the tracing debug logs are slightly misleading. Due to the precedence of the conditionals below, the sample_rate may be false or 0.0 if a sampler proc is defined and returns one of them:
|
sample_rate = |
|
if @traces_sampler.is_a?(Proc) |
|
@traces_sampler.call(sampling_context) |
|
elsif !sampling_context[:parent_sampled].nil? |
|
sampling_context[:parent_sampled] |
|
else |
|
@traces_sample_rate |
|
end |
This results in the following log message being logged, indicating the transaction will be discarded:
|
if sample_rate == 0.0 || sample_rate == false |
|
@sampled = false |
|
log_debug("#{MESSAGE_PREFIX} Discarding #{transaction_description} because traces_sampler returned 0 or false") |
|
return |
|
end |
However, if @parent_sampled is true for the transaction, it is still sent in finish:
|
unless @sampled || @parent_sampled |
|
hub.current_client.transport.record_lost_event(:sample_rate, 'transaction') |
|
return |
|
end |
|
|
|
event = hub.current_client.event_from_transaction(self) |
|
hub.capture_event(event) |
I assume the first two conditionals in the sample_rate assignment can just be reversed, but I wasn't 100% sure if doing that would have any other side-effects, so I opened this issue instead of a PR.
Reproduction Steps
- Configure Sentry to have a
traces_sampler proc which returns false or 0.0
- Send a request to Rails with a
Sentry-Trace header
- Observe the debug log message indicating the transaction will be discarded
- Observe that the transaction is still sent to Sentry
Expected Behavior
The log message should not indicate that the transaction will be discarded.
Actual Behavior
The log message indicates that the transaction will be discarded.
Ruby Version
2.7.4
SDK Version
4.8.2
Integration and Its Version
Rails
Sentry Config
No response
Issue Description
Hello 👋
If a transaction has a parent which is sampled, the tracing debug logs are slightly misleading. Due to the precedence of the conditionals below, the
sample_ratemay befalseor0.0if a sampler proc is defined and returns one of them:sentry-ruby/sentry-ruby/lib/sentry/transaction.rb
Lines 108 to 115 in 8538717
This results in the following log message being logged, indicating the transaction will be discarded:
sentry-ruby/sentry-ruby/lib/sentry/transaction.rb
Lines 125 to 129 in 8538717
However, if
@parent_sampledis true for the transaction, it is still sent infinish:sentry-ruby/sentry-ruby/lib/sentry/transaction.rb
Lines 167 to 173 in 8538717
I assume the first two conditionals in the
sample_rateassignment can just be reversed, but I wasn't 100% sure if doing that would have any other side-effects, so I opened this issue instead of a PR.Reproduction Steps
traces_samplerproc which returnsfalseor0.0Sentry-TraceheaderExpected Behavior
The log message should not indicate that the transaction will be discarded.
Actual Behavior
The log message indicates that the transaction will be discarded.
Ruby Version
2.7.4
SDK Version
4.8.2
Integration and Its Version
Rails
Sentry Config
No response