Skip to main content

nexus-observability-http

HTTP observability — a PSR-15 middleware that opens a server span per request and a PSR-14 listener that records RED metrics from the HTTP request lifecycle.

Install

terminal
composer require nexus-actors/observability-http

What's in this package

ClassPurpose
ServerSpanMiddlewarePSR-15 middleware: extracts inbound trace context, opens an OTEL Server span, records http.* attributes + status, and records handler exceptions
HttpMetricsListenerPSR-14 listener: records http.server.active_requests (UpDownCounter) and http.server.request.duration (Histogram) from RequestStarted/RequestCompleted events

Quick example

src/Http/Bootstrap.php
use Monadial\Nexus\Observability\Http\HttpMetricsListener;
use Monadial\Nexus\Observability\Http\ServerSpanMiddleware;

// $obs is an Observability instance (e.g. from ObservabilityFactory::fromConfig())
// $app is your HttpApplication

$app->middleware(new ServerSpanMiddleware($obs));

// Register the listener with the PSR-14 event dispatcher
$dispatcher->addListener(
\Monadial\Nexus\Http\Event\RequestStarted::class,
[new HttpMetricsListener($obs), 'onRequestStarted'],
);
$dispatcher->addListener(
\Monadial\Nexus\Http\Event\RequestCompleted::class,
[new HttpMetricsListener($obs), 'onRequestCompleted'],
);

ServerSpanMiddleware is fail-isolated: telemetry errors never break the request. When $obs->isEnabled() returns false, the middleware is a transparent pass-through. Register it as the outermost layer so the span covers the entire request including other middleware.

Emitted metrics

MetricTypeDescription
http.server.active_requestsUpDownCounterIn-flight requests; dimension: http.request.method
http.server.request.durationHistogram (seconds)Request duration; dimensions: http.request.method, http.response.status_code

See also