Skip to content

feat(scopes): extract transaction sampling logic into TransactionSampler#2118

Open
Litarnus wants to merge 3 commits into
scopes-clientfrom
transaction-sampler
Open

feat(scopes): extract transaction sampling logic into TransactionSampler#2118
Litarnus wants to merge 3 commits into
scopes-clientfrom
transaction-sampler

Conversation

@Litarnus

Copy link
Copy Markdown
Contributor

No description provided.

@Litarnus Litarnus force-pushed the transaction-sampler branch from 0ab8198 to 99d01dc Compare June 15, 2026 13:19
@Litarnus Litarnus changed the title Transaction sampler feat(scopes): extract transaction sampling logic into TransactionSampler Jun 15, 2026
@Litarnus Litarnus marked this pull request as ready for review June 22, 2026 14:38
$dynamicSamplingContext->set('sample_rate', (string) $sampleRate, true);
}

if ($sampleRate === 0.0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The strict comparison $sampleRate === 0.0 fails when the sample rate is an integer 0. The code works by accident, but the explicit check for a zero sample rate is bypassed.
Severity: LOW

Suggested Fix

Change the strict comparison === 0.0 to a non-strict comparison == 0 or cast the sample rate to a float before the comparison, like (float) $sampleRate === 0.0. This will correctly handle both integer 0 and float 0.0 values, aligning the code with its intended behavior. Apply this fix at both line 83 and line 151.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Tracing/TransactionSampler.php#L83

Potential issue: The code checks if the sample rate is zero using a strict comparison,
`if ($sampleRate === 0.0)`. However, the configuration for `traces_sample_rate` allows
an integer value. If a user configures the sample rate as integer `0`, the strict
comparison `0 === 0.0` will evaluate to `false`. This causes the intended early return
to be skipped. While the subsequent logic currently leads to the correct outcome of not
sampling the transaction, it does so accidentally because the condition `$sampleRand <
0` is always false. This makes the code fragile and reliant on an implementation detail
that could change in the future, breaking the zero-sampling behavior. A similar issue
exists in the `sampleRate()` method.

Also affects:

  • src/Tracing/TransactionSampler.php:151

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant