Instrumentation
The Observe Decorator
Wrap any function to create a span, works with sync functions, async functions, and generators.Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | function name | Span name |
type | SpanKind | str | "span" | Span kind: "llm", "agent", "tool", or "span" (accepts both SpanKind enum and string values) |
metadata | dict | None | Static metadata to attach |
tags | list[str] | None | Tags to attach |
capture_input | bool | True | Whether to auto-capture function arguments as input |
capture_output | bool | True | Whether to auto-capture the return value as output |
session_id | str | None | Session identifier to attach to the trace |
user_id | str | None | User identifier to attach to the trace |
Setting Trace Context
Useusing_attributes to set user and session context for all spans created within a block:
Parameters
| Parameter | Type | Description |
|---|---|---|
user_id | str | User identifier |
session_id | str | Session / conversation ID |
tags | list[str] | Tags to attach to all spans |
metadata | dict | Arbitrary metadata |
Updating Spans and Traces
Update the current span or trace programmatically:update_current_span Parameters
| Parameter | Type | Description |
|---|---|---|
name | str | Update the span name |
input | Any | Input data |
output | Any | Output data |
metadata | dict | Custom metadata key-value pairs |
model | str | LLM model name (e.g., "gpt-4o") |
model_parameters | dict | Model parameters (e.g., temperature, max_tokens) |
usage | dict | Token usage (e.g., {"input_tokens": 100, "output_tokens": 50}) |
prompt | Any | Prompt/messages sent to the LLM |
update_current_trace Parameters
| Parameter | Type | Description |
|---|---|---|
user_id | str | User who initiated the trace |
session_id | str | Session identifier for grouping traces |
metadata | dict | Trace-level metadata |
tags | list[str] | Tags to categorize the trace |
Environment Variables
All parameters can be set via 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_FLUSH_INTERVAL | 5.0 | Flush interval in seconds |
TRACEROOT_FLUSH_AT | 100 | Batch size before flush |
TRACEROOT_TIMEOUT | 30.0 | HTTP timeout in seconds |
TRACEROOT_GIT_REPO | auto-detected | Git repository (owner/repo) |
TRACEROOT_GIT_REF | auto-detected | Git reference |