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

Breadcrumb

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

class TracerProvider

Hierarchy

  • class \OpenTelemetry\SDK\Trace\TracerProvider implements \OpenTelemetry\SDK\Trace\TracerProviderInterface

Expanded class hierarchy of TracerProvider

File

vendor/open-telemetry/sdk/Trace/TracerProvider.php, line 21

Namespace

OpenTelemetry\SDK\Trace
View source
final class TracerProvider implements TracerProviderInterface {
    private readonly TracerSharedState $tracerSharedState;
    private readonly InstrumentationScopeFactoryInterface $instrumentationScopeFactory;
    private readonly WeakMap $tracers;
    
    /** @param list<SpanProcessorInterface>|SpanProcessorInterface|null $spanProcessors */
    public function __construct(SpanProcessorInterface|array|null $spanProcessors = [], ?SamplerInterface $sampler = null, ?ResourceInfo $resource = null, ?SpanLimits $spanLimits = null, ?IdGeneratorInterface $idGenerator = null, ?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null, ?Configurator $configurator = null) {
        $spanProcessors ??= [];
        $spanProcessors = is_array($spanProcessors) ? $spanProcessors : [
            $spanProcessors,
        ];
        $resource ??= ResourceInfoFactory::defaultResource();
        $sampler ??= new ParentBased(new AlwaysOnSampler());
        $idGenerator ??= new RandomIdGenerator();
        $spanLimits ??= (new SpanLimitsBuilder())->build();
        $this->tracerSharedState = new TracerSharedState($idGenerator, $resource, $spanLimits, $sampler, $spanProcessors);
        $this->instrumentationScopeFactory = $instrumentationScopeFactory ?? new InstrumentationScopeFactory(Attributes::factory());
        $this->tracers = new WeakMap();
    }
    public function forceFlush(?CancellationInterface $cancellation = null) : bool {
        return $this->tracerSharedState
            ->getSpanProcessor()
            ->forceFlush($cancellation);
    }
    
    /**
     * @inheritDoc
     */
    public function getTracer(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []) : API\TracerInterface {
        if ($this->tracerSharedState
            ->hasShutdown()) {
            return NoopTracer::getInstance();
        }
        $scope = $this->instrumentationScopeFactory
            ->create($name, $version, $schemaUrl, $attributes);
        $tracer = new Tracer($this->tracerSharedState, $scope, $this->configurator);
        $this->tracers
            ->offsetSet($tracer, null);
        return $tracer;
    }
    public function getSampler() : SamplerInterface {
        return $this->tracerSharedState
            ->getSampler();
    }
    
    /**
     * Returns `false` is the provider is already shutdown, otherwise `true`.
     */
    public function shutdown(?CancellationInterface $cancellation = null) : bool {
        if ($this->tracerSharedState
            ->hasShutdown()) {
            return true;
        }
        return $this->tracerSharedState
            ->shutdown($cancellation);
    }
    public static function builder() : TracerProviderBuilder {
        return new TracerProviderBuilder();
    }
    
    /**
     * Update the {@link Configurator} for a {@link TracerProvider}, which will
     * reconfigure all tracers created from the provider.
     * @experimental
     */
    public function updateConfigurator(Configurator $configurator) : void {
        $this->configurator = $configurator;
        foreach ($this->tracers as $tracer => $unused) {
            $tracer->updateConfig($configurator);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
TracerProvider::$instrumentationScopeFactory private property
TracerProvider::$tracers private property
TracerProvider::$tracerSharedState private property
TracerProvider::builder public static function
TracerProvider::forceFlush public function Overrides TracerProviderInterface::forceFlush
TracerProvider::getSampler public function
TracerProvider::getTracer public function @inheritDoc
TracerProvider::shutdown public function Returns `false` is the provider is already shutdown, otherwise `true`. Overrides TracerProviderInterface::shutdown
TracerProvider::updateConfigurator public function Update the {@link Configurator} for a {@link TracerProvider}, which will
reconfigure all tracers created from the provider.
@experimental
Overrides Configurable::updateConfigurator
TracerProvider::__construct public function
RSS feed
Powered by Drupal