class FiberBoundContextStorage
@internal
Hierarchy
- class \OpenTelemetry\Context\FiberBoundContextStorage implements \OpenTelemetry\Context\ContextStorageInterface, \OpenTelemetry\Context\ContextStorageHeadAware
Expanded class hierarchy of FiberBoundContextStorage
File
-
vendor/
open-telemetry/ context/ FiberBoundContextStorage.php, line 18
Namespace
OpenTelemetry\ContextView source
final class FiberBoundContextStorage implements ContextStorageInterface, ContextStorageHeadAware {
/** @var WeakMap<object, ContextStorageHead> */
private WeakMap $heads;
public function __construct() {
$this->heads = new WeakMap();
$this->heads[$this] = new ContextStorageHead($this);
}
public function head() : ?ContextStorageHead {
return $this->heads[Fiber::getCurrent() ?? $this] ?? null;
}
public function scope() : ?ContextStorageScopeInterface {
$head = $this->heads[Fiber::getCurrent() ?? $this] ?? null;
if (!$head?->node && Fiber::getCurrent()) {
self::triggerNotInitializedFiberContextWarning();
return null;
}
// Starts with empty head instead of cloned parent -> no need to check for head mismatch
return $head->node;
}
public function current() : ContextInterface {
$head = $this->heads[Fiber::getCurrent() ?? $this] ?? null;
if (!$head?->node && Fiber::getCurrent()) {
self::triggerNotInitializedFiberContextWarning();
// Fallback to {main} to preserve BC
$head = $this->heads[$this];
}
return $head->node->context ?? Context::getRoot();
}
public function attach(ContextInterface $context) : ContextStorageScopeInterface {
$head = $this->heads[Fiber::getCurrent() ?? $this] ??= new ContextStorageHead($this);
return $head->node = new ContextStorageNode($context, $head, $head->node);
}
private static function triggerNotInitializedFiberContextWarning() : void {
$fiber = Fiber::getCurrent();
assert($fiber !== null);
trigger_error(sprintf('Access to not initialized OpenTelemetry context in fiber (id: %d), automatic forking not supported, must attach initial fiber context manually', spl_object_id($fiber)), E_USER_WARNING);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
FiberBoundContextStorage::$heads | private | property | @var WeakMap<object, ContextStorageHead> | |
FiberBoundContextStorage::attach | public | function | Attaches the context as active context. | Overrides ContextStorageInterface::attach |
FiberBoundContextStorage::current | public | function | Returns the current context. | Overrides ContextStorageInterface::current |
FiberBoundContextStorage::head | public | function | Overrides ContextStorageHeadAware::head | |
FiberBoundContextStorage::scope | public | function | Returns the current scope. | Overrides ContextStorageInterface::scope |
FiberBoundContextStorage::triggerNotInitializedFiberContextWarning | private static | function | ||
FiberBoundContextStorage::__construct | public | function |