Skip to main content

Module diag

Module diag 

Source
Expand description

P2.10 (0.5.11): structured diagnostic trace.

Optional append-only JSONL log at $WIRE_HOME/state/wire/diag.jsonl. Every meaningful wire op (pull, push, pair transition, daemon spawn, schema rejection) emits one line. The previous “what is this binary actually doing right now” question required pgrep + strace + dtruss — now it’s wire diag tail.

Off by default. Enable per-process via env WIRE_DIAG=1, or per-machine via writing the file $WIRE_HOME/state/wire/diag.enabled (any non-empty content). Either signal flips emit() from a no-op to a real write — the env knob is good for one-off CLI sessions, the file knob is good for daemons that operators want to keep tracing across restarts without modifying their launchd plist.

Cost: a single OpenOptions::append(true) + write_all per event when enabled, no-op otherwise. The hot path checks one env var + one file metadata stat.

Functions§

emit
Append a structured diag entry. No-op when disabled. Never panics, never propagates an error — diag is a best-effort breadcrumb, not a load-bearing channel. If the write fails, we’d rather lose the trace line than break the operation we were instrumenting.
is_enabled
True if diag emission is enabled for THIS process invocation.
tail
Read the last n lines from diag.jsonl. Returns parsed JSON lines; malformed entries are skipped silently. Used by wire doctor --tail diag (or wire diag tail).