#pragma once // Observability skeletons: typed event bus, metrics registry, and tracer. // All three compile to near-zero overhead when kEnabled is false. // Gap: real 02-observability.md owns the log format, Prometheus and OTel // export, and the zero-cost macro layer. #include #include #include #include #include namespace molo::example::fw { struct Event { std::string type; std::string payload; std::string correlation_id; }; class EventBus { public: static constexpr bool kEnabled = true; void on(const std::string& type, std::function listener); void emit(const Event& event); std::vector delivered() const; private: mutable std::mutex mu_; std::map>> listeners_; std::vector delivered_; }; class Metrics { public: static constexpr bool kEnabled = true; void inc(const std::string& name, double value = 1.0); void gauge(const std::string& name, double value); double get(const std::string& name) const; std::string render_prometheus() const; private: mutable std::mutex mu_; std::map values_; }; struct Span { std::string trace_id; std::string span_id; std::string name; std::string correlation_id; }; class Telemetry { public: static constexpr bool kEnabled = true; Span start_span(const std::string& name, const std::string& correlation_id); void finish_span(const Span& span); std::vector spans() const; private: mutable std::mutex mu_; std::vector spans_; unsigned long next_id_ = 1; }; } // namespace molo::example::fw