Skip to content

PHP

Terminal window
composer require open-telemetry/sdk open-telemetry/exporter-otlp open-telemetry/opentelemetry-logger-monolog guzzlehttp/guzzle

Set these where PHP runs, including your PHP-FPM pool if you use one. Replace YOUR_INGEST_KEY with your key and checkout with your service name. The last line starts the SDK when your app loads vendor/autoload.php.

Terminal window
export OTEL_SERVICE_NAME=checkout
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.com
export OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEY
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_PHP_AUTOLOAD_ENABLED=true

Add the OpenTelemetry handler to your Monolog logger. Laravel and Symfony both log through Monolog.

$logger = new Logger('checkout', [new Handler(Globals::loggerProvider(), 'info')]);
$logger->info('order placed', ['orderId' => 42]);

Wrap work in a span:

$tracer = Globals::tracerProvider()->getTracer('checkout');
$span = $tracer->spanBuilder('place order')->startSpan();
$scope = $span->activate();
// Logs and spans created here belong to this span.
$scope->detach();
$span->end();

For automatic traces of every request, install the opentelemetry PHP extension (pecl install opentelemetry) and your framework’s package, such as open-telemetry/opentelemetry-auto-laravel or open-telemetry/opentelemetry-auto-symfony.

Globals::meterProvider()->getMeter('checkout')->createCounter('orders.placed')->add(1);

Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.

The code on this page comes from a runnable example that is checked against our ingest rules every month.

Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.