function Meter::createAsynchronousObserver
Return value
array{Instrument, ReferenceCounterInterface, RegisteredInstrument}
3 calls to Meter::createAsynchronousObserver()
- Meter::createObservableCounter in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates an `ObservableCounter`.
- Meter::createObservableGauge in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates an `ObservableGauge`.
- Meter::createObservableUpDownCounter in vendor/
open-telemetry/ sdk/ Metrics/ Meter.php - Creates an `ObservableUpDownCounter`.
File
-
vendor/
open-telemetry/ sdk/ Metrics/ Meter.php, line 343
Class
- Meter
- @internal
Namespace
OpenTelemetry\SDK\MetricsCode
private function createAsynchronousObserver(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 ($observer = $instruments->observers[$instrumentationScopeId][$instrumentId] ?? null) {
return $observer;
}
$stalenessHandler = $this->stalenessHandlerFactory
->create();
if ($this->config
->isEnabled()) {
$instruments->startTimestamp ??= $this->clock
->now();
$this->metricFactory
->createAsynchronousObserver($this->registry, $this->resource, $this->instrumentationScope, $instrument, $instruments->startTimestamp, $this->viewRegistrationRequests($instrument, $stalenessHandler));
}
$stalenessHandler->onStale(fn() => $this->releaseStreams($instrument));
$stalenessHandler->onStale(static function () use ($instruments, $instrumentationScopeId, $instrumentId) : void {
unset($instruments->observers[$instrumentationScopeId][$instrumentId]);
if (!$instruments->observers[$instrumentationScopeId]) {
unset($instruments->observers[$instrumentationScopeId]);
}
$instruments->startTimestamp = null;
});
return $instruments->observers[$instrumentationScopeId][$instrumentId] = [
$instrument,
$stalenessHandler,
new RegisteredInstrument(!$this->config
->isEnabled(), $this),
];
}