PHP code example of scoutapp / scout-apm-laravel

1. Go to this page and download the library: Download scoutapp/scout-apm-laravel 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/ */

    

scoutapp / scout-apm-laravel example snippets


$config[\Scoutapm\Config\ConfigKey::LOG_LEVEL] = \Psr\Log\LogLevel::ERROR;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // ...
    })
    ->withExceptions(function (Exceptions $exceptions) {
        // Add the following call to enable uncaught exceptions in Scout APM error reporting:
        $exceptions->reportable(function (Throwable $e) {
            app()->make(\Scoutapm\ScoutApmAgent::class)->recordThrowable($e);
        });
    })->create();

$request = new ServiceRequest();
$request->setApiVersion($version);

// At top, with other imports
use Scoutapm\Events\Span\Span;
use Scoutapm\Laravel\Facades\ScoutApm;

// Replacing the above code
$request = ScoutApm::instrument(
    'Custom',
    'Building Service Request',
    static function (Span $span) use ($version) {
        $request = new ServiceRequest();
        $request->setApiVersion($version);
        return $request;
    }
);
bash
php artisan vendor:publish --provider="Scoutapm\Laravel\Providers\ScoutApmServiceProvider"

SCOUT_LOG_LEVEL=error