Observability
A Laravel application on PAM has two observability layers:
- The runtime (always on): the PAM master exposes liveness, readiness, and Prometheus metrics on a private admin listener, without entering PHP.
- The application (with
pushinbr/pam-laravel): health and metrics routes inside Laravel, slow-query and N+1 detection, state-leak reports, and OpenTelemetry traces for requests, queries, jobs, cache, and HTTP calls.
The Admin Listener
Section titled “The Admin Listener”Start the cluster with --admin-address:
pam start pam.php --workers 8 --admin-address 127.0.0.1:3010| Endpoint | Returns 200 when |
|---|---|
/live |
The master process is alive |
/startup |
The first worker generation finished booting |
/ready |
The desired workers are ready and within their deadlines |
/metrics |
Always: Prometheus text format |
Use /ready for load-balancer and Kubernetes readiness, /live for liveness.
Runtime Metrics
Section titled “Runtime Metrics”A selection of what /metrics reports (real output, trimmed):
pam_cluster_ready 1pam_cluster_workers 1pam_http_requests_total 5pam_http_errors_total 0pam_http_active_requests 0pam_http_client_disconnect_cancellations_total 0pam_event_loop_lag_max_seconds 0.001023pam_process_resident_memory_bytes 94793728pam_php_memory_bytes 16777216pam_php_peak_memory_bytes 16777216pam_http_request_duration_seconds_bucket{le="0.01"} 3pam_http_response_cache_hits_total 0Stream them live in a terminal:
pam top http://127.0.0.1:3010Application Health and Metrics
Section titled “Application Health and Metrics”pushinbr/pam-laravel registers two routes:
curl http://127.0.0.1:3000/__pam/healthcurl http://127.0.0.1:3000/__pam/metrics/__pam/health returns 200 when the default database connection answers,
503 otherwise:
{ "ok": true, "runtime": "pam", "environment": "production", "database": true, "memory_bytes": 16777216, "peak_memory_bytes": 16777216, "observability": { "requests": 4, "errors": 0, "queries": 3 }}Protect /__pam/metrics with a bearer token:
PAM_LARAVEL_OBSERVABILITY_TOKEN=a-long-random-valuecurl -H "Authorization: Bearer $PAM_LARAVEL_OBSERVABILITY_TOKEN" http://127.0.0.1:3000/__pam/metricsChange the paths with PAM_LARAVEL_HEALTH_PATH and PAM_LARAVEL_METRICS_PATH,
or disable both with PAM_LARAVEL_HEALTH_ENABLED=false.
Application Metrics
Section titled “Application Metrics”/__pam/metrics reports, for the worker that answered:
- request and error counts, and per-route
count,errors,totalNs,maxNs(at most 256 routes); - query count and total time, plus the last 128 slow queries (≥ 100 ms);
stateViolations: leaked transactions and N+1 patterns (the same normalized query repeated 8 times in one request);- the last 128 queue job events; and
- current and peak PHP memory.
{ "requests": 4, "errors": 0, "queries": 3, "queryMilliseconds": 1.18, "routes": { "api/users": { "count": 3, "errors": 0, "totalNs": 12650103, "maxNs": 11500207 }, "api/tx": { "count": 1, "errors": 0, "totalNs": 748512, "maxNs": 748512 } }, "slowQueries": [], "stateViolations": [ { "kind": "transaction", "detail": "Rolled back leaked transaction on connection `sqlite`.", "observedAt": "2026-12-02T18:41:33+00:00" } ], "jobs": []}Metrics are per worker process, kept in memory, and bounded. Prefer the admin
/metrics endpoint for fleet-wide dashboards and use /__pam/metrics to
inspect a worker.
Add a Server-Timing: pam-laravel;dur=… header to every response with
PAM_LARAVEL_TIMING_HEADERS=true.
From the Command Line
Section titled “From the Command Line”pam artisan pam:health # JSON report; exit code 1 when unhealthypam artisan pam:leaks # memory, state violations, slow queries; exit 1 on violationsThese commands run in a fresh console process, so they report that process,
not your HTTP workers. Use them for the database check and in CI after a test
run; query /__pam/metrics for live workers.
OpenTelemetry Traces
Section titled “OpenTelemetry Traces”Enable the built-in OTLP/HTTP JSON exporter:
PAM_OTLP_ENABLED=trueOTEL_SERVICE_NAME=example-apiOTEL_SERVICE_VERSION=2026.12.02OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20secretOTEL_EXPORTER_OTLP_COMPRESSION=gzipPAM then records:
| Span | Kind | Attributes |
|---|---|---|
GET api/users |
server | method, path, status, route |
db.query |
client | connection, SQL summary with literals replaced by ? |
job App\Jobs\SendInvoice |
consumer | queue connection and name |
cache hit / miss / write / forget |
internal | store, SHA-256 of the key |
http.client |
client | method, host, status |
command reports:daily |
internal | exit code |
exception |
internal | exception class |
Incoming traceparent headers are continued. The exporter appends /v1/traces
when needed, buffers at most PAM_OTLP_BUFFER_LIMIT spans, times out after
500 ms, and fails open: export errors never fail a request unless
PAM_OTLP_FAIL_HARD=true. The OTEL_EXPORTER_OTLP_TRACES_* variants take
precedence over the generic ones.
Laravel Nightwatch
Section titled “Laravel Nightwatch”Nightwatch’s agent is a long-running process; run it beside your workers, never inside one:
pam composer require laravel/nightwatchpam artisan pam:nightwatch --install-processpam artisan pam:nightwatch--install-process adds this entry to pam.processes.json:
"nightwatch": { "command": ["pam", "artisan", "nightwatch:agent"], "instances": 1 }The check verifies the package is installed, the nightwatch:agent command
exists, NIGHTWATCH_TOKEN is set, and the manifest has a nightwatch process.
It exits 1 until all four pass. Keep the token in your secret store, not in a
committed file.
What to Alert On
Section titled “What to Alert On”/readyfailing, orpam_cluster_readydropping to0;- HTTP error rate and p95/p99 from
pam_http_request_duration_seconds; pam_event_loop_lag_max_secondsgrowing;pam_process_resident_memory_bytesclimbing between recycles;- non-empty
stateViolations; - queue age and failed jobs; and
- a new worker generation that never becomes ready.