Skip to content

Commit

Permalink
Set default to 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radostyle committed Nov 29, 2023
1 parent ec56114 commit ae641fa
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Profiler/DatadogProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class DatadogProfiler implements ProfilerInterface
private ?Scope $scope = null;

private LoggerInterface $logger;
private ?float $sampleRate;

private float $sampleRate = 1.0;

public function __construct(LoggerInterface $logger)
{
Expand All @@ -31,8 +32,6 @@ public function __construct(LoggerInterface $logger)
if(is_numeric($sampleRateString)) {
$sampleRate = floatval($sampleRateString);
$this->sampleRate = $sampleRate;
} else {
$this->sampleRate = null;
}
}

Expand Down Expand Up @@ -104,11 +103,8 @@ public function stopAndIgnore(): void

private function rateLimited(): bool
{
if($this->sampleRate) {
$randomFloat = mt_rand() / mt_getrandmax(); // between 0 and 1
return $randomFloat > $this->sampleRate;
}
return false;
$randomFloat = mt_rand() / mt_getrandmax(); // between 0 and 1
return $randomFloat > $this->sampleRate;
}

private function isEnabled(): bool
Expand Down

0 comments on commit ae641fa

Please sign in to comment.