Instrumentation
The Observe Decorator
Wrap any function to create a span, works with both sync and async functions.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 |
Setting Trace Context
Useusing_attributes to set user and session context:
user_id and session_id.
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_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 |