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

Breadcrumb

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

class SynchronousMetricStream

@internal @phan-file-suppress PhanUndeclaredTypeParameter, PhanUndeclaredTypeProperty

Hierarchy

  • class \OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream implements \OpenTelemetry\SDK\Metrics\Stream\MetricStreamInterface uses \OpenTelemetry\API\Behavior\LogsMessagesTrait

Expanded class hierarchy of SynchronousMetricStream

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

File

vendor/open-telemetry/sdk/Metrics/Stream/SynchronousMetricStream.php, line 24

Namespace

OpenTelemetry\SDK\Metrics\Stream
View source
final class SynchronousMetricStream implements MetricStreamInterface {
    use LogsMessagesTrait;
    private readonly DeltaStorage $delta;
    private int|GMP $readers = 0;
    private int|GMP $cumulative = 0;
    
    /**
     * @todo rector mistakenly makes $timestamp readonly, which conflicts with `self::push`. disabled in rector.php
     */
    public function __construct(AggregationInterface $aggregation, int $timestamp) {
        $this->delta = new DeltaStorage($this->aggregation);
    }
    public function temporality() : Temporality|string {
        return Temporality::DELTA;
    }
    public function timestamp() : int {
        return $this->timestamp;
    }
    public function push(Metric $metric) : void {
        [
            $this->timestamp,
            $metric->timestamp,
        ] = [
            $metric->timestamp,
            $this->timestamp,
        ];
        $this->delta
            ->add($metric, $this->readers);
    }
    public function register($temporality) : int {
        $reader = 0;
        for ($r = $this->readers; ($r & 1) != 0; $r >>= 1, $reader++) {
        }
        if ($reader === (PHP_INT_SIZE << 3) - 1 && is_int($this->readers)) {
            if (!extension_loaded('gmp')) {
                self::logWarning(sprintf('GMP extension required to register over %d readers', (PHP_INT_SIZE << 3) - 1));
                $reader = PHP_INT_SIZE << 3;
            }
            else {
                assert(is_int($this->cumulative));
                $this->readers = gmp_init($this->readers);
                $this->cumulative = gmp_init($this->cumulative);
            }
        }
        $readerMask = ($this->readers & 1 | 1) << $reader;
        $this->readers ^= $readerMask;
        if ($temporality === Temporality::CUMULATIVE) {
            $this->cumulative ^= $readerMask;
        }
        return $reader;
    }
    public function unregister(int $reader) : void {
        $readerMask = ($this->readers & 1 | 1) << $reader;
        if (($this->readers & $readerMask) == 0) {
            return;
        }
        $this->delta
            ->collect($reader);
        $this->readers ^= $readerMask;
        if (($this->cumulative & $readerMask) != 0) {
            $this->cumulative ^= $readerMask;
        }
    }
    public function collect(int $reader) : DataInterface {
        $cumulative = ($this->cumulative >> $reader & 1) != 0;
        $metric = $this->delta
            ->collect($reader, $cumulative) ?? new Metric([], [], $this->timestamp);
        $temporality = $cumulative ? Temporality::CUMULATIVE : Temporality::DELTA;
        return $this->aggregation
            ->toData($metric->attributes, $metric->summaries, Exemplar::groupByIndex($metric->exemplars), $metric->timestamp, $this->timestamp, $temporality);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
LogsMessagesTrait::doLog private static function
LogsMessagesTrait::logDebug protected static function
LogsMessagesTrait::logError protected static function
LogsMessagesTrait::logInfo protected static function
LogsMessagesTrait::logNotice protected static function
LogsMessagesTrait::logWarning protected static function
LogsMessagesTrait::shouldLog private static function
SynchronousMetricStream::$cumulative private property
SynchronousMetricStream::$delta private property
SynchronousMetricStream::$readers private property
SynchronousMetricStream::collect public function Collects metric data for the given reader. Overrides MetricStreamInterface::collect
SynchronousMetricStream::push public function Pushes metric data to the stream. Overrides MetricStreamInterface::push
SynchronousMetricStream::register public function Registers a new reader with the given temporality. Overrides MetricStreamInterface::register
SynchronousMetricStream::temporality public function Returns the internal temporality of this stream. Overrides MetricStreamInterface::temporality
SynchronousMetricStream::timestamp public function Returns the last metric timestamp. Overrides MetricStreamInterface::timestamp
SynchronousMetricStream::unregister public function Unregisters the given reader. Overrides MetricStreamInterface::unregister
SynchronousMetricStream::__construct public function @todo rector mistakenly makes $timestamp readonly, which conflicts with `self::push`. disabled in rector.php

API Navigation

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