PHP code example of takatost / php-zipkin

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

    

takatost / php-zipkin example snippets



$client   = new \GuzzleHttp\Client();
$logger   = new \Drefined\Zipkin\Transport\HTTPLogger($client);
$tracer   = new \Drefined\Zipkin\Tracer($logger, 1.0, true);
$endpoint = new \Drefined\Zipkin\Core\Endpoint('127.0.0.1', 8080, 'test-trace');
$trace    = new \Drefined\Zipkin\Core\Trace($tracer, $endpoint);

$trace->createNewSpan('test-server-trace');

$trace->record(
    [Annotation::generateServerRecv()],
    [BinaryAnnotation::generateString('server.request.uri', '/server')]
);

$trace->record(
    [Annotation::generateServerSend()],
    [BinaryAnnotation::generateString('server.response', 200)]
);

 // laravel-project/app/Http/Kernel.php

namespace App\Http;

use ...
use Drefined\Zipkin\Instrumentation\Laravel\Middleware\EnableZipkinTracing;

class Kernel extends HttpKernel
{
    ...
    protected $middleware = [
        ...
        EnableZipkinTracing::class,
    ];
    ...
}

 // laravel-project/config/app.php

use Drefined\Zipkin\Instrumentation\Laravel\Providers\ZipkinTracingServiceProvider;

return [
    ...
    'providers' => [
        ...
        ZipkinTracingServiceProvider::class,
    ],
    ...
];
bash
composer