Skip to content

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.

Start the cluster with --admin-address:

Terminal window
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.

A selection of what /metrics reports (real output, trimmed):

pam_cluster_ready 1
pam_cluster_workers 1
pam_http_requests_total 5
pam_http_errors_total 0
pam_http_active_requests 0
pam_http_client_disconnect_cancellations_total 0
pam_event_loop_lag_max_seconds 0.001023
pam_process_resident_memory_bytes 94793728
pam_php_memory_bytes 16777216
pam_php_peak_memory_bytes 16777216
pam_http_request_duration_seconds_bucket{le="0.01"} 3
pam_http_response_cache_hits_total 0

Stream them live in a terminal:

Terminal window
pam top http://127.0.0.1:3010

pushinbr/pam-laravel registers two routes:

Terminal window
curl http://127.0.0.1:3000/__pam/health
curl 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-value
Terminal window
curl -H "Authorization: Bearer $PAM_LARAVEL_OBSERVABILITY_TOKEN" http://127.0.0.1:3000/__pam/metrics

Change the paths with PAM_LARAVEL_HEALTH_PATH and PAM_LARAVEL_METRICS_PATH, or disable both with PAM_LARAVEL_HEALTH_ENABLED=false.

/__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.

Terminal window
pam artisan pam:health # JSON report; exit code 1 when unhealthy
pam artisan pam:leaks # memory, state violations, slow queries; exit 1 on violations

These 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.

Enable the built-in OTLP/HTTP JSON exporter:

PAM_OTLP_ENABLED=true
OTEL_SERVICE_NAME=example-api
OTEL_SERVICE_VERSION=2026.12.02
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20secret
OTEL_EXPORTER_OTLP_COMPRESSION=gzip

PAM 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.

Nightwatch’s agent is a long-running process; run it beside your workers, never inside one:

Terminal window
pam composer require laravel/nightwatch
pam artisan pam:nightwatch --install-process
pam 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.

  • /ready failing, or pam_cluster_ready dropping to 0;
  • HTTP error rate and p95/p99 from pam_http_request_duration_seconds;
  • pam_event_loop_lag_max_seconds growing;
  • pam_process_resident_memory_bytes climbing between recycles;
  • non-empty stateViolations;
  • queue age and failed jobs; and
  • a new worker generation that never becomes ready.