PHP OpenTelemetry instrumentation
Instrument a PHP application with OpenTelemetry using the opentelemetry PHP extension for zero-code auto-instrumentation. Once the extension and the SDK are installed, incoming requests, database queries, and outbound HTTP calls are traced without changes to your application code.
Prerequisites
Section titled “Prerequisites”- PHP 8.1 or newer (zero-code instrumentation requires the extension, which needs PHP 8.0+; the Laravel auto-instrumentation needs 8.1+).
- Composer and PECL for installing the extension.
- Your Osuite ingest token and region.
Install and configure
Section titled “Install and configure”-
Install and enable the
opentelemetryextension. It provides the hooks the auto-instrumentation libraries attach to.Terminal window pecl install opentelemetryEnable it by adding this line to your
php.ini, then confirm it loaded withphp -m | grep opentelemetry:extension=opentelemetry.so -
Install the SDK, the OTLP exporter, a PSR-18 HTTP client, and the Laravel auto-instrumentation with Composer.
Terminal window composer require \open-telemetry/sdk \open-telemetry/exporter-otlp \open-telemetry/opentelemetry-auto-laravel \php-http/guzzle7-adapteropen-telemetry/exporter-otlpsends data over OTLP, andphp-http/guzzle7-adaptersatisfies the PSR-18 client the HTTP exporter needs. For a non-Laravel app, swapopentelemetry-auto-laravelfor the auto-instrumentation matching your framework — for exampleopen-telemetry/opentelemetry-auto-slimfor Slim, oropen-telemetry/opentelemetry-auto-symfonyfor Symfony. -
Set the exporter environment variables. Provide them wherever your app runs — the PHP-FPM pool, the web server environment, or a
.envloaded at boot.Terminal window export OTEL_PHP_AUTOLOAD_ENABLED=trueexport OTEL_SERVICE_NAME=<service-name>export OTEL_RESOURCE_ATTRIBUTES=service.environment=productionexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufexport OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.osuite.io:443export OTEL_EXPORTER_OTLP_HEADERS=x-osuite-ingest-token=<your-ingest-token>export OTEL_TRACES_EXPORTER=otlpexport OTEL_LOGS_EXPORTER=otlpexport OTEL_METRICS_EXPORTER=otlpOTEL_PHP_AUTOLOAD_ENABLED=trueis what activates zero-code instrumentation at startup. Thehttps://scheme on the endpoint is required — the SDK exporter takes a URL and Osuite only accepts OTLP over TLS.
Run Laravel with instrumentation
Section titled “Run Laravel with instrumentation”With the extension enabled and the environment variables set, open-telemetry/opentelemetry-auto-laravel hooks into the framework’s request lifecycle automatically. No code changes are needed: run your app as usual and requests, Eloquent queries, and queue jobs are traced.
php artisan serveVerify in Osuite
Section titled “Verify in Osuite”What you should see
Send a request to any route. The service appears in APM within a minute with a trace per request, showing the controller, Eloquent queries, and outbound HTTP calls as nested spans. Application logs appear in the Logs explorer tagged with the matching trace ID.
Troubleshooting
Section titled “Troubleshooting”If no traces appear, confirm the extension is loaded (php -m | grep opentelemetry) and that OTEL_PHP_AUTOLOAD_ENABLED=true is set in the same environment the app runs in — PHP-FPM does not inherit your shell’s variables unless you pass them through the pool config.
No data in Osuite after a few minutes? Work through these checks.
- Endpoint — confirm the exporter targets exactly
ingest.<region>.osuite.io:443for your region, over TLS. - Token — confirm the ingest header carries a valid
<your-ingest-token>and has not been rotated. - Pipeline — confirm the signal you expect (traces, logs, or metrics) is wired into an active pipeline with the
otlp/osuiteexporter attached. - Export errors — check the application or Collector logs for OTLP export failures (auth, DNS, TLS, connection refused).
- Network — confirm the host has outbound access to the ingest endpoint on port
443. - Timing — allow up to a minute for the first data to appear before assuming a failure.
Still stuck? Ask the Investigation Agent or contact support.