Elastic PHP APM Agent does not report

Hello,

I am trying out elastic APM for monitoring a php application. So apologies if I am asking a dumb question.

The APM server is running on elastic cloud. So that's solved there, but the problem lies in the PHP Agent. The agent is installed and I can see it in running with the phpinfo() command. However, there is a total of 0 data going back to elastic cloud.

To test things out I am running a test environment on a single AWS EC2 instance running Amazon Linux 2. I was able to get the heartbeat monitor working (more of a sanity check than anything) after hitting this roadblock.

The EC2 instance is running php 7.4.15. Elastic APM Agent 1.4.2 was installed through the rpm posted on github. The php.ini, which is reflected on phpinfo(), has 6 additions.

elastic_apm.server_url="https://longURL.aws.cloud.es.io:443"
elastic.apm.secret_token="secretToken"
elastic_apm.service_name="testing"
elastic_apm.environment="testing"
elastic_apm.service_node_name="testing"
elastic_apm.service_version="1"

The default option of bootstrap_php_part_file is being read, and it exists.
/opt/elastic/apm-agent-php/src/bootstrap_php_part.php

I am seeing the heartbeat in the syslog. Heyyy, as I was typing this I finally found something.

Mar 18 22:04:49 testserver httpd: [Elastic APM PHP Tracer] 2022-03-18 17:04:49.574768-05:00 [PID: 10511] [TID: 10511] [ERROR]    [Util] [util_for_PHP.c:141] [callPhpFunction] call_user_function failed. Return value: -1. PHP function name: `\Elastic\Apm\Impl\AutoInstrument\PhpPartFacade::interceptedCallPostHook'. argsCount: 2.
Mar 18 22:04:49 testserver httpd: [Elastic APM PHP Tracer] 2022-03-18 17:04:49.574852-05:00 [PID: 10511] [TID: 10511] [ERROR]    [Util] [util_for_PHP.c:154] [callPhpFunction] Exiting...; resultCode: resultFailure (4);
Mar 18 22:04:49 testserver httpd: [Elastic APM PHP Tracer] 2022-03-18 17:04:49.574867-05:00 [PID: 10511] [TID: 10511] [ERROR]    [C-to-PHP] [tracer_PHP_part.c:208] [tracerPhpPartInterceptedCallPostHook] Exiting...; resultCode: resultFailure (4); dbgInterceptRegistrationId: 10; interceptedCallRetValOrThrown type: 2.

So where can I start checking the logs on the logger?

Edit:

So I found where the exception is being called in InerceptionManager.php, but I'm still not exactly sure where to reverse from here.

/**
     * @param int             $numberOfStackFramesToSkip
     * @param bool            $hasExitedByException
     * @param mixed|Throwable $returnValueOrThrown                 Return value of the intercepted call
     *                                                             or the object thrown by the intercepted call
     *
     * @noinspection PhpMissingParamTypeInspection
     */
    public function interceptedCallPostHook(
        int $numberOfStackFramesToSkip,
        bool $hasExitedByException,
        $returnValueOrThrown
    ): void {
        ($loggerProxy = $this->logger->ifTraceLevelEnabled(__LINE__, __FUNCTION__))
        && $loggerProxy->log('Entered');

        if ($this->interceptedCallInProgressRegistrationId === null) {
            ($loggerProxy = $this->logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__))
            && $loggerProxy->log('There is no intercepted call in progress');
            return;
        }
        assert($this->interceptedCallInProgressArgs !== null);
        assert($this->interceptedCallInProgressRegistration !== null);
        assert($this->interceptedCallInProgressPreHookRetVal !== null);

        $localLogger = $this->logger->inherit()->addAllContext(
            [
                'interceptRegistrationId' => $this->interceptedCallInProgressRegistrationId,
                'interceptRegistration'   => $this->interceptedCallInProgressRegistration,
            ]
        );

        try {
            ($this->interceptedCallInProgressPreHookRetVal)(
                $numberOfStackFramesToSkip + 1,
                $hasExitedByException,
                $returnValueOrThrown
            );
        } catch (Throwable $throwable) {
            ($loggerProxy = $localLogger->ifErrorLevelEnabled(__LINE__, __FUNCTION__))
            && $loggerProxy->logThrowable(
                $throwable,
                'postHook has let a Throwable to escape'
            );
        }

        $this->interceptedCallInProgressRegistrationId = null;
        $this->interceptedCallInProgressThisObj = null;
        $this->interceptedCallInProgressArgs = null;
        $this->interceptedCallInProgressPreHookRetVal = null;
    }

Thanks

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.