feat(scopes): extract transaction sampling logic into TransactionSampler#2118
Open
Litarnus wants to merge 3 commits into
Open
feat(scopes): extract transaction sampling logic into TransactionSampler#2118Litarnus wants to merge 3 commits into
Litarnus wants to merge 3 commits into
Conversation
0ab8198 to
99d01dc
Compare
| $dynamicSamplingContext->set('sample_rate', (string) $sampleRate, true); | ||
| } | ||
|
|
||
| if ($sampleRate === 0.0) { |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.