void onRequestInit()

in prod/native/libcommon/code/RequestScope.h [46:116]


    void onRequestInit() {
        ELOGF_DEBUG(log_, REQUEST, "%s", __FUNCTION__);

        resetRequest();

        if (!sapi_->isSupported()) {
            ELOGF_DEBUG(log_, REQUEST, "SAPI '%s' not supported", sapi_->getName().data());
            return;
        }

        config_->update();

        if (!(*config_)->enabled) {
            ELOGF_DEBUG(log_, REQUEST, "Global instrumentation not enabled");
            return;
        }

        requestCounter_++;

        if (requestCounter_ == 1) {
            dependencyGuard_->setBootstrapPath((*config_)->bootstrap_php_part_file);
        }

        auto requestStartTime = std::chrono::system_clock::now();

        bridge_->enableAccessToServerGlobal();

        preloadDetected_ = requestCounter_ == 1 ? bridge_->detectOpcachePreload() : false;

        dependencyGuard_->onRequestInit();

        if (requestCounter_ == 1 && preloadDetected_) {
            ELOGF_DEBUG(log_, REQUEST, "opcache.preload request detected on init");
            return;
        } else if (!preloadDetected_ && requestCounter_ <= 2) {
            auto const &diagnosticFile = (*config_)->debug_diagnostic_file;
            if (!diagnosticFile.empty()) {
                if (sharedMemory_->shouldExecuteOneTimeTaskAmongWorkers()) {
                    try {
                        // TODO log supportability info
                        elasticapm::utils::storeDiagnosticInformation(elasticapm::utils::getParameterizedString(diagnosticFile), *(bridge_));
                    } catch (std::exception const &e) {
                        ELOGF_WARNING(log_, REQUEST, "Unable to write agent diagnostics: %s", e.what());
                    }
                }
            }
        }

        if (!bridge_->isScriptRestricedByOpcacheAPI() && bridge_->detectOpcacheRestartPending()) {
            ELOGF_WARNING(log_, REQUEST, "Detected that opcache reset is in a pending state. Instrumentation has been disabled for this request. There may be warnings or errors logged for this request.");
            return;
        }

        bootstrapSuccessfull_ = bootstrapPHPSideInstrumentation(requestStartTime);

        if (bootstrapSuccessfull_ && (*config_)->inferred_spans_enabled) {
            auto periodicTaskExecutor = getPeriodicTaskExecutor_();
            auto interval = (*config_)->inferred_spans_sampling_interval;

            if (interval.count() == 0) {
                interval = std::chrono::milliseconds{ConfigurationSnapshot().ELASTIC_OTEL_CFG_OPT_NAME_INFERRED_SPANS_SAMPLING_INTERVAL};
                ELOGF_DEBUG(log_, REQUEST, "inferred spans thread interval too low, forced to default %zums", interval.count());
            }

            ELOGF_DEBUG(log_, REQUEST, "resuming inferred spans thread with sampling interval %zums", interval.count());
            inferredSpans_->setInterval(interval);
            inferredSpans_->reset();
            periodicTaskExecutor->setInterval(interval);
            periodicTaskExecutor->resumePeriodicTasks();
        }
    }