Wrap a function at its definition so it opens a LangSmith child span every time it runs — the
definition-site counterpart to the call-site withStepTrace. The wrapped export keeps its own
name (no traced twin), and the span nests automatically under whatever root/child span is active
(via traceable's async context). Use it for deterministic pipeline steps — gates, derivations,
post-process — whose output you'd want to inspect in a trace.
The return value is auto-captured as the span's output (through the Set/Map-safe trace
serializer); pass traceInputs to also record a non-PII projection of the arguments. Tracing
no-ops when disabled, so the wrapped function runs its raw body unchanged (just Promise-wrapped).
Because traceable always returns a promise, the wrapped function is async even if fn is
synchronous — call sites and tests await it.
Wrap a function at its definition so it opens a LangSmith child span every time it runs — the definition-site counterpart to the call-site
withStepTrace. The wrapped export keeps its own name (no traced twin), and the span nests automatically under whatever root/child span is active (viatraceable's async context). Use it for deterministic pipeline steps — gates, derivations, post-process — whose output you'd want to inspect in a trace.The return value is auto-captured as the span's output (through the Set/Map-safe trace serializer); pass
traceInputsto also record a non-PII projection of the arguments. Tracing no-ops when disabled, so the wrapped function runs its raw body unchanged (just Promise-wrapped).Because
traceablealways returns a promise, the wrapped function is async even iffnis synchronous — call sites and testsawaitit.