|SpanProcessorInterface|null $spanProcessors */ public function __construct( $spanProcessors = [], SamplerInterface $sampler = null, ResourceInfo $resource = null, SpanLimits $spanLimits = null, IdGeneratorInterface $idGenerator = null, ?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null ) { if (null === $spanProcessors) { $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()); } 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(); } return new Tracer( $this->tracerSharedState, $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes), ); } 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(); } }