protected function __construct()

in agent/php/ElasticApm/Impl/ExecutionSegment.php [114:187]


    protected function __construct(
        Tracer $tracer,
        ?ExecutionSegment $parentExecutionSegment,
        string $traceId,
        string $name,
        string $type,
        ?float $sampleRate,
        ?float $timestampArg = null
    ) {
        $monotonicClockNow = $tracer->getClock()->getMonotonicClockCurrentTime();
        $systemClockNow = $tracer->getClock()->getSystemClockCurrentTime();

        $this->id = IdGenerator::generateId(Constants::EXECUTION_SEGMENT_ID_SIZE_IN_BYTES);

        $this->systemClockBeginTime = $systemClockNow;
        if ($timestampArg === null) {
            $this->timestamp = $systemClockNow;
        } elseif ($timestampArg <= $systemClockNow) {
            $this->timestamp = $timestampArg;
        } else {
            $this->timestamp = $systemClockNow;

            $localLogger = self::createLogger($tracer->loggerFactory());
            ($loggerProxy = $localLogger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
            && $loggerProxy->log(
                'Using systemClockNow for start time instead of timestampArg argument'
                . ' because timestampArg argument is later (further into the future) than systemClockNow',
                [
                    'systemClockNow' => $systemClockNow,
                    'timestampArg'   => $timestampArg,
                    'timestampArg - systemClockNow (seconds)'
                                     => TimeUtil::microsecondsToSeconds($timestampArg - $systemClockNow),
                    'id'             => $this->id,
                    'name'           => $name,
                    'type'           => $type,
                ]
            );
        }
        $this->diffStartTimeWithSystemClockOnBeginInMicroseconds = TimeUtil::calcDurationInMicrosecondsClampNegativeToZero($this->timestamp, $systemClockNow);
        $this->monotonicBeginTime = $monotonicClockNow;
        $this->traceId = $traceId;
        $this->setName($name);
        $this->setType($type);
        $this->sampleRate = $sampleRate;

        if ($this->containingTransaction()->getConfig()->breakdownMetrics()) {
            $this->breakdownMetricsSelfTimeTracker = new BreakdownMetricsSelfTimeTracker($monotonicClockNow);
            if ($parentExecutionSegment !== null) {
                /**
                 * If breakdownMetrics config is true then all transaction's spans
                 * breakdownMetricsSelfTimeTracker should not be null
                 *
                 * Local variable to workaround PHPStan not having a way to declare that
                 * $parentExecutionSegment->breakdownMetricsSelfTimeTracker is not null
                 *
                 * @var BreakdownMetricsSelfTimeTracker $parentBreakdownMetricsSelfTimeTracker
                 */
                $parentBreakdownMetricsSelfTimeTracker = $parentExecutionSegment->breakdownMetricsSelfTimeTracker;
                $parentBreakdownMetricsSelfTimeTracker->onChildBegin($monotonicClockNow);
            }
        }

        $this->logger = self::createLogger($tracer->loggerFactory())->addContext('this', $this);
        ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
        && $loggerProxy->log(
            'Exiting...',
            [
                'systemClockNow' => $systemClockNow,
                'timestampArg'   => $timestampArg,
                'systemClockNow - timestampArg (seconds)'
                                 => TimeUtil::microsecondsToSeconds($systemClockNow - $timestampArg),
            ]
        );
    }