PHP code example of taisph / laravel-opentracing

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

    

taisph / laravel-opentracing example snippets




// Create the application.
$app = new \Illuminate\Foundation\Application(realpath(__DIR__ . '/../'));

// Bind important interfaces.
// ...

// Register important providers.
$app->register(\LaravelOpenTracing\TracingServiceProvider::class);

// Enable tracing span context in log messages.
$app->configureMonologUsing(function (\Monolog\Logger $logger) {
    $logger->pushProcessor(new \LaravelOpenTracing\Log\Processor\LocalTracerProcessor());
});

// Return the application.
return $app;

$items = app(\LaravelOpenTracing\TracingService::class)->trace(
    'todo.get_list_items',
    function () {
        return \App\Models\TodoListItem::get();
    }
);

function a() {
    // We don't care about tracing this specifically.
    doSomething();

    app(\LaravelOpenTracing\TracingService::class)->trace(
        'app.do_something_else',
        function () {
            doSomethingElse();
        }
    );
}

app(\LaravelOpenTracing\TracingService::class)->trace(
    'app.do_stuff',
    function () {
        a();
    }
);

$title = 'Make more coffee';

$item = app(\LaravelOpenTracing\TracingService::class)->trace(
    'todo.store_item',
    function () use ($title) {
        return \App\Models\TodoListItem::create(['title' => $title]);
    },
    ['tags' => ['title' => $title]]
);



app(\Illuminate\Bus\Dispatcher::class)->pipeThrough([
    \LaravelOpenTracing\TracingJobPipe::class,
]);



class Kernel extends HttpKernel
{
    protected $middleware = [
        \LaravelOpenTracing\Http\Middleware\Tracing::class,
    ];
}



new \GuzzleHttp\Client(
    [
        'handler' => new \LaravelOpenTracing\TracingHandlerStack(),
        'headers' => [
            'cache-control' => 'no-cache',
            'content-type' => 'application/json',
        ],
        'base_uri' => 'http://localhost/api/myservice',
        'http_errors' => false
    ]
);
bash
php artisan vendor:publish --provider="LaravelOpenTracing\TracingServiceProvider"