1. Go to this page and download the library: Download vantt/opentracing-php 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/ */
vantt / opentracing-php example snippets
use OpenTracing\GlobalTracer;
$tracer = GlobalTracer::set(new MyTracerImplementation());
use OpenTracing\Formats;
use OpenTracing\GlobalTracer;
...
// extract the span context
$spanContext = GlobalTracer::get()->extract(
Formats\HTTP_HEADERS,
getallheaders()
);
function doSomething() {
...
// start a new span called 'my_span' and make it a child of the $spanContext
$span = GlobalTracer::get()->buildSpan('my_operation_span_name')
->start();
...
// add some logs to the span
$span->log([
'event' => 'soft error',
'type' => 'cache timeout',
'waiter.millis' => 1500,
]);
// finish the the span
$span->finish();
}
$parent = GlobalTracer::get()->buildSpan('parent')->startActive();
...
/*
* Since the parent span has been created by using startActiveSpan we don't need
* to pass a reference for this child span
*/
$child = GlobalTracer::get()->buildSpan('my_second_span')->startActive();
...
$child->close();
...
$parent->close();
use OpenTracing\GlobalTracer;
use OpenTracing\Formats;
$tracer = GlobalTracer::get();
$spanContext = $tracer->extract(Formats\HTTP_HEADERS, getallheaders());
$tracer->buildSpan('my_span')->asChildOf($spanContext)->startActive();
use OpenTracing\GlobalTracer;
$application->run();
register_shutdown_function(function() {
/* Flush the tracer to the backend */
$tracer = GlobalTracer::get();
$tracer->flush();
});