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

Breadcrumb

  1. Drupal Core 11.1.x

SynchronousInstrumentTrait.php

Namespace

OpenTelemetry\SDK\Metrics

File

vendor/open-telemetry/sdk/Metrics/SynchronousInstrumentTrait.php

View source
<?php

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

use function assert;
use OpenTelemetry\SDK\Metrics\MetricRegistry\MetricWriterInterface;

/**
 * @internal
 */
trait SynchronousInstrumentTrait {
    private MetricWriterInterface $writer;
    private Instrument $instrument;
    private ReferenceCounterInterface $referenceCounter;
    public function __construct(MetricWriterInterface $writer, Instrument $instrument, ReferenceCounterInterface $referenceCounter) {
        assert($this instanceof InstrumentHandle);
        $this->writer = $writer;
        $this->instrument = $instrument;
        $this->referenceCounter = $referenceCounter;
        $this->referenceCounter
            ->acquire();
    }
    public function __destruct() {
        $this->referenceCounter
            ->release();
    }
    public function getHandle() : Instrument {
        return $this->instrument;
    }
    public function write($amount, iterable $attributes = [], $context = null) : void {
        if ($this->isEnabled()) {
            $this->writer
                ->record($this->instrument, $amount, $attributes, $context);
        }
    }
    public function isEnabled() : bool {
        return $this->writer
            ->enabled($this->instrument);
    }

}

Traits

Title Deprecated Summary
SynchronousInstrumentTrait @internal

API Navigation

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