1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Structured observability / audit spine (`tracing` feature, default-off).
//!
//! RLX's diagnostics are ~2600 ad-hoc `eprintln!`/`println!` sites: unstructured
//! and impossible to feed into an audit trail. This module is the typed, opt-in
//! alternative — a thin facade over the `tracing` crate that emits STRUCTURED
//! events with a stable name plus a metadata detail. It is the foundation for
//! the audit-logging a HIPAA/FDA validated pipeline needs (per-inference
//! records: model + weight hash, engine version, device, shapes, timing).
//!
//! ## PHI-safety invariant (load-bearing)
//! Events carry METADATA ONLY — ids, content hashes, shapes, dtypes, op kinds,
//! counts, timings. NEVER pass tensor contents, input values, decoded text, or
//! raw file paths that could embed PHI. Reference data by a content hash, never
//! the data itself. A leaked value in a log is a reportable breach, so the facade
//! deliberately takes a formatted *detail* the caller controls rather than
//! slurping arbitrary state.
//!
//! ## Zero-overhead default
//! Without the `tracing` feature every entry point compiles to a no-op (the
//! optimizer removes the call), exactly like [`crate::kernel_trace`]. Turn on
//! `--features tracing` to get structured logs; a downstream product installs
//! its own `tracing` subscriber to route events to an append-only audit sink.
//!
//! ```ignore
//! rlx_runtime::obs::event("inference", format_args!(
//! "model={model_id} weight_sha={weight_sha} engine={engine} device={dev}"
//! ));
//! ```
//!
//! This is a *foundation*: one representative call site (`maybe_log_fusion`) is
//! wired through it. Migrating the remaining diagnostics off `eprintln!` is
//! tracked follow-up — each converted site becomes audit-visible for free.
/// Install a default `tracing` subscriber (idempotent). No-op without the
/// `tracing` feature. A downstream product typically installs its OWN
/// subscriber (to route to an audit sink) and never calls this; it exists so
/// `--features tracing` is usable standalone (tests, local debugging).
/// No-op without the `tracing` feature.
/// Emit a structured observability/audit event. `kind` is a stable event name
/// (e.g. `"compile.fusion"`, `"inference"`); `detail` is a caller-formatted,
/// METADATA-ONLY payload (see the PHI-safety invariant). No-op without the
/// `tracing` feature — the optimizer removes the call.
/// No-op without the `tracing` feature.
/// Structured event with a caller-controlled metadata detail. Expands to a
/// no-op without the `tracing` feature (the optimizer removes it), mirroring
/// [`crate::ktrace`]. Keep the detail metadata-only — never tensor values.