PHP code example of basis-company / opentelemetry
1. Go to this page and download the library: Download basis-company/opentelemetry 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/ */
basis-company / opentelemetry example snippets
use OpenTelemetry\Tracing\Builder;
use OpenTelemetry\Tracing\SpanContext;
$spanContext = SpanContext::generate(); // or extract from headers
$tracer = Builder::create()->setSpanContext($spanContext)->getTracer();
// start a span, register some events
$span = $tracer->createSpan('session.generate');
// set attributes as array
$span->setAttributes([ 'remote_ip' => '5.23.99.245' ]);
// set attribute one by one
$span->setAttribute('country', 'Russia');
$span->addEvent('found_login', [
'id' => 67235,
'username' => 'nekufa',
]);
$span->addEvent('generated_session', [
'id' => md5(microtime(true))
]);
$span->end(); // pass status as an optional argument