OpenTelemetry PHP exporter
The OpenTelemetry PHP SDK supports vendor-specific exporters. The spans that are created with the SDK can be sent to an Instana agent. For more information on exporters and the OpenTelemetry PHP SDK, refer to their documentation.
Installing the exporter
To install the exporter through Composer, run the following command:
composer require instana/opentelemetry-php-exporter
Configuring the exporter
You can configure the exporter with the factory or by manually configuring SpanExporter
.
The factory method uses the environment variables INSTANA_AGENT_HOST
and INSTANA_AGENT_PORT
to form the endpoint of the Instana agent. If these variables are unset, then the following fallbacks are used:
// Default configuration values
// INSTANA_AGENT_HOST=127.0.0.1
// INSTANA_AGENT_PORT=42699
$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(
(new \Instana\SpanExporterFactory)->create()
)
);
To manually configure SpanExporter
, run the following command:
$transport = new InstanaTransport('127.0.0.1:42699');
$exporter = new SpanExporter(
$transport,
new SpanConverter($transport->getUuid(), $transport->getPid())
);
$tracerProvider = new TracerProvider(
new SimpleSpanProcessor($exporter)
);
Example of exporter usage
After the tracer provider is set up, you can initialize an OpenTelemetry PHP tracer and use the SDK as normal.
$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();