Skip to main content

nexus-observability-otel

OpenTelemetry SDK bridge — turns an ObservabilityConfig into a real Observability provider backed by OTLP exporters. Returns NoopObservability when disabled, so the same wiring works in every environment.

Install

terminal
composer require nexus-actors/observability-otel

What's in this package

ClassPurpose
ObservabilityFactoryStatic factory: fromConfig(ObservabilityConfig): Observability — the primary entry point
OtelObservabilitySDK-backed Observability implementation; owns TracerProvider + MeterProvider
OtelTracerBridges Nexus Tracer to OTEL TracerProviderInterface
OtelMeterBridges Nexus Meter to OTEL MeterProviderInterface
OtelSpanBridges Nexus Span to OTEL SpanInterface

Quick example

src/Bootstrap/ObservabilitySetup.php
use Monadial\Nexus\Observability\Config\ObservabilityConfig;
use Monadial\Nexus\Observability\Otel\ObservabilityFactory;

$config = ObservabilityConfig::fromEnv($_SERVER);
// or: ObservabilityConfig::enabled('my-service')->withExporterEndpoint('http://otel-collector:4318')

$obs = ObservabilityFactory::fromConfig($config);
// $obs is OtelObservability when enabled, NoopObservability when OTEL_SDK_DISABLED=true

// Call shutdown() once during graceful shutdown to flush pending spans/metrics
$obs->shutdown();

ObservabilityFactory::fromConfig() reads ObservabilityConfig::$sampler to wire the OTEL sampler (always_on, always_off, parentbased_always_on, traceidratio, etc.) and $exporterEndpoint to set the OTLP HTTP endpoint.

Sampler mapping

Config valueOTEL sampler
always_onAlwaysOnSampler
always_offAlwaysOffSampler
traceidratioTraceIdRatioBasedSampler($samplerArg)
parentbased_traceidratioParentBased(TraceIdRatioBasedSampler($samplerArg))
anything else (default)ParentBased(AlwaysOnSampler)

See also