pecl install opentelemetry
composer require open-telemetry/sdk open-telemetry/exporter-otlp php-http/guzzle7-adapter open-telemetry/opentelemetry-auto-slim
export OTEL_PHP_AUTOLOAD_ENABLED=true
export OTEL_SERVICE_NAME=hello-php
export OTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-us.pydantic.dev
export OTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
<?php
require __DIR__ . '/vendor/autoload.php';
\OpenTelemetry\API\Globals::tracerProvider()
->getTracer('hello-php')
->spanBuilder('Hello World')
->startSpan()
->end();
PHP auto-instrumentation hooks through the opentelemetry extension, so pecl install it and enable it in your
php.ini; opentelemetry-auto-slim is what turns Slim routes into spans. Swap it for the package matching your framework — without
one you still get your own spans, just not the framework's. The OTLP exporter also needs a PSR-18 HTTP client, which is what php-http/guzzle7-adapter provides. There is
no Logfire PHP SDK to adopt: this is the standard OpenTelemetry SDK exporting over OTLP. Full details are in the PHP setup guide.