Skip to main content
For narrative usage see the tutorial. For config details see configuration. For runnable end-to-end demos see examples.

Source and issues

TruLayer class

The main client. Import and construct once per app.

Methods

trace()

The return value of fn becomes the return value of trace(). Exceptions are captured onto the trace as errors, then re-thrown.

TraceContext

Passed to the trace() callback.

span()

SpanContext

Instrumentation helpers

instrumentOpenAI(client, tl?)

Returns a Proxy-wrapped client; every chat.completions.create and embeddings.create call becomes a span automatically.

instrumentAnthropic(client, tl?)

instrumentVercelAI(tl?)

Module-level helpers

init() / getClient()

If you prefer a global pattern over passing tl explicitly:

Types

All of the following are exported type-only (no runtime cost):

Error handling

SDK errors are logged, not thrown to your code — a failed flush drops traces but never interrupts your app. Subscribe to errors with:
Exception types (re-exported for narrowing):