trait SynchronousInstrumentTrait
@internal
Hierarchy
- trait \OpenTelemetry\SDK\Metrics\SynchronousInstrumentTrait
File
-
vendor/
open-telemetry/ sdk/ Metrics/ SynchronousInstrumentTrait.php, line 13
Namespace
OpenTelemetry\SDK\MetricsView source
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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
SynchronousInstrumentTrait::$instrument | private | property | |
SynchronousInstrumentTrait::$referenceCounter | private | property | |
SynchronousInstrumentTrait::$writer | private | property | |
SynchronousInstrumentTrait::getHandle | public | function | |
SynchronousInstrumentTrait::isEnabled | public | function | |
SynchronousInstrumentTrait::write | public | function | |
SynchronousInstrumentTrait::__construct | public | function | |
SynchronousInstrumentTrait::__destruct | public | function |