| 
 | 1 | +<?php  | 
 | 2 | +declare(strict_types=1);  | 
 | 3 | + | 
 | 4 | +namespace Jaeger\Symfony\Sampler;  | 
 | 5 | + | 
 | 6 | +use Jaeger\Sampler\SamplerDecisionTag;  | 
 | 7 | +use Jaeger\Sampler\SamplerFlagsTag;  | 
 | 8 | +use Jaeger\Sampler\SamplerInterface;  | 
 | 9 | +use Jaeger\Sampler\SamplerParamTag;  | 
 | 10 | +use Jaeger\Sampler\SamplerResult;  | 
 | 11 | +use Jaeger\Sampler\SamplerTypeTag;  | 
 | 12 | + | 
 | 13 | +final class DenylistOperationsSampler implements SamplerInterface  | 
 | 14 | +{  | 
 | 15 | +    private $sampler;  | 
 | 16 | + | 
 | 17 | +    private $denylistedOperationsMap;  | 
 | 18 | + | 
 | 19 | +    /**  | 
 | 20 | +     * @var SamplerInterface $sampler  | 
 | 21 | +     * @var string[]         $denylistedOperations  | 
 | 22 | +     */  | 
 | 23 | +    public function __construct(SamplerInterface $sampler, array $denylistedOperations)  | 
 | 24 | +    {  | 
 | 25 | +        $this->sampler = $sampler;  | 
 | 26 | +        $this->denylistedOperationsMap = \array_fill_keys($denylistedOperations, true);  | 
 | 27 | +    }  | 
 | 28 | + | 
 | 29 | +    public function decide(int $traceId, string $operationName, string $debugId): SamplerResult  | 
 | 30 | +    {  | 
 | 31 | +        if ('' !== $debugId) {  | 
 | 32 | +            return $this->sampler->decide($traceId, $operationName, $debugId);  | 
 | 33 | +        }  | 
 | 34 | + | 
 | 35 | +        if (false === \array_key_exists($operationName, $this->denylistedOperationsMap)) {  | 
 | 36 | +            return $this->sampler->decide($traceId, $operationName, $debugId);  | 
 | 37 | +        }  | 
 | 38 | + | 
 | 39 | +        return new SamplerResult(  | 
 | 40 | +            false,  | 
 | 41 | +            0,  | 
 | 42 | +            [  | 
 | 43 | +                new SamplerTypeTag('denylist_operations'),  | 
 | 44 | +                new SamplerParamTag($operationName),  | 
 | 45 | +                new SamplerDecisionTag(false),  | 
 | 46 | +                new SamplerFlagsTag(0x00),  | 
 | 47 | +            ]  | 
 | 48 | +        );  | 
 | 49 | +    }  | 
 | 50 | +}  | 
0 commit comments