PHP
1. Install
Section titled “1. Install”composer require open-telemetry/sdk open-telemetry/exporter-otlp open-telemetry/opentelemetry-logger-monolog guzzlehttp/guzzle2. Configure
Section titled “2. Configure”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.
export OTEL_SERVICE_NAME=checkoutexport OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=productionexport OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.comexport OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEYexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufexport OTEL_PHP_AUTOLOAD_ENABLED=true3. Send a log
Section titled “3. Send a log”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]);4. Trace a request
Section titled “4. Trace a request”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.
5. Record a metric (optional)
Section titled “5. Record a metric (optional)”Globals::meterProvider()->getMeter('checkout')->createCounter('orders.placed')->add(1);See your data
Section titled “See your data”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.