code wiki / (root) / nx_obs.nx

nx_obs.nx

buildroot/runtime/nx_obs.nx

4901 B145 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

obs.nx -- observability primitives (spans, structured logs). EFFICIENCY_ROADMAP ยง5.2. OpenTelemetry-style distributed tracing + structured logging. Today's observability is ad-hoc sys_write; this module lands a proper API with trace IDs, parent-child span relationships, + KV attributes. Phase A: runtime spans + log records serialised to stdout as JSON (or future Protobuf via protobuf_wire.nx). Phase B: `@trace` function attribute auto-instruments every call. Designed to match OpenTelemetry data model so future bridges to Jaeger / Honeycomb / Datadog are clean byte-copies. Invariants: OB1 Span IDs are 128-bit; collision probability at one million spans/sec for a year < 1 in 10^30. OB2 Parent-child relationships form a tree per trace_id (enforced by caller; runtime doesn't verify). OB3 Log records are structured: all fields get key+value; no printf-style interpolation (bad for aggregation).

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_rand.nx nx_obs.nx

imports: nx_syscalls.nxnx_rand.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main span_new_root sys_mmap rand_bytes rand_open_urandom sys_openat_rd sys_read sys_close span_new sys_mmap ↻ rand_bytes ↻ span_new ↻ span_close span_duration_ns

structs

46struct Span

consts

31const LOG_MAGIC_1000000000: i64 = 1000000000
32const LOG_MAGIC_1000100000: i64 = 1000100000
33const LOG_MAGIC_1000200000: i64 = 1000200000
34const LOG_MAGIC_100000: i64 = 100000
35const LOG_MAGIC_1000500000: i64 = 1000500000
36const LOG_MAGIC_500000: i64 = 500000
39const LOG_TRACE: i64 = 0
40const LOG_DEBUG: i64 = 1
41const LOG_INFO: i64 = 2
42const LOG_WARN: i64 = 3
43const LOG_ERROR: i64 = 4
44const LOG_FATAL: i64 = 5

functions

58func span_new(name: *u8, name_len: i64,
87func span_new_root(name: *u8, name_len: i64, start_ns: i64) -> *Span
called by 1: main calls 3: sys_mmaprand_bytesspan_new
99func span_close(s: *Span, end_ns: i64, status: i64) -> i64
called by 1: main
105func span_duration_ns(s: *Span) -> i64
called by 1: main
113func log_write(fd: i64, level: i64,
128func main() -> i64