PHP code example of instana / instana-php-opentracing

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

    

instana / instana-php-opentracing example snippets


use Instana\OpenTracing\InstanaTracer;

\OpenTracing\GlobalTracer::set(InstanaTracer::restSdk());

use Instana\OpenTracing\InstanaTracer;

\OpenTracing\GlobalTracer::set(InstanaTracer::getDefault());

$parentScope = \OpenTracing\GlobalTracer::get()->startActiveSpan('one');
$parentSpan = $parentScope->getSpan();
$parentSpan->setTag(\Instana\OpenTracing\InstanaTags\SERVICE, "example-service");
$parentSpan->setTag(\OpenTracing\Tags\COMPONENT, 'PHP simple example app');
$parentSpan->setTag(\OpenTracing\Tags\SPAN_KIND, \OpenTracing\Tags\SPAN_KIND_RPC_SERVER);
$parentSpan->setTag(\OpenTracing\Tags\PEER_HOSTNAME, 'localhost');
$parentSpan->setTag(\OpenTracing\Tags\HTTP_URL, '/php/simple/one');
$parentSpan->setTag(\Instana\OpenTracing\InstanaTags\HTTP_PATH_TPL, '/php/simple/{id}');
$parentSpan->setTag(\OpenTracing\Tags\HTTP_METHOD, 'GET');
$parentSpan->setTag(\OpenTracing\Tags\HTTP_STATUS_CODE, 200);
$parentSpan->log(['event' => 'bootstrap', 'type' => 'kernel.load', 'waiter.millis' => 1500]);

$childScope = \OpenTracing\GlobalTracer::get()->startActiveSpan('two');
$childSpan = $childScope->getSpan();
$childSpan->setTag(\OpenTracing\Tags\SPAN_KIND, \OpenTracing\Tags\SPAN_KIND_RPC_CLIENT);
$childSpan->setTag(\OpenTracing\Tags\PEER_HOSTNAME, 'localhost');
$childSpan->setTag(\OpenTracing\Tags\HTTP_URL, '/php/simple/two');
$childSpan->setTag(\OpenTracing\Tags\HTTP_METHOD, 'POST');
$childSpan->setTag(\OpenTracing\Tags\HTTP_STATUS_CODE, 204);

$childScope->close();
$parentScope->close();

\OpenTracing\GlobalTracer::get()->flush();

use Instana\OpenTracing\InstanaTracer;

InstanaTracer::phpSensor('tcp://172.17.0.1:16816');

use Instana\OpenTracing\InstanaTracer;

InstanaTracer::restSdk('http://172.17.0.1:42699/com.instana.plugin.generic.trace');
bash
composer req "instana/instana-php-opentracing:^2.0"
json
{
    "nstana/instana-php-opentracing": "^2.0"
    }
}