class CachedInstrumentation
Provides access to cached {@link TracerInterface} and {@link MeterInterface} instances.
Autoinstrumentation should prefer using a {@link CachedInstrumentation} instance over repeatedly obtaining instrumentation instances from {@link Globals}.
Hierarchy
- class \OpenTelemetry\API\Instrumentation\CachedInstrumentation
Expanded class hierarchy of CachedInstrumentation
File
-
vendor/
open-telemetry/ api/ Instrumentation/ CachedInstrumentation.php, line 26
Namespace
OpenTelemetry\API\InstrumentationView source
final class CachedInstrumentation {
/** @var WeakMap<TracerProviderInterface, TracerInterface> */
private WeakMap $tracers;
/** @var WeakMap<MeterProviderInterface, MeterInterface> */
private WeakMap $meters;
/** @var WeakMap<LoggerProviderInterface, LoggerInterface> */
private WeakMap $loggers;
/** @var WeakMap<EventLoggerProviderInterface, EventLoggerInterface> */
private WeakMap $eventLoggers;
/**
* @psalm-suppress PropertyTypeCoercion
*/
public function __construct(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []) {
$this->tracers = new \WeakMap();
$this->meters = new \WeakMap();
$this->loggers = new \WeakMap();
$this->eventLoggers = new \WeakMap();
}
public function tracer() : TracerInterface {
$tracerProvider = Globals::tracerProvider();
return $this->tracers[$tracerProvider] ??= $tracerProvider->getTracer($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
public function meter() : MeterInterface {
$meterProvider = Globals::meterProvider();
return $this->meters[$meterProvider] ??= $meterProvider->getMeter($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
public function logger() : LoggerInterface {
$loggerProvider = Globals::loggerProvider();
return $this->loggers[$loggerProvider] ??= $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
public function eventLogger() : EventLoggerInterface {
$eventLoggerProvider = Globals::eventLoggerProvider();
return $this->eventLoggers[$eventLoggerProvider] ??= $eventLoggerProvider->getEventLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
CachedInstrumentation::$eventLoggers | private | property | @var WeakMap<EventLoggerProviderInterface, EventLoggerInterface> |
CachedInstrumentation::$loggers | private | property | @var WeakMap<LoggerProviderInterface, LoggerInterface> |
CachedInstrumentation::$meters | private | property | @var WeakMap<MeterProviderInterface, MeterInterface> |
CachedInstrumentation::$tracers | private | property | @var WeakMap<TracerProviderInterface, TracerInterface> |
CachedInstrumentation::eventLogger | public | function | |
CachedInstrumentation::logger | public | function | |
CachedInstrumentation::meter | public | function | |
CachedInstrumentation::tracer | public | function | |
CachedInstrumentation::__construct | public | function | @psalm-suppress PropertyTypeCoercion |