# ElasticApm class not found after configuration (Laravel)

**URL:** <https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759>\
**Category:** APM\
**Tags:** php, infrastructure-observability\
**Created:** [March 28, 2023, 11:39pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759 "2023-03-28T23:39:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Medeiros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago_medeiros/32/119081_2.png) [@Thiago\_Medeiros](https://discuss.elastic.co/u/Thiago_Medeiros)\
**Post date:** [March 28, 2023, 11:39pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/1 "2023-03-28T23:39:49Z")

</div>

I did what [Elastic PHP agent](https://www.elastic.co/guide/en/apm/agent/php/current/setup.html) tutorial says and have:

- elastic\_apm plugin shown in php info ✅
- can use ElasticApm class ❌

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](https://us1.discourse-cdn.com/elastic/original/3X/a/d/adcd2be5ba6864056a5d04bdac71983a12be73da.png)  
 ![Screen Shot 2023-03-28 at 20.39.05](https://us1.discourse-cdn.com/elastic/original/3X/e/9/e930b3523737834fe0e06bcf80541e63e87df51f.png)

---

<div class="post-metadata">

**Author:** ![Pawel\_Filipczak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_filipczak/32/119132_2.png) [@Pawel\_Filipczak](https://discuss.elastic.co/u/Pawel_Filipczak)\
**Post date:** [March 29, 2023, 12:17pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/2 "2023-03-29T12:17:22Z")

</div>

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](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](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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Thiago\_Medeiros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago_medeiros/32/119081_2.png) [@Thiago\_Medeiros](https://discuss.elastic.co/u/Thiago_Medeiros)\
**Post date:** [March 29, 2023, 12:39pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/3 "2023-03-29T12:39:27Z")

</div>

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](https://www.php.net/manual/en/ini.core.php#ini.open-basedir)  
**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](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:  
**Enabled**

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

```auto
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

```

 ![php-info](https://us1.discourse-cdn.com/elastic/original/3X/5/7/5700def0dbe53c0bd4846924c6e54f4cfe011097.jpeg)

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](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9c08146f489040503f6a7a1c10397ec83c61744c.png)

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](https://us1.discourse-cdn.com/elastic/original/3X/0/b/0b1aeb00178206b81f2136797542a0086e91a29b.png)

The code used was the same for both:

![Screen Shot 2023-03-29 at 09.48.39](https://us1.discourse-cdn.com/elastic/original/3X/1/7/178c405321171a429ae9878868e29d6edc0350b1.png)

---

<div class="post-metadata">

**Author:** ![Pawel\_Filipczak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_filipczak/32/119132_2.png) [@Pawel\_Filipczak](https://discuss.elastic.co/u/Pawel_Filipczak)\
**Post date:** [March 29, 2023, 1:48pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/4 "2023-03-29T13:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thiago\_Medeiros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago_medeiros/32/119081_2.png) [@Thiago\_Medeiros](https://discuss.elastic.co/u/Thiago_Medeiros)\
**Post date:** [March 30, 2023, 7:29am UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/5 "2023-03-30T07:29:17Z")

</div>

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](https://us1.discourse-cdn.com/elastic/original/3X/a/7/a759896cdf8d987fd795293e2355200764d9efca.png)

![Screen Shot 2023-03-30 at 04.25.33](https://us1.discourse-cdn.com/elastic/original/3X/7/8/7886b2bd1875bc323c657df5315d94cc6a6a0f5d.png)

about the log file, it does not exits.

But, importing still not works:  
 ![Screen Shot 2023-03-30 at 04.28.31](https://us1.discourse-cdn.com/elastic/original/3X/d/2/d287cbe102d8b2f4c5a9db7ec0ca6aa372101e47.png)

Plus info  
I can add a label to the transaction

 ![Screen Shot 2023-03-30 at 04.32.37](https://us1.discourse-cdn.com/elastic/original/3X/b/3/b331523013b13f370987aec0533a66dd9ed650eb.png)

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

Any Idea?

---

<div class="post-metadata">

**Author:** ![Pawel\_Filipczak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_filipczak/32/119132_2.png) [@Pawel\_Filipczak](https://discuss.elastic.co/u/Pawel_Filipczak)\
**Post date:** [March 30, 2023, 9:44am UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/6 "2023-03-30T09:44:15Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Thiago\_Medeiros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago_medeiros/32/119081_2.png) [@Thiago\_Medeiros](https://discuss.elastic.co/u/Thiago_Medeiros)\
**Post date:** [March 31, 2023, 1:43am UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/7 "2023-03-31T01:43:17Z")

</div>

> [@Pawel\_Filipczak](#):
>
> Did you tried to get logs from syslog or stderr?

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:

```auto
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`:

 ![Screen Shot 2023-03-30 at 22.17.13](https://us1.discourse-cdn.com/elastic/original/3X/7/8/78cdcfe74ed2f4ddd991c6b8c79244932c1a635d.png)

in dev I do have HTTP data (notice the `GET /test`)  
 ![Screen Shot 2023-03-30 at 22.17.29](https://us1.discourse-cdn.com/elastic/original/3X/f/1/f14c297c44b5c921587ddc85111ef4307932f970.png)

 ![Screen Shot 2023-03-30 at 22.17.57](https://us1.discourse-cdn.com/elastic/original/3X/e/7/e79c9ffdc35a36c3844bdf386f4ed81f2a2fefed.png)

but in prod, don't  
 ![Screen Shot 2023-03-30 at 22.18.08](https://us1.discourse-cdn.com/elastic/original/3X/1/2/125048337726ddf61df8efc9957aa0dfd8d0e478.png)

 ![Screen Shot 2023-03-30 at 22.18.19](https://us1.discourse-cdn.com/elastic/original/3X/3/e/3eabe66682269c441e32cd3106228ad7dbd8f1d5.png)

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](https://www.plesk.com/) 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

---

<div class="post-metadata">

**Author:** ![Pawel\_Filipczak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_filipczak/32/119132_2.png) [@Pawel\_Filipczak](https://discuss.elastic.co/u/Pawel_Filipczak)\
**Post date:** [March 31, 2023, 12:18pm UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/8 "2023-03-31T12:18:53Z")

</div>

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`.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/f/df823066387623217be1f4c527c70744e7b5969f.png)

I posted a link to official php documentation about [open\_basedir](https://www.php.net/manual/en/ini.core.php#ini.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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 21, 2023, 8:19am UTC](https://discuss.elastic.co/t/elasticapm-class-not-found-after-configuration-laravel/328759/9 "2023-04-21T08:19:21Z")

</div>

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