diff options
Diffstat (limited to 'vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler')
4 files changed, 247 insertions, 0 deletions
diff --git a/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ConstSampler.php b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ConstSampler.php new file mode 100644 index 000000000..7c6ba3d62 --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ConstSampler.php @@ -0,0 +1,68 @@ +<?php + +namespace Jaeger\Sampler; + +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_CONST; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +/** + * ConstSampler always returns the same decision. + * + * @package Jaeger\Sampler + */ +class ConstSampler implements SamplerInterface +{ + /** + * Whether or not the new trace should be sampled. + * + * @var bool + */ + private $decision; + + /** + * A list of the sampler tags. + * + * @var array + */ + private $tags = []; + + /** + * ConstSampler constructor. + * + * @param bool $decision + */ + public function __construct(bool $decision = true) + { + $this->tags = [ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_CONST, + SAMPLER_PARAM_TAG_KEY => $decision, + ]; + + $this->decision = $decision; + } + + /** + * {@inheritdoc} + * + * @param string $traceId The traceId on the span. + * @param string $operation The operation name set on the span. + * @return array + */ + public function isSampled(string $traceId, string $operation = ''): array + { + return [$this->decision, $this->tags]; + } + + /** + * {@inheritdoc} + * + * Only implemented to satisfy the sampler interface. + * + * @return void + */ + public function close() + { + // nothing to do + } +} diff --git a/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ProbabilisticSampler.php b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ProbabilisticSampler.php new file mode 100644 index 000000000..cb265d01e --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/ProbabilisticSampler.php @@ -0,0 +1,88 @@ +<?php + +namespace Jaeger\Sampler; + +use OutOfBoundsException; +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_PROBABILISTIC; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +/** + * A sampler that randomly samples a certain percentage of traces specified + * by the samplingRate, in the range between 0.0 and 1.0. + * + * @package Jaeger\Sampler + */ +class ProbabilisticSampler implements SamplerInterface +{ + /** + * The sampling rate rate between 0.0 and 1.0. + * + * @var float + */ + private $rate; + + /** + * A list of the sampler tags. + * + * @var array + */ + private $tags = []; + + /** + * The boundary of the sample sampling rate. + * + * @var float + */ + private $boundary; + + /** + * ProbabilisticSampler constructor. + * + * @param float $rate + * @throws OutOfBoundsException + */ + public function __construct(float $rate) + { + $this->tags = [ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_PROBABILISTIC, + SAMPLER_PARAM_TAG_KEY => $rate, + ]; + + if ($rate < 0.0 || $rate > 1.0) { + throw new OutOfBoundsException('Sampling rate must be between 0.0 and 1.0.'); + } + + $this->rate = $rate; + if ($rate < 0.5) { + $this->boundary = (int)($rate * PHP_INT_MAX); + } else { + // more precise calculation due to int and float having different precision near PHP_INT_MAX + $this->boundary = PHP_INT_MAX - (int)((1 - $rate) * PHP_INT_MAX); + } + } + + /** + * {@inheritdoc} + * + * @param string $traceId The traceId on the span. + * @param string $operation The operation name set on the span. + * @return array + */ + public function isSampled(string $traceId, string $operation = ''): array + { + return [($traceId < $this->boundary), $this->tags]; + } + + /** + * {@inheritdoc} + * + * Only implemented to satisfy the sampler interface. + * + * @return void + */ + public function close() + { + // nothing to do + } +} diff --git a/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/RateLimitingSampler.php b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/RateLimitingSampler.php new file mode 100644 index 000000000..d0ea0f180 --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/RateLimitingSampler.php @@ -0,0 +1,62 @@ +<?php + +namespace Jaeger\Sampler; + +use Jaeger\Util\RateLimiter; + +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_RATE_LIMITING; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +class RateLimitingSampler implements SamplerInterface +{ + /** + * @var RateLimiter + */ + private $rateLimiter; + + /** + * A list of the sampler tags. + * + * @var array + */ + private $tags = []; + + public function __construct($maxTracesPerSecond, RateLimiter $rateLimiter) + { + $this->tags = [ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_RATE_LIMITING, + SAMPLER_PARAM_TAG_KEY => $maxTracesPerSecond, + ]; + + $maxTracesPerNanosecond = $maxTracesPerSecond / 1000000000.0; + $this->rateLimiter = $rateLimiter; + $this->rateLimiter->initialize($maxTracesPerNanosecond, $maxTracesPerSecond > 1.0 ? 1.0 : $maxTracesPerSecond); + } + + /** + * Whether or not the new trace should be sampled. + * + * Implementations should return an array in the format [$decision, $tags]. + * + * @param string $traceId The traceId on the span. + * @param string $operation The operation name set on the span. + * @return array + */ + public function isSampled(string $traceId = '', string $operation = '') + { + return [$this->rateLimiter->checkCredit(1.0), $this->tags]; + } + + /** + * {@inheritdoc} + * + * Only implemented to satisfy the sampler interface. + * + * @return void + */ + public function close() + { + // nothing to do + } +} diff --git a/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/SamplerInterface.php b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/SamplerInterface.php new file mode 100644 index 000000000..b6d44e783 --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sampler/SamplerInterface.php @@ -0,0 +1,29 @@ +<?php + +namespace Jaeger\Sampler; + +/** + * Sampler is responsible for deciding if a new trace should be sampled and captured for storage. + * + * @package Jaeger\Sampler + */ +interface SamplerInterface +{ + /** + * Whether or not the new trace should be sampled. + * + * Implementations should return an array in the format [$decision, $tags]. + * + * @param string $traceId The traceId on the span. + * @param string $operation The operation name set on the span. + * @return array + */ + public function isSampled(string $traceId, string $operation); + + /** + * Release any resources used by the sampler. + * + * @return void + */ + public function close(); +} |