PHP code example of vantt / opentracing-jaeger-php
1. Go to this page and download the library: Download vantt/opentracing-jaeger-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/ */
use OpenTracing\Formats;
use OpenTracing\GlobalTracer;
...
// extract the span context
$spanContext = GlobalTracer::get()->extract(
Formats\TEXT_MAP,
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();