PHP code example of cryptoman3 / elastic-apm-php

1. Go to this page and download the library: Download cryptoman3/elastic-apm-php 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/ */

    

cryptoman3 / elastic-apm-php example snippets


// COMMENT THIS SECTION
$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

// USE THIS SECTION FOR LARAVEL <= 7
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\Handler(new App\Exceptions\Handler($app), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});

// USE THIS SECTION FOR LARAVEL >= 8
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\HandlerThrowable(new App\Exceptions\Handler($app), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});

// COMMENT THIS SECTION
$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

// USE THIS SECTION FOR LUMEN <= 7
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\Handler(new App\Exceptions\Handler(), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});

// USE THIS SECTION FOR LUMEN >= 8
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function ($app) {
    return new Anik\ElasticApm\Exceptions\HandlerThrowable(new App\Exceptions\Handler(), [
        // NotFoundHttpException::class, // (1)
        // ConnectException::class, // (2)
    ]);
});



class Kernel extends HttpKernel {
    protected $middleware = [
        // ...
        \Anik\ElasticApm\Middleware\RecordForegroundTransaction::class,
        // ..
    ];
}

$app->middleware([
    // ...
    \Anik\ElasticApm\Middleware\RecordForegroundTransaction::class,
    // ...
]);

$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(new \Anik\ElasticApm\Middleware\RecordHttpTransaction(), 'whatever-you-wish');

$client = new \GuzzleHttp\Client([
    'base_uri' => 'http://httpbin.org',
    'timeout'  => 10.0,
    'handler'  => $stack,
]);
$client->request('GET', '/');
shell script
composer