PHP code example of icovn / laravel-zipkin

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

    

icovn / laravel-zipkin example snippets


Mts88\LaravelZipkin\Providers\LaravelZipkinServiceProvider::class

'Zipkin'       => Mts88\LaravelZipkin\Facades\Zipkin,

php artisan vendor:publish

ZIPKIN_HOST=http://localhost
ZIPKIN_PORT=9411

'api' => [
	'throttle:60,1',
	'bindings',
	// Others middleware
	\Mts88\LaravelZipkin\Middlewares\ZipkinRequestLogger::class,
],

class MyApiController extends ZipkinBaseController{
// My Api Methods
}

use Mts88\LaravelZipkin\Services\ZipkinService;

class MyAwesomeController extends Controller{
	public  function  __construct(ZipkinService  $zipkinService)
	{
		// Do something with $zipkinService
	}
}

use Mts88\LaravelZipkin\Controllers\ZipkinBaseController;

class MyAwesomeController  extends  ZipkinBaseController {
	// My Awesome Methods
}

use Mts88\LaravelZipkin\Services\ZipkinService;
use Mts88\LaravelZipkin\Controllers\ZipkinBaseController;

class MyAwesomeController extends ZipkinBaseController{

	public  function  __construct(ZipkinService  $zipkinService)
	{
		parent::__construct($zipkinService);
		// Do something with your override
	}
}

	// zipkinService instance
	$this->zipkinService;	

$this->zipkinService = new ZipkinService(); // or you can access in others way

// Create trace
$this->zipkinService->setTracer('my_trace_name', $request->ip());

$tags = [
	"my_value1" => "hello",
	"my_value2" => "world"
];

// Create RootSpan
$this->zipkinService->createRootSpan('root_span_of_request', $tags);

// Set Annotation
$this->zipkinService->setRootSpanAnnotation('my_annotation_1', \Zipkin\Timestamp\Timestamp\now());

// Dedicated Tags Methods
$this->zipkinService->setRootSpanMethod('GET') // Method of request
	->setRootSpanPath('/') // Path of request
	->setRootSpanStatusCode("200") // Response Code Server
	->setRootAuthUser(Auth::user()); // User that perform request
	
// Insert others tags
$this->setRootSpanTag('my_value3', "ciao")
	->setRootSpanTag('my_value4', "mondo");


// Close rootSpan and tracer
$this->zipkinService->closeSpan();

// Create tracer
$tracing = $this->zipkinService->createTracing('child_span_tracing', $request->ip());
$tracer = $tracing->getTracer(); 

// Create Span
$span = $tracer->nextSpan($this->zipkinService->getRootSpanContext());
$span->annotate("Start", \Zipkin\Timestamp\Timestamp\now());
$span->setName('Child span method');
$span->start(\Zipkin\Timestamp\Timestamp\now());

// Create Tag for Child Span
$span->tag("my_tag_1", 'Hello');
$span->tag("my_tag_2", 'World');
// Make annotation
$span->annotate("End", \Zipkin\Timestamp\Timestamp\now());

// Close Span
$span->finish(\Zipkin\Timestamp\Timestamp\now());
$tracer->flush();