Skip to content

Observability & Diagnostics

A persistent runtime needs different instruments than PHP-FPM. Memory that is not released, a request that blocks the event loop, or a worker stuck draining all show up over time, not in a single request. PAM exposes them at three levels:

  • Live metrics and health: Prometheus /metrics on each worker, and a cluster control plane with health, readiness and diagnostics endpoints that pam top reads.
  • Logs and traces: JSON access logs, Pam\Observability\Telemetry for your own logs and spans, W3C trace context and OTLP export.
  • Snapshots: commands such as pam diagnostics, pam heap and pam fibers that load your application and print what is in memory, plus a private dashboard for applications managed by pam up.

Every worker answers GET /metrics (change the path with metricsPath) in the Prometheus text format:

pam_http_requests_total 3
pam_http_errors_total 0
pam_http_client_disconnect_cancellations_total 0
pam_http_active_requests 1
pam_http_response_cache_hits_total 0
pam_websocket_connections 0
pam_event_loop_lag_seconds 0.000229
pam_event_loop_lag_max_seconds 0.001210
pam_process_resident_memory_bytes 50331648
pam_php_memory_bytes 4194304
pam_php_fibers 0
pam_process_info{worker="standalone",generation="1",pid="1041273"} 1
pam_otlp_spans_exported_total 0
pam_http_request_duration_seconds_bucket{le="0.0005"} 1
...

The families you will use most:

Metric Meaning
pam_http_requests_total, pam_http_errors_total Requests and 5xx responses
pam_http_active_requests Requests in flight, suspended ones included
pam_http_request_duration_seconds Latency histogram, 100 µs to 5 s buckets
pam_http_client_disconnect_cancellations_total Requests cancelled because the client left
pam_event_loop_lag_seconds (and _max_, _average_) How long the worker took to get back to the event loop; high values mean blocking code
pam_process_resident_memory_bytes, pam_php_memory_bytes, pam_php_peak_memory_bytes Process RSS and PHP heap
pam_php_fibers Live Fibers
pam_websocket_* Connections, messages, backpressure
pam_http_response_cache_* Edge page cache counters
pam_otlp_* OTLP exporter health

Set routeMetrics: true to add per-route counters and histograms (pam_http_route_requests_total, pam_http_route_request_duration_seconds) for frameworks that register route templates, such as Nimbus. routeMetricsMaxEntries (256) bounds the number of routes; extra ones are counted in pam_http_route_metrics_overflow_total.

By default a worker answers /metrics only to loopback peers, and not to a loopback request that carries X-Forwarded-For, Forwarded or X-Real-IP (a proxy on the same host). Everyone else reaches your application’s own route for that path.

Option Environment Effect
metricsToken PAM_METRICS_TOKEN Require Authorization: Bearer <token> from any peer
metricsPublic PAM_METRICS_PUBLIC=1 Serve every peer without a token
metricsPath Change the path (default /metrics)
$server->listen(3000, '0.0.0.0', [
'metricsToken' => getenv('PAM_METRICS_TOKEN') ?: null,
]);
Terminal window
curl -H "Authorization: Bearer $PAM_METRICS_TOKEN" http://10.0.0.5:3000/metrics

A request without a valid token is passed to your application like any other request.

A cluster started with --admin-address exposes a separate, aggregated endpoint for the whole cluster:

Terminal window
pam start index.php --workers 8 --admin-address 127.0.0.1:3010
Endpoint Purpose
/live The master is running
/ready The cluster can take traffic (200) or not (503)
/startup Startup finished, with a JSON body
/health Versioned JSON with every worker’s ID, generation, PID, pool and state
/metrics Cluster, pool and worker series in Prometheus format
/diagnostics Versioned JSON used by pam top --json

Worker states are integers: 1 starting, 2 ready, 3 busy, 4 draining. Point your orchestrator’s probes at /live and /ready directly; never route them through the public virtual host.

On loopback the token is optional. On any other address the master refuses to start unless PAM_ADMIN_TOKEN or PAM_ADMIN_TOKEN_FILE provides a token of 32 to 256 printable characters; every endpoint then requires Authorization: Bearer <token>. The control plane speaks plain HTTP, so keep it on a private network or behind a TLS sidecar. See Clustering for the full option list.

pam top samples the control plane and prints a live table. It reads only the control plane, so it never enters PHP:

Terminal window
pam top http://127.0.0.1:3010 --iterations 60 --interval-ms 1000 --lag-warn-ms 10
PAM / LIVE TELEMETRY sample 01/01 · http://127.0.0.1:3010
────────────────────────────────────────────────────────────
● [ok] no worker at or above 10 ms current event-loop lag
pam_cluster_workers 3
pam_http_requests_total 15
pam_http_errors_total 0
pam_http_active_requests 0
pam_event_loop_lag_seconds 0.000000
pam_event_loop_lag_max_seconds 0.001596
pam_process_resident_memory_bytes 81637376
...
Option Default Description
[admin-url] http://127.0.0.1:3010 Control plane address
--iterations N 10 Number of samples
--interval-ms N 1000 Delay between samples
--lag-warn-ms N 10 Mark workers whose current event-loop lag is at or above N ms (1 to 60000)
--json Emit one versioned NDJSON object per sample

Only the current lag triggers the [warn] marker; maximum and average stay visible as context. With --json, each line carries resultCode (1 no alert, 2 alert) and, per worker, workerId, generation, pid, pool, lifecycleCode and lag in microseconds:

Terminal window
pam top http://127.0.0.1:3010 --iterations 60 --json > pam-top.ndjson

pam top sends PAM_ADMIN_TOKEN automatically when it is set. The schemas are docs/schemas/top-sample.schema.json and control-plane-diagnostics.schema.json in the PAM repository.

Set accessLog: true to write one JSON line per request to stderr:

{"durationMs":11.785209,"event":"http.request","level":"info","method":"GET","requestId":"standalone-1388063-1","status":200,"target":"/checkout","timestamp":1796237548809,"traceparent":"","worker":"standalone"}

Server errors (5xx) are logged even when access logs are off. Under heavy traffic, accessLogSampleRate: 100 logs one request in a hundred; use /metrics for exact totals. Collect stderr with your process supervisor or container runtime.

Telemetry::log() writes the same JSON shape and adds the current request ID, trace context and worker ID. {placeholders} are filled from the context:

use Pam\Observability\Telemetry;
Telemetry::log('info', 'Order {order} placed', ['order' => 1001]);
{"timestamp":1796237548809,"level":"info","message":"Order 1001 placed","context":{"order":1001},"requestId":"standalone-1388063-1","traceparent":"00-000001a2...-01","worker":"standalone"}

When psr/log is installed, Pam\Observability\Logger is a PSR-3 logger that forwards to Telemetry::log(), so you can hand it to any library that expects a LoggerInterface. Frameworks may provide their own logging; see Logging.

Set telemetryHeaders: true to return x-request-id, traceparent and Server-Timing on every response. PAM continues a valid incoming W3C traceparent (version 00) with a new server span ID; malformed values start a new trace. It is off by default to save bytes on every response.

Wrap interesting work in Telemetry::span(). The span’s duration is logged at debug level, and when the OpenTelemetry PHP API is installed, a real span is started, activated, marked OK or ERROR and ended:

use Pam\Observability\Telemetry;
$total = Telemetry::span('checkout.total', static function () use ($cart): int {
return $cart->total();
}, ['cart.items' => 3]);

The runtime itself exports one span per HTTP request to an OpenTelemetry collector over OTLP/HTTP JSON:

Terminal window
OTEL_SERVICE_NAME=catalog-api \
OTEL_EXPORTER_OTLP_ENDPOINT=https://collector.example.com \
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/json \
OTEL_EXPORTER_OTLP_HEADERS='authorization=Bearer%20token' \
pam start index.php --workers 4
Variable Notes
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT Full traces URL; or OTEL_EXPORTER_OTLP_ENDPOINT, to which /v1/traces is appended
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL / OTEL_EXPORTER_OTLP_PROTOCOL Must be http/json; anything else stops startup with an error
OTEL_EXPORTER_OTLP_TRACES_HEADERS / OTEL_EXPORTER_OTLP_HEADERS Percent-encoded key=value pairs; never logged
OTEL_SERVICE_NAME Defaults to pam
OTEL_BSP_MAX_QUEUE_SIZE Default 2048
OTEL_BSP_MAX_EXPORT_BATCH_SIZE Default 512
OTEL_BSP_SCHEDULE_DELAY Default 5000 ms
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT / OTEL_EXPORTER_OTLP_TIMEOUT Default 10000 ms

The queue never blocks a response: when the collector is slow, spans are dropped and counted. Exported spans contain the method, status and validated route template, never the concrete URL, query string or request ID. Plain HTTP is accepted only for loopback collectors. Watch pam_otlp_spans_exported_total, _dropped_total, _rejected_total and pam_otlp_export_errors_total.

These commands load your application in a fresh process (without serving traffic), then print a JSON snapshot:

Command Prints
pam diagnostics [index.php] The full snapshot
pam heap [index.php] Memory and garbage collector status
pam fibers [index.php] Pending futures and active request scopes
pam connections [index.php] HTTP dispatches, WebSockets and rooms
pam profile [index.php] The snapshot with PAM_PROFILE=1
pam trace [index.php] The snapshot with PAM_TRACE=1
pam inspect [index.php] Runtime capabilities: PHP version, SAPI, ini files, extensions
Terminal window
pam heap index.php
{
"allocatedBytes": 4194304,
"gc": { "collected": 0, "roots": 5, "runs": 0, "threshold": 10001, "...": "..." },
"peakBytes": 4194304,
"usedBytes": 1972224
}

Use them to see what your bootstrap costs: memory after boot, open resources by type, and leak-detector counters.

The same switches work on a running server:

  • PAM_PROFILE=1 aggregates per-request duration and memory under profiles['http.request'];
  • PAM_TRACE=1 records diagnostic events (request start and end, Fiber suspend and resume, I/O, cleanup, errors) and also writes each one to stderr as a pam_trace JSON line;
  • PAM_DIAGNOSTICS=1 records events without printing them.

Read them from your own protected endpoint with Pam\Diagnostics\Diagnostics::snapshot():

use Pam\Diagnostics\Diagnostics;
if ($request->path === '/internal/pam' && $isAdmin) {
return $response->json(Diagnostics::snapshot()['profiles']);
}
{"http.request":{"count":1,"durationNanoseconds":11485099,"memoryDeltaBytes":4840,"peakMemoryBytes":2546088}}

The event buffer keeps the last 1,024 events. To process events as they happen, register a callback with Pam\Diagnostics\Channel::subscribe(callable $subscriber); it receives Pam\Diagnostics\Event objects (kind, timestampNanoseconds, requestId, context) and enables event recording while subscribed.

For applications started with pam up:

  • pam monit shows live state and pam monit:history [name] [--limit N] [--json] reads the resource samples the manager records every 60 seconds (at most 120 per application). --record captures a sample now.
  • pam dashboard [file.html] writes a private, self-contained HTML snapshot of every managed application (no scripts, no external assets, never overwrites an existing file).
  • pam dashboard:start --token-file TOKEN serves an authenticated live dashboard on 127.0.0.1:9615 (change it with --listen 127.0.0.1:PORT); pam dashboard:status --json and pam dashboard:stop manage it. Log in with user pam and the token, or send Authorization: Bearer TOKEN.
Terminal window
umask 077
openssl rand -hex 32 > pam-dashboard.token
pam dashboard:start --token-file pam-dashboard.token

pam support runs the doctor audit and prints a bounded, redacted JSON report you can attach to an issue. Paths are replaced with $PROJECT and $HOME; environment values, network data and file contents are never included. --output pam-support.json writes it with owner-only permissions, and --manager adds the pam monit --json snapshot. Review the report before sharing it.

Terminal window
pam support --output pam-support.json