inspector-apm / inspector-laravel

Code Execution Monitoring foe Laravel applications.
https://inspector.dev
MIT License
204 stars 14 forks source link

Ability to change `curlPath` for AsyncTransport #48

Closed tomykho closed 3 days ago

tomykho commented 4 days ago

Is your feature request related to a problem? Please describe. Official Documentaion for Laravel Vapor mentioned Inspector requires two natives PHP functions (proc_open, proc_close) to send monitoring data to the remote API. But Laravel Vapor PHP runtime layers didn't disable_functions proc_open and proc_close, Instead of curl binary are actually built and installed at different path.

Describe the solution you'd like Add curlPath and certPath for config/inspector.php

Additional context Custom Transport for Inspector to work with Laravel Vapor without Docker and Queue.

<?php

namespace App\Transports;

use Inspector\Transports\AsyncTransport;

class VaporAsyncTransport extends AsyncTransport
{
    protected $curlPath = '/opt/bin/curl';

    protected function buildCurlCommand($data): string
    {
        $curl = parent::buildCurlCommand($data);
        $curl .= ' --cacert /opt/lib/curl/cert.pem';
        return $curl;
    }
}
ilvalerione commented 3 days ago

Hi @tomykho, the package already has an option for this configuration:

https://github.com/inspector-apm/inspector-laravel/blob/master/config/inspector.php#L73

To access this configuration property you should publish the inspector config file:

php artisan vendor:publish --provider="Inspector\Laravel\InspectorServiceProvider"

After publishing the config/inspector.php file you can customize the curlPath:

'options' => [
    'curlPath' => '/opt/bin/curl --cacert /opt/lib/curl/cert.pem'
],

Furthermore you must be sure to have the underlying php package at the latest version 3.8.3 You should update composer dependencies (composer update) before using this option.

ilvalerione commented 3 days ago

@tomykho Are proc_close and proc_open functions enabled by default in the default Vapor runtime?

When I built this package they weren't. If you tried using the default Vapor configuration without any other customizations I could update the documentation to reflect this opportunity for other users.

Are any other configurations needed to the Vapor runtime layers?

tomykho commented 3 days ago

@tomykho Are proc_close and proc_open functions enabled by default in the default Vapor runtime?

When I built this package they weren't. If you tried using the default Vapor configuration without any other customizations I could update the documentation to reflect this opportunity for other users.

Are any other configurations needed to the Vapor runtime layers?

I am using this repo to build custom Vapor runtime layers (with updated packages without extra customization), because I thought I could use that instead of using Docker. I will try it on default Vapor runtime and give you updates here later.

tomykho commented 3 days ago

It is also working on the Vapor default runtime. Is it possible to remove this deprecation warning?

PHP Deprecated:  Creation of dynamic property Inspector\Transports\AsyncTransport::$curlPath is deprecated in /vendor/inspector-apm/inspector-php/src/Transports/AbstractApiTransport.php on line 52
ilvalerione commented 3 days ago

I released a patch: https://github.com/inspector-apm/inspector-php/releases/tag/3.8.4

You can get it updating composer dependencies (composer update).