function Meter::createSynchronousWriter
Return value
array{Instrument, ReferenceCounterInterface, RegisteredInstrument}
4 calls to Meter::createSynchronousWriter()
- Meter::createCounter in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates a `Counter`.
- Meter::createGauge in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates a `Gauge`.
- Meter::createHistogram in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates a `Histogram`.
- Meter::createUpDownCounter in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates an `UpDownCounter`.
File
-
vendor/
open-telemetry/ sdk/ Metrics/ Meter.php, line 297
Class
- Meter
- @internal
Namespace
OpenTelemetry\SDK\MetricsCode
private function createSynchronousWriter(string|InstrumentType $instrumentType, string $name, ?string $unit, ?string $description, array $advisory = []) : array {
$instrument = new Instrument($instrumentType, $name, $unit, $description, $advisory);
$instrumentationScopeId = $this->instrumentationScopeId($this->instrumentationScope);
$instrumentId = $this->instrumentId($instrument);
$instruments = $this->instruments;
if ($writer = $instruments->writers[$instrumentationScopeId][$instrumentId] ?? null) {
return $writer;
}
$stalenessHandler = $this->stalenessHandlerFactory
->create();
if ($this->config
->isEnabled()) {
$instruments->startTimestamp ??= $this->clock
->now();
$this->metricFactory
->createSynchronousWriter($this->registry, $this->resource, $this->instrumentationScope, $instrument, $instruments->startTimestamp, $this->viewRegistrationRequests($instrument, $stalenessHandler), $this->exemplarFilter);
}
$stalenessHandler->onStale(fn() => $this->releaseStreams($instrument));
$stalenessHandler->onStale(static function () use ($instruments, $instrumentationScopeId, $instrumentId) : void {
unset($instruments->writers[$instrumentationScopeId][$instrumentId]);
if (!$instruments->writers[$instrumentationScopeId]) {
unset($instruments->writers[$instrumentationScopeId]);
}
$instruments->startTimestamp = null;
});
return $instruments->writers[$instrumentationScopeId][$instrumentId] = [
$instrument,
$stalenessHandler,
new RegisteredInstrument(!$this->config
->isEnabled(), $this),
];
}