Record a span
Create spans inside the trace root callback so they nest under the trace.- TypeScript
- Python
{ asType: "span" } is the default, so you can omit it.
Nesting spans
Spans can contain other spans, generations, and tool calls. Anything created inside a span’s callback becomes its child, which is how you model a multi-step sub-task:What to record
| Field | Use |
|---|---|
input | Inputs to the operation (keep it a small summary if large) |
output | Result or a summary of the result |
level + statusMessage | Mark errors (level: "ERROR") |
metadata | Operation-specific detail for debugging |
Spans are for app logic that the model and tools do not cover. Start with generations and tool calls; add spans where you need to time or debug a specific step.
Next steps
Threads & context
Group conversations and attach users, sessions, and metadata.
Trace contract
The exact shape Lemma reads.