Skip to main content
TracePilot traces the OpenAI calls that LangChain makes under the hood. You don’t wrap LangChain itself — you intercept the openai.chat.completions.create call at the point where LangChain invokes it, using a custom LangChain callback or a thin wrapper around the OpenAI client. This gives you full span visibility without touching your chain or agent logic.

How the pattern works

LangChain calls OpenAI internally. TracePilot’s wrapOpenAI intercepts that call, captures inputs, outputs, tokens, and latency as a span, then returns the original result untouched. LangChain never knows TracePilot is there.
TracePilot wraps OpenAI calls — it does not wrap LangChain itself. Your chains, agents, and tools continue to work exactly as before.

Setup

1

Install dependencies

2

Create a traced OpenAI client

Extend the LangChain ChatOpenAI class to intercept completions calls before they reach OpenAI. Pass tp.wrapOpenAI as the call executor inside the _generate override.
3

Build your chain with the traced model

Use TracedChatOpenAI anywhere you’d use ChatOpenAI. Pass stepOrder to match LangChain’s chain step numbering so spans appear in the correct order in the dashboard.

Multi-step chains

When your chain has multiple LLM steps, pass stepOrder to each TracedChatOpenAI instance and use parentSpanId to link them into a tree.
Set stepOrder to match LangChain’s chain step index. This keeps spans in the correct sequence in the dashboard, making it easy to spot which step produced a bad output.

What you’ll see in the dashboard

Each wrapOpenAI call creates one span. For a two-step chain, you get a parent span for Step 1 and a child span for Step 2 nested beneath it. Click any span to inspect the exact messages sent to OpenAI, the response, token usage, latency, and cost.