Skip to content

Commit ebe1a89

Browse files
committed
Added adaptive sampling
1 parent 6815786 commit ebe1a89

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/Sampler/RateLimitingSampler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function __construct(float $rate, GeneratorInterface $generator)
1818
public function doDecide(int $tracerId, string $operationName): SamplerResult
1919
{
2020
$key = $this->generator->generate($tracerId, $operationName);
21-
if (false !== ($current = apcu_add($key, sprintf('%s:%d', time(), 1), 1 / $this->rate))) {
21+
$ttl = max((int)(1 / $this->rate + 1), 1);
22+
if (false !== ($current = apcu_add($key, sprintf('%s:%d', time(), 1), $ttl))) {
2223
return new SamplerResult(
2324
true, 0x01, [
2425
new SamplerTypeTag('ratelimiting'),

0 commit comments

Comments
 (0)