Skip to content

PHP ​

Automatic traces for Laravel, Symfony, Slim, PDO, Guzzle and more, without code changes. The examples use Laravel; other frameworks swap in their own auto-instrumentation package.

Prerequisites

An OpenTelemetry Stream and an ingest key for that Stream. See OpenTelemetry → Prerequisites.

1. Install the extension ​

The OpenTelemetry PHP extension hooks into the framework. It needs PHP 8.0 or newer:

bash
pecl install opentelemetry

Using the official Docker images? Use install-php-extensions opentelemetry instead.

Then enable it in php.ini:

ini
[opentelemetry]
extension=opentelemetry.so

Check it loaded:

bash
php -m | grep opentelemetry

2. Install the packages ​

bash
composer require \
    open-telemetry/sdk \
    open-telemetry/exporter-otlp \
    open-telemetry/opentelemetry-auto-laravel \
    php-http/guzzle7-adapter

Not on Laravel? Find the framework's package on Packagist, such as open-telemetry/opentelemetry-auto-symfony or open-telemetry/opentelemetry-auto-slim.

3. Configure ​

Add to php.ini (or the PHP-FPM pool's environment):

ini
OTEL_PHP_AUTOLOAD_ENABLED="true"
OTEL_SERVICE_NAME="checkout-api"
OTEL_TRACES_EXPORTER="otlp"
OTEL_METRICS_EXPORTER="none"
OTEL_LOGS_EXPORTER="none"
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
OTEL_EXPORTER_OTLP_ENDPOINT="https://ws.latency.app/v1/ingest"
OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer%20lit_XXXXXXXXXXX"
OTEL_PROPAGATORS="baggage,tracecontext"

Not in Laravel's .env

OpenTelemetry starts before Laravel reads .env, so it never sees values set there. Use php.ini, the PHP-FPM pool config, or real environment variables.

4. Check it's working ​

Restart PHP-FPM (or the server), make a few requests, then open Telemetry in the Console, pick the Stream and choose Traces.

Custom spans ​

php
use OpenTelemetry\API\Globals;

$tracer = Globals::tracerProvider()->getTracer('checkout');

$span = $tracer->spanBuilder('charge-card')->startSpan();
$scope = $span->activate();

try {
    $span->setAttribute('order.id', $order->id);
    $this->chargeCard($order);
} finally {
    $scope->detach();
    $span->end();
}

Logs ​

To send Monolog logs as well, use OpenTelemetry's Monolog handler and set OTEL_LOGS_EXPORTER="otlp". They go to the same Stream with the same key.

Or send simple JSON logs to an Events Stream over the HTTP API.

© 2026 Latency Labs LLC