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

Breadcrumb

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

class BucketStorage

@internal

Hierarchy

  • class \OpenTelemetry\SDK\Metrics\Exemplar\BucketStorage

Expanded class hierarchy of BucketStorage

File

vendor/open-telemetry/sdk/Metrics/Exemplar/BucketStorage.php, line 19

Namespace

OpenTelemetry\SDK\Metrics\Exemplar
View source
final class BucketStorage {
    
    /** @var array<int, BucketEntry|null> */
    private array $buckets;
    public function __construct(int $size = 0) {
        $this->buckets = array_fill(0, $size, null);
    }
    public function store(int $bucket, int|string $index, float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp) : void {
        assert($bucket <= count($this->buckets));
        $exemplar = $this->buckets[$bucket] ??= new BucketEntry();
        $exemplar->index = $index;
        $exemplar->value = $value;
        $exemplar->timestamp = $timestamp;
        $exemplar->attributes = $attributes;
        if (($spanContext = Span::fromContext($context)->getContext())
            ->isValid()) {
            $exemplar->traceId = $spanContext->getTraceId();
            $exemplar->spanId = $spanContext->getSpanId();
        }
        else {
            $exemplar->traceId = null;
            $exemplar->spanId = null;
        }
    }
    
    /**
     * @param array<AttributesInterface> $dataPointAttributes
     * @return array<Exemplar>
     */
    public function collect(array $dataPointAttributes) : array {
        $exemplars = [];
        foreach ($this->buckets as $index => &$exemplar) {
            if (!$exemplar) {
                continue;
            }
            $exemplars[$index] = new Exemplar($exemplar->index, $exemplar->value, $exemplar->timestamp, $this->filterExemplarAttributes($dataPointAttributes[$exemplar->index], $exemplar->attributes), $exemplar->traceId, $exemplar->spanId);
            $exemplar = null;
        }
        return $exemplars;
    }
    private function filterExemplarAttributes(AttributesInterface $dataPointAttributes, AttributesInterface $exemplarAttributes) : AttributesInterface {
        $attributes = [];
        foreach ($exemplarAttributes as $key => $value) {
            if ($dataPointAttributes->get($key) === null) {
                $attributes[$key] = $value;
            }
        }
        return new Attributes($attributes, $exemplarAttributes->getDroppedAttributesCount());
    }

}

Members

Title Sort descending Modifiers Object type Summary
BucketStorage::$buckets private property @var array&lt;int, BucketEntry|null&gt;
BucketStorage::collect public function
BucketStorage::filterExemplarAttributes private function
BucketStorage::store public function
BucketStorage::__construct public function

API Navigation

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