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

Breadcrumb

  1. Drupal Core 11.1.x

InMemoryExporter.php

Same filename in this branch
  1. 11.1.x vendor/open-telemetry/sdk/Trace/SpanExporter/InMemoryExporter.php
  2. 11.1.x vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php

Namespace

OpenTelemetry\SDK\Metrics\MetricExporter

File

vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporter.php

View source
<?php

declare (strict_types=1);
namespace OpenTelemetry\SDK\Metrics\MetricExporter;

use function array_push;
use OpenTelemetry\SDK\Metrics\AggregationTemporalitySelectorInterface;
use OpenTelemetry\SDK\Metrics\Data\Metric;
use OpenTelemetry\SDK\Metrics\Data\Temporality;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use OpenTelemetry\SDK\Metrics\MetricMetadataInterface;

/**
 * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/in-memory.md
 */
final class InMemoryExporter implements MetricExporterInterface, AggregationTemporalitySelectorInterface {
    
    /**
     * @var list<Metric>
     */
    private array $metrics = [];
    private bool $closed = false;
    public function __construct(string|Temporality|null $temporality = null) {
    }
    public function temporality(MetricMetadataInterface $metric) : string|Temporality|null {
        return $this->temporality ?? $metric->temporality();
    }
    
    /**
     * @return list<Metric>
     */
    public function collect(bool $reset = false) : array {
        $metrics = $this->metrics;
        if ($reset) {
            $this->metrics = [];
        }
        return $metrics;
    }
    public function export(iterable $batch) : bool {
        if ($this->closed) {
            return false;
        }
        
        /** @psalm-suppress InvalidPropertyAssignmentValue */
        array_push($this->metrics, ...$batch);
        return true;
    }
    public function shutdown() : bool {
        if ($this->closed) {
            return false;
        }
        $this->closed = true;
        return true;
    }

}

Classes

Title Deprecated Summary
InMemoryExporter

API Navigation

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