ElasticApm class not found after configuration (Laravel)

I did what Elastic PHP agent tutorial says and have:

  • elastic_apm plugin shown in php info :white_check_mark:
  • can use ElasticApm class :x:

when I import ElasticApm class with use Elastic\Apm\ElasticApm I'm getting

Class 'Elastic\Apm\ElasticApm' not found

This is in production server.. I've restarted server and run the install process several times, but I was not able to fix it yet, so anything can be helpful

Screen Shot 2023-03-28 at 20.38.55
Screen Shot 2023-03-28 at 20.39.05

Hey Thiago

Thank you for reporting this issue. Could you please provide us a bit more details?

  • How you installed agent, from package or manually compiled?
  • Did you verified that path specified in php.ini setting elastic_apm.bootstrap_php_part_file is correct and point to existing agent bootstrap file?
  • Is the path to agent bootstrap compatible with the PHP configuration? I mean compatibility with https://www.php.net/manual/en/ini.core.php#ini.open-basedir
  • Please provide us a full output from phpinfo(). It might be html, pdf or screenshoots. Please keep in mind that it may contain sensitive data, like session data, keys, passwords, environment variables. Please remove this kind of data before publishing it.
  • Could you please attach agent logs? Here is a documentation how to enable logging https://www.elastic.co/guide/en/apm/agent/php/current/configuration.html#configure-logging. I suggest to set log level to TRACE. Depending on preferred output mode it can be one of following:
elastic_apm.log_file=/path/to/file.txt
elastic_apm.log_level_file=TRACE
elastic_apm.log_level_syslog=TRACE
elastic_apm.log_level_stderr=TRACE

Best regards,
Pawel

1 Like

Thanks for the reply @Pawel_Filipczak

  • How you installed agent, from package or manually compiled?
    Mannually

  • Did you verified that path specified in php.ini setting elastic_apm.bootstrap_php_part_file is correct and point to existing agent bootstrap file?
    Yes it is pointing to an existing path

  • Is the path to agent bootstrap compatible with the PHP configuration? I mean compatibility with PHP: Description of core php.ini directives - Manual
    I'm not sure how to answer this one

  • Please provide us a full output from phpinfo(). It might be html, pdf or screenshoots. Please keep in mind that it may contain sensitive data, like session data, keys, passwords, environment variables. Please remove this kind of data before publishing it.
    Attached

  • Could you please attach agent logs? Here is a documentation how to enable logging Configuration | APM PHP Agent Reference [1.x] | Elastic. I suggest to set log level to TRACE. Depending on preferred output mode it can be one of following:
    Enabled

This is my entire php.ini configuration about elastic-apm:

extension=elastic_apm.so
elastic_apm.bootstrap_php_part_file=/opt/apm-agent-php/src/bootstrap_php_part.php
elastic_apm.server_url=https://quick-rats-remain-191-177-48-160.loca.lt
elastic_apm.service_name="reuni-apm-PROD"
elastic_apm.enabled=true
elastic_apm.log_file=/opt/apm-agent-php/apm-agent-log.txt
elastic_apm.log_level=TRACE
elastic_apm.log_level_syslog=TRACE
elastic_apm.log_level_stderr=TRACE
elastic_apm.environment=production

Adding to this, I tried to force Laravel to find ElasticApm compiled classes, so I copied it to laravel folder, renaming namespace to make it be found.
Actually it dit found classes after this, but the transactions data was not complete,
it just register the name of transaction:
(production)
Screen Shot 2023-03-29 at 09.46.29

While in my container it shows every request:
(development) - I want that in production it logs as much as this
Screen Shot 2023-03-29 at 09.47.45

The code used was the same for both:

Screen Shot 2023-03-29 at 09.48.39

Thank @Thiago_Medeiros you for providing more data

I'm not sure how to answer this one
I thought about checking if /opt-apm-agent-php/ path is accessible from PHP.
If open_basedir is configured in php.ini to some other location then PHP will not be able to access agent files.

Could you attach content of /opt/apm-agent-php/apm-agent-log.txt log file when you was trying to reproduce bug from first post?

Please add this line to php.ini - it was my mistake, I forgot about it:
elastic_apm.log_level_file=TRACE

Thank you,
Pawel

Thanks again @Pawel_Filipczak youre giving me the feeling that I will solve this issue some how

Yes I've confirmed that my files are visible by open_basedir:
Screen Shot 2023-03-30 at 04.24.51

Screen Shot 2023-03-30 at 04.25.33

about the log file, it does not exits.

But, importing still not works:
Screen Shot 2023-03-30 at 04.28.31

Plus info
I can add a label to the transaction

but what I really need are the http requests data, that is being captured

Any Idea?

Hey @Thiago_Medeiros

Did you tried to get logs from syslog or stderr? Please also try to get php error log (you can enable it and redirect to file via php.ini https://www.php.net/manual/en/errorfunc.configuration.php)

Could you also provide a code snippets where you're using agent API?

  • For the file where it works and he can successfully set a label
  • For the file where it fails with class not found error

Could you share more details about environments you're running both snippets? Do they both have ionCube loader enabled?

Regards,
Pawel

Honestly I don't know how and where to get those files.. can you help me with this?

about the snippets, they are the exact same, both in dev and prod:

use App\Elastic\Apm\ElasticApm;

Route::get('/test', function () {
  $transaction = ElasticApm::beginCurrentTransaction(
    'HomeController@index',
    'request'
  );
  try {
    return view('welcome');
  } finally {
    $transaction->end();
  }
});

With this snippet I get different results from dev and prod when I click in route /test:

in dev I do have HTTP data (notice the GET /test)
Screen Shot 2023-03-30 at 22.17.29

but in prod, don't
Screen Shot 2023-03-30 at 22.18.08

If you noticed, I'm getting the ElasticApm class from App\Elastic\Apm, not from Elastic\Apm as documentation says.. thats because I've copied the classes and changed namespace to force my app in prod to find the files..
At first I thought that was the reason for incomplete data, but I did the same in dev and worked nicely..
The platform I'm using in prod is Plesk and yes, I've checked all the configs I could use to make it work (php.ini, environment variables), but did not make it collect HTTP data

I'm not a fan of long replies, but this is the only place I found some help, thanks @Pawel_Filipczak

Hey @Thiago_Medeiros

I don't have much experience with Plesk. I think you should get any agent related logs from container output.

Anyway, please take a look into phpinfo ouput. It states that you have open_basedir option enabled which points to /var/www/vhosts/udv.org.br/ and you have agent deployed into /opt/apm-agent-php.

I posted a link to official php documentation about open_basedir. If this feature is enabled PHP is unable to access files outside /var/www/vhosts/udv.org.br/ filesystem node. It can only go deeper.
That is why agent started to operate if you copied files into you application path, beacuse it is inside a fs node /var/www/vhosts/udv.org.br/ and because of auto-loading you got additional namespace node App\

To solve the issue you should modify open_basedir ini entry and add :/opt/apm-agent-php/ at the end.

Regarding differences between dev and prod. In my opinion there are differences in deployment. Try to fetch phpinfo from both and compare it (take a look at open_basedir).

Best regards,
Pawel

1 Like

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