PHP code example of wieni / saloon-aws-xray

1. Go to this page and download the library: Download wieni/saloon-aws-xray library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wieni / saloon-aws-xray example snippets


// app/Providers/SaloonXrayServiceProvider.php
 declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Napp\Xray\Submission\DaemonSegmentSubmitter;
use Napp\Xray\Xray;
use Saloon\Config as SaloonConfig;
use Saloon\HttpSender\HttpSender;
use Wieni\SaloonAwsXray\XrayHttpSender;

final class SaloonXrayServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        // Configure the XrayHttpSender
        $this->app->bind(
            XrayHttpSender::class,
            function (): XrayHttpSender {
                $submitterClass = config('xray.submitter', DaemonSegmentSubmitter::class);
                $senderClass = config('saloon.default_sender', HttpSender::class);

                return new XrayHttpSender(
                    new $senderClass(),
                    $this->app[Xray::class]->tracer(),
                    new $submitterClass(),
                );
            },
        );

        // Configure Saloon to use the XrayHttpSender
        SaloonConfig::setSenderResolver(fn() => $this->app[XrayHttpSender::class]);
    }
}