in prod/php/ElasticOTel/InferredSpans/InferredSpans.php [395:427]
private function endFrameSpan(array $frame, bool $dropSpan, ?int $endEpochNanos = null): void
{
if (!array_key_exists(self::METADATA_SPAN, $frame)) { // @phpstan-ignore function.alreadyNarrowedType
self::logError("endFrameSpan missing metadata.", [$frame]);
return;
}
if (!$dropSpan) {
$dropSpan = $this->shouldDropTooShortSpan($frame, $endEpochNanos);
}
$span = $frame[self::METADATA_SPAN]->get();
if (!$span instanceof Span) {
self::logDebug("Span in frame is not instanceof Trace\Span", [$span, $frame]);
return;
}
if ($dropSpan) {
self::logDebug("Span dropped: " . $span->getName() . ' StackTraceId: ' . $frame[self::METADATA_STACKTRACE_ID]);
$frame[self::METADATA_SCOPE]->get()?->detach();
return;
}
$scope = Context::storage()->scope();
$scope?->detach();
if (!$scope || $scope->context() === Context::getCurrent()) {
return;
}
$span->end($endEpochNanos);
self::logDebug("Span finished: " . $span->getName() . ' StackTraceId: ' . $frame[self::METADATA_STACKTRACE_ID]);
}