Instrumentation
Pass module instances toinitialize() to instrument all calls automatically:
The Observe Wrapper
Wrap any async function to create a span:Parameters
See Data Capture and Privacy for
captureInput and captureOutput examples that keep sensitive values off spans.
To rewrite personal data in every span before export, pass a redact function to TraceRoot.initialize(). See Data Capture and Privacy.
Setting Trace Context
UseusingAttributes() to set user and session context for all spans created within a block:
Parameters
Updating Spans and Traces
Update the current span or trace programmatically:updateCurrentSpan Parameters
updateCurrentTrace Parameters
Flushing and Shutdown
By default, the TypeScript SDK batches spans to optimize performance, flushing them every 5 seconds or when 100 spans are accumulated. Important: The SDK’s only automatic shutdown flush is abeforeExit hook. Node.js does not emit beforeExit on process.exit(), unhandled exceptions, or signals like SIGINT/SIGTERM. Serverless runtimes that freeze the process (e.g. AWS Lambda, Cloud Functions) skip it too. In any of these cases, buffered spans will be lost if you exit without flushing explicitly.
To ensure all spans are exported before your script terminates, await shutdown() (or flush()):
flush() or shutdown() before terminating the process with process.exit().
(Note: The Python SDK registers an atexit handler that flushes spans automatically in most environments. However, atexit does not run when a serverless runtime freezes the process — Python handlers there still need traceroot.flush() before returning.)

