class BaggagePropagator
Hierarchy
- class \OpenTelemetry\API\Baggage\Propagation\BaggagePropagator implements \OpenTelemetry\Context\Propagation\TextMapPropagatorInterface
Expanded class hierarchy of BaggagePropagator
See also
File
-
vendor/
open-telemetry/ api/ Baggage/ Propagation/ BaggagePropagator.php, line 22
Namespace
OpenTelemetry\API\Baggage\PropagationView source
final class BaggagePropagator implements TextMapPropagatorInterface {
public const BAGGAGE = 'baggage';
private static ?self $instance = null;
public static function getInstance() : self {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function fields() : array {
return [
self::BAGGAGE,
];
}
public function inject(&$carrier, ?PropagationSetterInterface $setter = null, ?ContextInterface $context = null) : void {
$setter ??= ArrayAccessGetterSetter::getInstance();
$context ??= Context::getCurrent();
$baggage = Baggage::fromContext($context);
if ($baggage->isEmpty()) {
return;
}
$headerString = '';
/** @var Entry $entry */
foreach ($baggage->getAll() as $key => $entry) {
$value = urlencode((string) $entry->getValue());
$headerString .= "{$key}={$value}";
if (($metadata = $entry->getMetadata()
->getValue()) !== '' && ($metadata = $entry->getMetadata()
->getValue()) !== '0') {
$headerString .= ";{$metadata}";
}
$headerString .= ',';
}
if ($headerString !== '' && $headerString !== '0') {
$headerString = rtrim($headerString, ',');
$setter->set($carrier, self::BAGGAGE, $headerString);
}
}
public function extract($carrier, ?PropagationGetterInterface $getter = null, ?ContextInterface $context = null) : ContextInterface {
$getter ??= ArrayAccessGetterSetter::getInstance();
$context ??= Context::getCurrent();
if (!($baggageHeader = $getter->get($carrier, self::BAGGAGE))) {
return $context;
}
$baggageBuilder = Baggage::getBuilder();
$this->extractValue($baggageHeader, $baggageBuilder);
return $context->withContextValue($baggageBuilder->build());
}
private function extractValue(string $baggageHeader, BaggageBuilderInterface $baggageBuilder) : void {
(new Parser($baggageHeader))->parseInto($baggageBuilder);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
BaggagePropagator::$instance | private static | property | ||
BaggagePropagator::BAGGAGE | public | constant | ||
BaggagePropagator::extract | public | function | Extracts specific values from the provided carrier into the provided {via an { | Overrides TextMapPropagatorInterface::extract |
BaggagePropagator::extractValue | private | function | ||
BaggagePropagator::fields | public | function | Returns list of fields that will be used by this propagator. | Overrides TextMapPropagatorInterface::fields |
BaggagePropagator::getInstance | public static | function | ||
BaggagePropagator::inject | public | function | Injects specific values from the provided {via an { | Overrides TextMapPropagatorInterface::inject |