1. Go to this page and download the library: Download mix/opentracing 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/ */
mix / opentracing example snippets
use OpenTracing\GlobalTracer;
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()->startSpan('my_span', ['child_of' => $spanContext]);
...
// 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()->startActiveSpan('parent');
...
/*
* 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()->startActiveSpan('my_second_span');
...
$child->close();
...
$parent->close();
use OpenTracing\GlobalTracer;
use OpenTracing\Formats;
$tracer = GlobalTracer::get();
$spanContext = $tracer->extract(Formats\HTTP_HEADERS, getallheaders());
$tracer->startSpan('my_span', [
'child_of' => $spanContext,
]);
use OpenTracing\GlobalTracer;
$application->run();
register_shutdown_function(function() {
/* Flush the tracer to the backend */
$tracer = GlobalTracer::get();
$tracer->flush();
});