PHP code example of open-telemetry / opentelemetry-exporter-instana

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

    

open-telemetry / opentelemetry-exporter-instana example snippets


use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

$tracerProvider = new TracerProvider(
    new SimpleSpanProcessor(
        Registry::spanExporterFactory("instana")->create()
    )
);
$tracer = $tracerProvider->getTracer('io.instana.opentelemetry.php');

$span = $tracer->spanBuilder('root')->startSpan();
$span->setAttribute('remote_ip', '1.2.3.4')
    ->setAttribute('country', 'CAN');
$span->addEvent('generated_session', [
    'id' => md5((string) microtime(true)),
]);
$span->end();

$tracerProvider->shutdown();
bash
curl -s https://getcomposer.org/installer | php