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

Breadcrumb

  1. Drupal Core 11.1.x
  2. CachedInstrumentation.php

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\Instrumentation
View 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&lt;EventLoggerProviderInterface, EventLoggerInterface&gt;
CachedInstrumentation::$loggers private property @var WeakMap&lt;LoggerProviderInterface, LoggerInterface&gt;
CachedInstrumentation::$meters private property @var WeakMap&lt;MeterProviderInterface, MeterInterface&gt;
CachedInstrumentation::$tracers private property @var WeakMap&lt;TracerProviderInterface, TracerInterface&gt;
CachedInstrumentation::eventLogger public function
CachedInstrumentation::logger public function
CachedInstrumentation::meter public function
CachedInstrumentation::tracer public function
CachedInstrumentation::__construct public function @psalm-suppress PropertyTypeCoercion

API Navigation

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