TracingTraces & Spans

Traces & Spans

Detailed reference for the tracing data model.

Trace

A trace is the top-level container for a single agent execution.

FieldTypeDescription
iduuidUnique trace identifier
namestringHuman-readable name
statusrunning | success | errorCurrent trace status
inputJSONInput data passed to the agent
outputJSONFinal output from the agent
tagsstring[]Tags for filtering
session_idstringGroup traces by session
duration_msintegerAuto-calculated on endTrace
metadataJSONArbitrary metadata

Span

A span represents a single step within a trace.

FieldTypeDescription
iduuidUnique span identifier
trace_iduuidParent trace
parent_span_iduuidParent span (for nesting)
namestringHuman-readable name
typellm | tool | retrieval | agent | chain | spanSpan type for color-coding
modelstringModel name (for LLM spans)
providerstringProvider name (openai, anthropic, etc.)
prompt_tokensintegerInput tokens used
completion_tokensintegerOutput tokens used
total_tokensintegerTotal tokens
cost_usdnumberCost in USD
duration_msintegerAuto-calculated on endSpan
error_messagestringError details if status is error

Span Types

TypeColorWhen to use
llmBlueLLM API calls (OpenAI, Anthropic, etc.)
toolPurpleTool/function calls (database, API, etc.)
retrievalOrangeRAG retrieval, vector search, knowledge base
agentGreenSub-agent execution
chainPinkChain/pipeline steps
spanGrayGeneric step (default)

Nesting Spans

Pass parent_span_id when starting a span to create nested hierarchies:

The tree view in the dashboard automatically visualizes parent-child relationships between spans.
class=class="tk-str">"tk-cmt">// Nested spans example
const traceId = await ai.startTrace({ name: class="tk-str">'rag-pipeline' })

const parentSpan = await ai.startSpan({
  name: class="tk-str">'process-query',
  type: class="tk-str">'chain',
})

class=class="tk-str">"tk-cmt">// Child span nested under parentSpan
const retrieveSpan = await ai.startSpan({
  name: class="tk-str">'vector-search',
  type: class="tk-str">'retrieval',
  parent_span_id: parentSpan,
  input: { query: class="tk-str">'product specs' },
})
await ai.endSpan(retrieveSpan, {
  output: { results: 5 },
  status: class="tk-str">'success',
})

class=class="tk-str">"tk-cmt">// Another child span
const llmSpan = await ai.startSpan({
  name: class="tk-str">'generate-answer',
  type: class="tk-str">'llm',
  parent_span_id: parentSpan,
  model: class="tk-str">'claude-3-5-sonnet',
  provider: class="tk-str">'anthropic',
})
await ai.endSpan(llmSpan, {
  output: { answer: class="tk-str">'...' },
  prompt_tokens: 1200,
  completion_tokens: 350,
  total_tokens: 1550,
  cost_usd: 0.0089,
})

await ai.endSpan(parentSpan, { status: class="tk-str">'success' })
await ai.endTrace(traceId, { status: class="tk-str">'success' })