The causal stack and hook surface the runtime records through.
Every instrumented site in the runtime talks to this one module. It holds two things: a pointer to the active recorder, and the causal stack — the chain of nodes currently being executed, innermost last. A node emitted while that stack is non-empty is attributed to whatever sits on top of it, which is what turns a flat log into "this DOM patch happened because that click ran that action which wrote that property".
Cost when tracing is off
Tracing is off by default and must stay free. Every hook site is written as a guarded pair:
const token = tracer.on ? tracer.enter(TYPE, data) : -1;
try { ... } finally { if (token >= 0) tracer.leave(token); }
With on === false that is one property read and one comparison; the
descriptor object is never allocated, because it only appears inside the
conditional. Nothing else in the runtime changes shape.
Stack safety
enter returns a restore token rather than expecting a balanced leave.
leave truncates the stack back to that depth, so an exception unwinding
past a leave cannot leave the tracer permanently mis-parented — the next
outer leave repairs it.
- Source:
Classes
Members
(static, constant) tracer :Tracer
The process-wide tracer. Inactive until a recorder attaches to it.
Type:
- Tracer
- Source: