diff --git a/src/Profiler/DatadogProfiler.php b/src/Profiler/DatadogProfiler.php index ea478a4..41c9e74 100644 --- a/src/Profiler/DatadogProfiler.php +++ b/src/Profiler/DatadogProfiler.php @@ -29,8 +29,8 @@ public function __construct(LoggerInterface $logger) $this->logger = $logger; $sampleRateString = getenv('DD_TRACE_SAMPLE_RATE'); - if(is_numeric($sampleRateString)) { - $sampleRate = floatval($sampleRateString); + if (is_numeric($sampleRateString)) { + $sampleRate = (float) $sampleRateString; $this->sampleRate = $sampleRate; } } @@ -41,7 +41,7 @@ public function start(string $name, ?string $kind = null): void return; } - if($this->rateLimited()) { + if ($this->rateLimited()) { return; } @@ -104,6 +104,7 @@ public function stopAndIgnore(): void private function rateLimited(): bool { $randomFloat = mt_rand() / mt_getrandmax(); // between 0 and 1 + return $randomFloat > $this->sampleRate; }