diff options
author | Andrew Dolgov <[email protected]> | 2023-10-20 17:12:29 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-10-20 21:13:39 +0300 |
commit | cdd7ad020e165fe680703b6d3319b908b682fb7a (patch) | |
tree | b51eb09b7b4587e8fbc5624ac8d88d28cfcd0b04 /vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php | |
parent | 45a9ff0c88cbd33892ff16ab837e9059937d656e (diff) |
jaeger-client -> opentelemetry
Diffstat (limited to 'vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php')
-rw-r--r-- | vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php b/vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php new file mode 100644 index 000000000..075fe98fe --- /dev/null +++ b/vendor/open-telemetry/context/Propagation/MultiTextMapPropagator.php @@ -0,0 +1,83 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\Context\Propagation; + +use function array_map; +use function array_merge; +use function array_unique; +use function array_values; +use OpenTelemetry\Context\Context; +use OpenTelemetry\Context\ContextInterface; + +final class MultiTextMapPropagator implements TextMapPropagatorInterface +{ + /** + * @readonly + * + * @var list<TextMapPropagatorInterface> + */ + private array $propagators = []; + + /** + * @readonly + * + * @var list<string> + */ + private array $fields; + + /** + * @no-named-arguments + * + * @param list<TextMapPropagatorInterface> $propagators + */ + public function __construct(array $propagators) + { + $this->propagators = $propagators; + $this->fields = $this->extractFields($propagators); + } + + public function fields(): array + { + return $this->fields; + } + + public function inject(&$carrier, PropagationSetterInterface $setter = null, ContextInterface $context = null): void + { + foreach ($this->propagators as $propagator) { + $propagator->inject($carrier, $setter, $context); + } + } + + public function extract($carrier, PropagationGetterInterface $getter = null, ContextInterface $context = null): ContextInterface + { + $context ??= Context::getCurrent(); + + foreach ($this->propagators as $propagator) { + $context = $propagator->extract($carrier, $getter, $context); + } + + return $context; + } + + /** + * @param list<TextMapPropagatorInterface> $propagators + * @return list<string> + */ + private function extractFields(array $propagators): array + { + return array_values( + array_unique( + // Phan seems to struggle here with the variadic argument + // @phan-suppress-next-line PhanParamTooFewInternalUnpack + array_merge( + ...array_map( + static fn (TextMapPropagatorInterface $propagator) => $propagator->fields(), + $propagators + ) + ) + ) + ); + } +} |