Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExportingReader.php

class ExportingReader

Hierarchy

  • class \OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader implements \OpenTelemetry\SDK\Metrics\MetricReaderInterface, \OpenTelemetry\SDK\Metrics\MetricSourceRegistryInterface, \OpenTelemetry\SDK\Metrics\MetricSourceRegistryUnregisterInterface, \OpenTelemetry\SDK\Metrics\DefaultAggregationProviderInterface uses \OpenTelemetry\SDK\Metrics\DefaultAggregationProviderTrait

Expanded class hierarchy of ExportingReader

1 file declares its use of ExportingReader
MeterProviderFactory.php in vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php

File

vendor/open-telemetry/sdk/Metrics/MetricReader/ExportingReader.php, line 25

Namespace

OpenTelemetry\SDK\Metrics\MetricReader
View source
final class ExportingReader implements MetricReaderInterface, MetricSourceRegistryInterface, MetricSourceRegistryUnregisterInterface, DefaultAggregationProviderInterface {
    use DefaultAggregationProviderTrait {
        defaultAggregation as private _defaultAggregation;
    }
    
    /** @var array<int, MetricSourceInterface> */
    private array $sources = [];
    
    /** @var array<int, MetricCollectorInterface> */
    private array $registries = [];
    
    /** @var array<int, array<int, list<int>>> */
    private array $streamIds = [];
    private bool $closed = false;
    public function __construct(MetricExporterInterface $exporter) {
    }
    public function defaultAggregation($instrumentType, array $advisory = []) : ?AggregationInterface {
        if ($this->exporter instanceof DefaultAggregationProviderInterface) {
            
            /** @phan-suppress-next-line PhanParamTooMany @phpstan-ignore-next-line */
            return $this->exporter
                ->defaultAggregation($instrumentType, $advisory);
        }
        return $this->_defaultAggregation($instrumentType, $advisory);
    }
    public function add(MetricSourceProviderInterface $provider, MetricMetadataInterface $metadata, StalenessHandlerInterface $stalenessHandler) : void {
        if ($this->closed) {
            return;
        }
        if (!$this->exporter instanceof AggregationTemporalitySelectorInterface) {
            return;
        }
        if (!($temporality = $this->exporter
            ->temporality($metadata))) {
            return;
        }
        $source = $provider->create($temporality);
        $sourceId = spl_object_id($source);
        $this->sources[$sourceId] = $source;
        if (!$provider instanceof StreamMetricSourceProvider) {
            $stalenessHandler->onStale(function () use ($sourceId) : void {
                unset($this->sources[$sourceId]);
            });
            return;
        }
        $streamId = $provider->streamId;
        $registry = $provider->metricCollector;
        $registryId = spl_object_id($registry);
        $this->registries[$registryId] = $registry;
        $this->streamIds[$registryId][$streamId][] = $sourceId;
    }
    public function unregisterStream(MetricCollectorInterface $collector, int $streamId) : void {
        $registryId = spl_object_id($collector);
        foreach ($this->streamIds[$registryId][$streamId] ?? [] as $sourceId) {
            unset($this->sources[$sourceId]);
        }
        unset($this->streamIds[$registryId][$streamId]);
        if (!$this->streamIds[$registryId]) {
            unset($this->registries[$registryId], $this->streamIds[$registryId]);
        }
    }
    private function doCollect() : bool {
        foreach ($this->registries as $registryId => $registry) {
            $streamIds = $this->streamIds[$registryId] ?? [];
            $registry->collectAndPush(array_keys($streamIds));
        }
        $metrics = [];
        foreach ($this->sources as $source) {
            $metrics[] = $source->collect();
        }
        if ($metrics === []) {
            return true;
        }
        return $this->exporter
            ->export($metrics);
    }
    public function collect() : bool {
        if ($this->closed) {
            return false;
        }
        return $this->doCollect();
    }
    public function shutdown() : bool {
        if ($this->closed) {
            return false;
        }
        $this->closed = true;
        $collect = $this->doCollect();
        $shutdown = $this->exporter
            ->shutdown();
        $this->sources = [];
        return $collect && $shutdown;
    }
    public function forceFlush() : bool {
        if ($this->closed) {
            return false;
        }
        if ($this->exporter instanceof PushMetricExporterInterface) {
            $collect = $this->doCollect();
            $forceFlush = $this->exporter
                ->forceFlush();
            return $collect && $forceFlush;
        }
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary Member alias Overriden Title
DefaultAggregationProviderTrait::defaultAggregation public function Aliased as: _defaultAggregation
ExportingReader::$closed private property
ExportingReader::$registries private property @var array&lt;int, MetricCollectorInterface&gt;
ExportingReader::$sources private property @var array&lt;int, MetricSourceInterface&gt;
ExportingReader::$streamIds private property @var array&lt;int, array&lt;int, list&lt;int&gt;&gt;&gt;
ExportingReader::add public function Overrides MetricSourceRegistryInterface::add
ExportingReader::collect public function Overrides MetricReaderInterface::collect
ExportingReader::defaultAggregation public function @noinspection PhpDocSignatureInspection not added for BC
@phan-suppress PhanCommentParamWithoutRealParam @phpstan-ignore-next-line
Overrides DefaultAggregationProviderInterface::defaultAggregation
ExportingReader::doCollect private function
ExportingReader::forceFlush public function Overrides MetricReaderInterface::forceFlush
ExportingReader::shutdown public function Overrides MetricReaderInterface::shutdown
ExportingReader::unregisterStream public function Overrides MetricSourceRegistryUnregisterInterface::unregisterStream
ExportingReader::__construct public function
RSS feed
Powered by Drupal