Go from install to live trace in under 5 minutes. This guide gets your OpenAI agent fully instrumented with structured spans, cost tracking, and one-click replay.Documentation Index
Fetch the complete documentation index at: https://docs.tracepilotai.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Node.js or TypeScript project using the OpenAI SDK
- An OpenAI API key
- Node.js 18+
1. Install
2. Add your API key
Get your key from tracepilotai.com → Account Settings..env
3. Initialize the OpenAI client
lib/clients.ts
4. Wrap your first completion
agent.ts
tp.wrapOpenAI returns the original result untouched — plus a spanId for chaining.
5. Trace a multi-step agent
agent.ts
Expected dashboard output
After running your agent, open tracepilotai.com/dashboard:
6. Replay a failing span
When a span fails in production, you don’t need to redeploy to debug it.Find the failing trace
Go to tracepilotai.com/dashboard. Failed traces are marked with a red ✗. Click the trace.
Open the failing span
Expand the span tree and click the span where the failure occurred. You’ll see the exact
messages array, model parameters, token usage, and error output.Replay example — what TracePilot captures per span
Troubleshooting
Trace not showing in dashboard
Trace not showing in dashboard
- Confirm
TRACEPILOT_API_KEYstarts withtp_live_. tp.startTrace()must be called before anywrapOpenAIcall in the same execution.- Check your network: TracePilot ships spans over HTTPS to
ingest.tracepilotai.com. Ensure it’s not blocked by a firewall or proxy.
spanId is undefined
spanId is undefined
tp.wrapOpenAI() always returns a spanId. If it’s undefined, the call threw before TracePilot could create the span. Check for initialization errors — missing API key is the most common cause.Tool call spans not appearing
Tool call spans not appearing
Make sure
tp.wrapToolCall receives the parentSpanId from the preceding wrapOpenAI call. A missing parentSpanId creates an orphaned span that may not render in the tree view.Cost shows $0.00 for all spans
Cost shows $0.00 for all spans
Cost tracking is based on the model string. Pass the exact OpenAI model name (
gpt-4o, gpt-4o-mini, gpt-3.5-turbo). Custom or fine-tuned model IDs are not mapped automatically.Next steps
Debug OpenAI agent infinite loops
Detect, trace, and replay runaway agent loops before they drain your budget.
Tracing tool calls
Instrument every tool, function, and external API your agent calls.
Time-travel debugging
Fork any span and rerun it with edited inputs — no redeployment.
Cost tracking
Monitor token spend per span and catch runaway costs early.