Traces
A trace represents a complete unit of work in your AI application - like handling a user request, processing a document, or running an agent workflow.What is a Trace?
Think of a trace as a timeline that captures everything that happens when your AI system processes a request:Trace Structure
Every trace has:| Property | Description |
|---|---|
traceId | Unique identifier (UUID) |
name | Human-readable name (optional) |
startTime | When the trace began |
endTime | When the trace completed |
duration | Total time in milliseconds |
status | ’completed’, ‘error’, or ‘running’ |
spans | Array of child spans |
Creating Traces
- JavaScript
- Python
Trace Hierarchy
Traces contain spans organized in a tree structure:Linking Related Work
UsetraceId to connect related operations:
Trace Context
Pass trace context across service boundaries:Viewing Traces
In the Foil dashboard, traces show:- Timeline View - Visual representation of all spans
- Span Details - Click any span to see inputs/outputs
- Token Usage - Total and per-span token counts
- Errors - Any failures highlighted in red
- Alerts - Quality issues detected by Foil
Best Practices
One trace per user request
One trace per user request
Create a new trace for each distinct user interaction. Don’t reuse trace IDs across requests.
Name traces descriptively
Name traces descriptively
Use names that describe the workflow:
process-customer-query, generate-report, analyze-document.Include conversation IDs
Include conversation IDs
For chat applications, include a
convoId to group traces from the same conversation.Don't over-nest
Don't over-nest
Keep span depth reasonable (typically 3-5 levels max). Deep nesting makes traces hard to read.