Skip to content

ObservabilityAdapter

Viames Marino edited this page Sep 30, 2026 · 1 revision

Pair framework: ObservabilityAdapter

Pair\Core\ObservabilityAdapter receives completed runtime spans from Observability.

Contract

public function record(\Pair\Core\ObservabilitySpan $span): void;

ObservabilitySpan exposes the operation name, start/end timestamps, duration in milliseconds, status, sanitized attributes, and correlation ID through accessor methods and toArray().

Register an adapter

use Pair\Core\Observability;
use Pair\Core\ObservabilityAdapter;
use Pair\Core\ObservabilitySpan;

final class LogSpanAdapter implements ObservabilityAdapter {

	/**
	 * Forward one completed span to the application log.
	 */
	public function record(ObservabilitySpan $span): void {
		error_log(json_encode($span->toArray(), JSON_UNESCAPED_SLASHES));
	}

}

Observability::setAdapter(new LogSpanAdapter());

Installing an adapter enables instrumentation unless it is explicitly disabled with Observability::enable(false). Applications can also register it under AdapterKeys::OBSERVABILITY; see AdapterRegistry.

Implement ObservabilityEventAdapter as well when the collector should receive non-span warning/error events. The two interfaces are separate so existing span-only adapters remain compatible.

See Observability for sampling, environment configuration, event limits, and debug headers. Built-in collectors include SentryObservabilityAdapter and OpenTelemetryHttpExporter.

Clone this wiki locally