Skip to content

Logs are misleading when transaction is sampled due to parent being sampled #1712

@rmsy

Description

@rmsy

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

  1. Configure Sentry to have a traces_sampler proc which returns false or 0.0
  2. Send a request to Rails with a Sentry-Trace header
  3. Observe the debug log message indicating the transaction will be discarded
  4. 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

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions