PHP code example of lucagiardina / lara-zipkin

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

    

lucagiardina / lara-zipkin example snippets


/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @param  string|null  $guard
 * @return mixed
 */
public function handle($request, Closure $next)
{
    app('ZipkinClient')->track('Authenticate', 'handle');

    ...
    code
    ...

    app('ZipkinClient')->finishTrack('Authenticate', 'handle');

    return $next($request);
}
 

 class Foo extends Bar
{
    public function foo()
    {
        app('ZipkinClient')->track('Foo', __FUNCTION__);

        ..
        code
        ..

        app('ZipkinClient')->trackCall('Foo', 'third_party->call');
        $fooService->barMethod();
        app('ZipkinClient')->trackEndCall('Foo', 'third_party->call');

        app('ZipkinClient')->finishTrack('Foo');
    }
}
 

$client = new Client();
$res = $client->request('GET', 'http://foo.com/bar', [
    'headers' => [
        'X-B3-TraceId' => (string) app('ZipkinClient')->getTraceId(),
        'X-B3-SpanId' => (string) app('ZipkinClient')->getTraceSpanId(),
        'X-B3-ParentId' => (string) app('ZipkinClient')->getTraceSpanId(),
        'X-B3-Sampled' => app('ZipkinClient')->isSampled()
    ]
]);
 

public function getNextSpan( $name = 'no-name', $kind = 'SERVER', $headers = null ) : Span

app('ZipkinClient')->trackCall($spanName, $callName = null, $kind = 'CONSUMER');

public function tagBy($name, $value)
public function getTracer() : Tracer