Files
moloapp/src/observability
retoor 3c4334cec9 feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
2026-10-23 18:20:04 +02:00
..

Observability backbone (02-observability.md)

Four pillars plus correlation: logging (molo::log), typed events (molo::events), metrics (molo::metrics), distributed tracing (molo::trace), correlation (molo::corr), shared config and lifecycle hooks (molo::obs). Spec: plans/02-observability.md.

Layout

  • config.h: compile flags, runtime toggles, static ceilings.
  • hooks.h: runtime lifecycle hook points, all optional no-ops until wired.
  • correlation/: request IDs, RequestContext, shared redaction helper.
  • logging/: levels, records, loggers, sinks (console, file with rotation, null, ring, async), JSON format, registry, MOLO_LOG_* macros.
  • events/: event base with clone, sync/async listeners, dispatcher with pubsub bridge hook, lifecycle event set.
  • metrics/: counter, gauge, histogram, RAII timer, labels, registry with cardinality caps, Prometheus text renderer.
  • tracing/: IDs, span context, spans, tracer, samplers, W3C propagator, batch processor, exporters (memory, OTLP/HTTP JSON).
  • observability.h: umbrella header. observability.mk: root Makefile fragment.

Rules that matter here

  • Disabled pillars cost one branch at runtime and compile to nothing at compile time (MOLO_OBSERVABILITY, MOLO_ACTIVE_LEVEL, MOLO_ENABLE_METRICS, MOLO_ENABLE_TRACING, MOLO_ENABLE_EVENTS).
  • No pillar blocks a handler: bounded queues, drop-on-full, visible counters.
  • Static ceilings live in config.h (Caps). Overflows drop and count.
  • Secrets are redacted by molo::corr::is_sensitive_key in loggers and spans.
  • Label values must be bounded sets; the registry maps the 65th distinct value per key to "other". Raw paths and user IDs are forbidden.
  • Counters end in _total (auto-appended), histograms export cumulative _bucket plus _sum and _count.
  • Server span names are {METHOD} {route_template}; raw paths forbidden.

Wiring points owned elsewhere

  • Runtime threads and request lifecycle call molo::obs::fire_* (01, 05).
  • Pubsub core registers via Dispatcher::set_publisher (01 or 06).
  • GET /metrics renders molo::metrics::render (09).
  • OTLP sender becomes the framework HTTP client via HttpSender (08); NullHttpSender is the marked stub until then.
  • gzip for OTLP needs the codec from 01 via set_compressor.

Build and test

Included by the root Makefile through observability.mk (obs-test target). Standalone:

g++ -std=c++23 -O2 -Wall -Wextra -pthread -Isrc <sources> \
  -Itests/src/observability tests/src/observability/<name>_test.cpp \
  -o build/obs_tests/<name>

Tests assert on RingSink, registry snapshots and MemoryExporter, never on files or network, except FileSink rotation which uses build/.