Skip to main content

nexus-observability-swoole

Swoole observability — coroutine-aware OTEL context storage so active spans are isolated per coroutine, and Swoole server/coroutine statistics as observable gauges.

Install

terminal
composer require nexus-actors/observability-swoole

What's in this package

ClassPurpose
SwooleContextRegistrarInstalls SwooleContextStorage as the OTEL context backend; call once per worker at startup; idempotent
SwooleAdminMetricsRegisters Swoole server/coroutine statistics as OTEL observable gauges; registerCoroutineGauges() and registerServerGauges(Server $server)

Quick example

src/WorkerPool/Bootstrap.php
use Monadial\Nexus\Observability\Swoole\SwooleAdminMetrics;
use Monadial\Nexus\Observability\Swoole\SwooleContextRegistrar;

// 1. Install coroutine-isolated context storage (must run inside a worker coroutine)
SwooleContextRegistrar::install();

// 2. Register system gauges — $server is a Swoole\Server instance
$metrics = new SwooleAdminMetrics($obs);
$metrics->registerCoroutineGauges();
$metrics->registerServerGauges($server);

Without SwooleContextRegistrar::install(), the active span leaks across coroutines because the default OTEL context storage is not coroutine-aware. Call install() before starting any telemetry work on each worker thread.

Emitted gauges

MetricDescription
swoole.coroutine.countNumber of running coroutines
swoole.coroutine.peakPeak concurrent coroutines
swoole.server.connectionsActive server connections
swoole.server.requestsTotal requests handled
swoole.server.workers.idleIdle worker processes

Gauges are collected on demand by the OTEL metric reader — no polling loop required. All are server-wide with no high-cardinality dimensions.

See also