private function tryToAllocateToBeSent()

in agent/php/ElasticApm/Impl/InferredSpansBuilder.php [240:287]


    private function tryToAllocateToBeSent(InferredSpanFrame $frame, ?int $toBeSentDescendantIndex): bool
    {
        $loggerTrace = $this->logger->ifTraceLevelEnabledNoLine(__FUNCTION__);

        if ($frame->duration < $this->minDurationInMilliseconds) {
            $loggerTrace && $loggerTrace->log(
                __LINE__,
                "Frame will NOT be sent as inferred span because its duration is below configured minimum",
                [
                    'frame' => $frame,
                    OptionNames::PROFILING_INFERRED_SPANS_MIN_DURATION . ' (milliseconds)'
                            => $this->minDurationInMilliseconds,
                ]
            );
            return false;
        }

        if ($toBeSentDescendantIndex !== null) {
            $toBeSentDescendant = $this->openFramesReverseOrder[$toBeSentDescendantIndex];
            if ($frame->duration <= $toBeSentDescendant->duration) {
                $loggerTrace && $loggerTrace->log(
                    __LINE__,
                    "Frame will NOT be sent as inferred span"
                    . " because it's duration is not greater than nearest sent descendant",
                    ['frame' => $frame, 'toBeSentDescendant' => $toBeSentDescendant]
                );
                return false;
            }
        }

        if (!$this->transaction->tryToAllocateStartedSpan()) {
            $loggerTrace && $loggerTrace->log(
                __LINE__,
                "Frame will NOT be sent as inferred span"
                . " because the current transaction reached configured started spans limit",
                ['frame' => $frame]
            );
            return false;
        }

        $loggerTrace && $loggerTrace->log(
            __LINE__,
            "Frame will be sent as inferred span because it satisfies all the requirements",
            ['frame' => $frame]
        );
        $frame->markAsAllocatedToBeSent();
        return true;
    }