finishedSpanContexts[] = $context; } /** * Get the list of finished spans. * @return SpanContext[] */ public function getSpanContexts(): array { return $this->finishedSpanContexts; } /** * Clear the list of finished spans. */ public function clearSpanContexts(): void { $this->finishedSpanContexts = []; } /** * Make the given span the active span. * @param SpanContext $spanContext Context of the span to activate * @return void */ public function activateSpan( SpanContext $spanContext ): void { $this->activeSpanContextStack[] = $spanContext; } /** * Deactivate the given span, if it was the active span. * @param SpanContext $spanContext Context of the span to deactivate * @return void */ public function deactivateSpan( SpanContext $spanContext ): void { $activeSpanContext = $this->getActiveSpanContext(); Assert::invariant( $activeSpanContext !== null && $activeSpanContext->getSpanId() === $spanContext->getSpanId(), 'Attempted to deactivate a span which is not the active span.' ); array_pop( $this->activeSpanContextStack ); } /** * Get the context of the currently active span, or `null` if no span is active. * @return SpanContext|null */ public function getActiveSpanContext(): ?SpanContext { return $this->activeSpanContextStack[count( $this->activeSpanContextStack ) - 1] ?? null; } }