Files

3.1 KiB

Observability Hooks, Context, Metrics, and Tracing

Task ID: S-OBSERVABILITY-01..04 Phase: P2 Status: APPROVED Contracts: C-01, C-02, C-03, C-04, C-05

1. Context and baseline

ObservabilityHooks and Observability do not yet exist in src/ or include/Void/Observability/. Higher modules need zero-dependency instrumentation hooks, HookLease drain lifetimes, immutable ContextSnapshot propagation, bounded producer-sharded metrics, head-sampled bounded tracing, and a deterministic text snapshot exporter with zero dependency on Async, IO, Runtime, Log, Net, Configuration, or System.

2. Deliverables

  • src/ObservabilityHooks/module.cmake (header-only Void/Observability/Hooks.hpp, zero deps)
  • src/Observability/module.cmake (INTERNAL_DEPS ObservabilityHooks Core Functional Time Memory, EXCLUDE_HEADERS Void/Observability/Hooks.hpp)
  • include/Void/Observability/Hooks.hpp: MetricKind, AttributeView, MetricPoint, DiagnosticEvent, ObservationHooks, kNullObservationHooks, DrainStatus, HookRegistrationId, HookLease, HookSlot
  • include/Void/Observability/Context.hpp: ObservabilityErrorCode, make_observability_error (kObservabilityErrorDomain = 14), TraceId, SpanId, TraceContext, ContextLimits, ContextSnapshot, ScopedContext
  • include/Void/Observability/AsyncContext.hpp: bind_context, ContextAwaitable (no #include <Void/Async/...>)
  • include/Void/Observability/Metrics.hpp & src/Observability/Metrics.cpp: MetricsLimits, InstrumentSpec, InstrumentHandle, HistogramSnapshot, SeriesSnapshot, MetricsSnapshot, MetricRegistry
  • include/Void/Observability/Tracing.hpp & src/Observability/Tracing.cpp: TracingLimits, SpanStatus, SpanSpec, SpanEvent, CompletedSpan, ExportBatch, ExportReport, ExportOptions, Span, SpanExporter, CallbackSpanExporter, TextSnapshotExporter, Tracer
  • include/Void/Observability/Observability.hpp
  • tests/standalone/Observability/Observability.cpp
  • tests/package/ObservabilityHooksOnly/{CMakeLists.txt,main.cpp} & tests/package/ObservabilityOnly/{CMakeLists.txt,main.cpp} registered in tests/package/InstalledComponents.cmake

3. Edge cases

  • Null hooks allocate zero memory and initialize no backend.
  • HookSlot::detach_and_drain detects self-drain from within an active callback (would_deadlock) and destroys owners strictly outside the lock.
  • Exiting producer threads retain their metric shards via std::shared_ptr<Shard> in MetricRegistry while thread_local caches hold std::weak_ptr<Shard>, preventing leaks when MetricRegistry is destroyed.
  • Cardinality overflow routes to __overflow__ and increments overflow counters; exporting respects span/byte caps, retry limits, and deadline/stop without spawning hidden background threads.

4. Verification commands

dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w5-obs -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Observability;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w5-obs && /tmp/void-w5-obs/tests/VoidTests --filter "Observability*" && ctest --test-dir /tmp/void-w5-obs --output-on-failure --timeout 120'