Instrumentation
Pass module instances toinitialize() to instrument all calls automatically:
The Observe Wrapper
Wrap any async function to create a span:Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | function name | Span name |
type | 'span' | 'agent' | 'tool' | 'llm' | 'span' | Span kind — 'agent' for multi-step agents, 'tool' for function calls, 'llm' for model inference, 'span' for generic |
metadata | Record<string, unknown> | — | Static metadata to attach |
tags | string[] | — | Tags to attach |
Setting Trace Context
UseusingAttributes() to set user and session context for all spans created within a block:
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | Session / conversation ID |
userId | string | User identifier |
tags | string[] | Tags to attach to all spans |
metadata | Record<string, unknown> | Arbitrary metadata |
Updating Spans and Traces
Update the current span or trace programmatically:updateCurrentSpan Parameters
| Parameter | Type | Description |
|---|---|---|
input | unknown | Input data |
output | unknown | Output data |
metadata | Record<string, unknown> | Custom metadata |
updateCurrentTrace Parameters
| Parameter | Type | Description |
|---|---|---|
userId | string | User identifier |
sessionId | string | Session identifier |
tags | string[] | Tags for the trace |
metadata | Record<string, unknown> | Trace-level metadata |
Environment Variables
| Variable | Default | Description |
|---|---|---|
TRACEROOT_API_KEY | (required) | API key |
TRACEROOT_HOST_URL | https://app.traceroot.ai | API endpoint |
TRACEROOT_ENABLED | true | Enable/disable tracing |
TRACEROOT_ENVIRONMENT | — | Deployment environment tag (e.g. production, staging) |
TRACEROOT_GIT_REPO | auto-detected | Git repository (owner/repo) |
TRACEROOT_GIT_REF | auto-detected | Git reference |