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

Breadcrumb

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

class AsynchronousMetricStream

@internal

Hierarchy

  • class \OpenTelemetry\SDK\Metrics\Stream\AsynchronousMetricStream implements \OpenTelemetry\SDK\Metrics\Stream\MetricStreamInterface

Expanded class hierarchy of AsynchronousMetricStream

1 file declares its use of AsynchronousMetricStream
StreamFactory.php in vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamFactory.php

File

vendor/open-telemetry/sdk/Metrics/Stream/AsynchronousMetricStream.php, line 17

Namespace

OpenTelemetry\SDK\Metrics\Stream
View source
final class AsynchronousMetricStream implements MetricStreamInterface {
    private Metric $metric;
    
    /** @var array<int, Metric|null> */
    private array $lastReads = [];
    public function __construct(AggregationInterface $aggregation, int $startTimestamp) {
        $this->metric = new Metric([], [], $startTimestamp);
    }
    public function temporality() : Temporality|string {
        return Temporality::CUMULATIVE;
    }
    public function timestamp() : int {
        return $this->metric->timestamp;
    }
    public function push(Metric $metric) : void {
        $this->metric = $metric;
    }
    public function register($temporality) : int {
        if ($temporality === Temporality::CUMULATIVE) {
            return -1;
        }
        if (($reader = array_search(null, $this->lastReads, true)) === false) {
            $reader = count($this->lastReads);
        }
        $this->lastReads[$reader] = $this->metric;
        return $reader;
    }
    public function unregister(int $reader) : void {
        if (!isset($this->lastReads[$reader])) {
            return;
        }
        $this->lastReads[$reader] = null;
    }
    public function collect(int $reader) : DataInterface {
        $metric = $this->metric;
        if (($lastRead = $this->lastReads[$reader] ?? null) === null) {
            $temporality = Temporality::CUMULATIVE;
            $startTimestamp = $this->startTimestamp;
        }
        else {
            $temporality = Temporality::DELTA;
            $startTimestamp = $lastRead->timestamp;
            $this->lastReads[$reader] = $metric;
            $metric = $this->diff($lastRead, $metric);
        }
        return $this->aggregation
            ->toData($metric->attributes, $metric->summaries, Exemplar::groupByIndex($metric->exemplars), $startTimestamp, $metric->timestamp, $temporality);
    }
    private function diff(Metric $lastRead, Metric $metric) : Metric {
        $diff = clone $metric;
        foreach ($metric->summaries as $k => $summary) {
            if (!isset($lastRead->summaries[$k])) {
                continue;
            }
            $diff->summaries[$k] = $this->aggregation
                ->diff($lastRead->summaries[$k], $summary);
        }
        return $diff;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AsynchronousMetricStream::$lastReads private property @var array&lt;int, Metric|null&gt;
AsynchronousMetricStream::$metric private property
AsynchronousMetricStream::collect public function Collects metric data for the given reader. Overrides MetricStreamInterface::collect
AsynchronousMetricStream::diff private function
AsynchronousMetricStream::push public function Pushes metric data to the stream. Overrides MetricStreamInterface::push
AsynchronousMetricStream::register public function Registers a new reader with the given temporality. Overrides MetricStreamInterface::register
AsynchronousMetricStream::temporality public function Returns the internal temporality of this stream. Overrides MetricStreamInterface::temporality
AsynchronousMetricStream::timestamp public function Returns the last metric timestamp. Overrides MetricStreamInterface::timestamp
AsynchronousMetricStream::unregister public function Unregisters the given reader. Overrides MetricStreamInterface::unregister
AsynchronousMetricStream::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal