PHP code example of dipenduroy / lumenzipkin

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

    

dipenduroy / lumenzipkin example snippets


	//Set your application variables below
	$baseUri='http://local.app/';
	$method='POST';
	$requestUrl='example/url';
	$queryString='?filter=category';
	$formParams=[];
	
	//Get Zipkin Trace Object
	$ZipkinTrace=app('Trace\ZipkinTrace');
	
	/* Creates the span for getting the guzzle client call */
    $childSpan = $ZipkinTrace->createChildClientSpan($baseUri);
    
    //Tags can be configured as per your ;
    $headers['accept'] = "application/json";
    $headers=array_merge($headers,$ZipkinTrace->getHeaders());
    $params=[
            'form_params' => $formParams,
            'headers'     => $headers,
            'query' => $queryString,
        ];
    try {
        $response = $client->request($method, $requestUrl, $params);
    } catch (\GuzzleHttp\Exception\TransferException $e) {
        $response = $e->getResponse();
        if ($e->hasResponse()) {
            $responseString = $e->getResponse()->getBody(true);
        } else {
            $childSpan->tag(\Zipkin\Tags\HTTP_STATUS_CODE, 503);
            $childSpan->tag(\Zipkin\Tags\ERROR, 'Guzzle Transfer Exception');
            $childSpan->annotate('request_failed', \Zipkin\Timestamp\now());
        }
    }
    $childSpan->tag(\Zipkin\Tags\HTTP_STATUS_CODE, $response->getStatusCode());
    $childSpan->annotate('request_finished', \Zipkin\Timestamp\now());