The function to trace. Can be synchronous or asynchronous.
Configuration options for the tracer.
A TracedFunction with the same signature as fn, plus a calls array and clear().
const traced = traceFunction(fetchUser, { label: 'fetchUser', log: true });
await traced('user-1');
await traced('user-2');
console.log(traced.calls.length); // 2
console.log(traced.calls[0].durationMs); // e.g. 42.3
console.log(traced.calls[0].result); // resolved value
traced.clear(); // reset call history
Wraps a function to record every invocation — arguments, return value (or error), and duration.
Works with both synchronous and asynchronous functions. For async functions the TraceCallInfo entry is appended after the Promise settles, and the wrapper transparently propagates the resolved value or rejection. Logging is opt-in via
log: true. Errors from TraceOptions.onCall are silently isolated and never reach the caller.