Send OpenTelemetry from Laravel to your Mac
PHP instruments Laravel with an extension and a Composer package. No code changes.
Before you start
Section titled “Before you start”- Loggerhead is open.
- You know the effective port. Open Collectors → Loggerhead receiver → Connection and copy the HTTP port. The first workspace uses 4318. See Ports and the effective port.
Step 1: install the extension
Section titled “Step 1: install the extension”Auto-instrumentation needs the opentelemetry PHP extension.
pecl install opentelemetryAdd extension=opentelemetry.so to your php.ini, then check it with php -m | grep opentelemetry.
Step 2: install the packages
Section titled “Step 2: install the packages”composer require \ open-telemetry/sdk \ open-telemetry/exporter-otlp \ open-telemetry/opentelemetry-auto-laravelStep 3: set the endpoint
Section titled “Step 3: set the endpoint”OTEL_PHP_AUTOLOAD_ENABLED=trueOTEL_SERVICE_NAME=my-laravel-appOTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufOTEL_PHP_AUTOLOAD_ENABLED is the switch. Without it the packages load and do nothing.
Start the app with php artisan serve and open one route.
What arrives
Section titled “What arrives”| Signal | State |
|---|---|
| Traces | Every request, with the route, the queries, and the queued jobs. |
| Metrics | Only what you record yourself. |
| Logs | Add OTEL_LOGS_EXPORTER=otlp and the Monolog handler of the Laravel package. |
Tag the environment
Section titled “Tag the environment”OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=stagingSee Workspaces and environments.
Then read it with your agent
Section titled “Then read it with your agent”- Open Traces in Loggerhead and click a request to open its waterfall.
- Connect your coding agent once, and it reads the same data. See Claude Code.