diff options
Diffstat (limited to 'vendor/open-telemetry/sdk/Trace/SamplerFactory.php')
-rw-r--r-- | vendor/open-telemetry/sdk/Trace/SamplerFactory.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Trace/SamplerFactory.php b/vendor/open-telemetry/sdk/Trace/SamplerFactory.php new file mode 100644 index 000000000..f99674d79 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SamplerFactory.php @@ -0,0 +1,48 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\SDK\Trace; + +use InvalidArgumentException; +use OpenTelemetry\SDK\Common\Configuration\Configuration; +use OpenTelemetry\SDK\Common\Configuration\KnownValues as Values; +use OpenTelemetry\SDK\Common\Configuration\Variables as Env; +use OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler; +use OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler; +use OpenTelemetry\SDK\Trace\Sampler\ParentBased; +use OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler; + +class SamplerFactory +{ + private const TRACEIDRATIO_PREFIX = 'traceidratio'; + + public function create(): SamplerInterface + { + $name = Configuration::getString(Env::OTEL_TRACES_SAMPLER); + + if (strpos($name, self::TRACEIDRATIO_PREFIX) !== false) { + $arg = Configuration::getRatio(Env::OTEL_TRACES_SAMPLER_ARG); + + switch ($name) { + case Values::VALUE_TRACE_ID_RATIO: + return new TraceIdRatioBasedSampler($arg); + case Values::VALUE_PARENT_BASED_TRACE_ID_RATIO: + return new ParentBased(new TraceIdRatioBasedSampler($arg)); + } + } + + switch ($name) { + case Values::VALUE_ALWAYS_ON: + return new AlwaysOnSampler(); + case Values::VALUE_ALWAYS_OFF: + return new AlwaysOffSampler(); + case Values::VALUE_PARENT_BASED_ALWAYS_ON: + return new ParentBased(new AlwaysOnSampler()); + case Values::VALUE_PARENT_BASED_ALWAYS_OFF: + return new ParentBased(new AlwaysOffSampler()); + default: + throw new InvalidArgumentException(sprintf('Unknown sampler: %s', $name)); + } + } +} |