tp.wrapOpenAI for any call to OpenAI’s chat completions API, and tp.wrapToolCall for any other async operation you want to trace — web searches, database queries, external API calls, file reads, or anything else. This works with AutoGen, custom agent loops, event-driven systems, or any orchestration pattern you’ve built.
Core pattern
Every wrapped call returns{ result, spanId }. Pass spanId as parentSpanId to subsequent calls to build a parent-child span tree in the dashboard. The result is the original return value, unchanged.
Patterns
- Sequential steps
- Parallel steps
- Nested tool calls
Each step passes its
spanId as parentSpanId for the next step, creating a chain of linked spans.AutoGen compatibility
AutoGen uses async function calls internally. Wrap at the same level — intercept the OpenAI call inside your AutoGen agent’s reply function, or wrap the tool functions your agent registers.AutoGen support is available for any async call pattern. If AutoGen exposes a custom reply function hook in your version, use
tracedReplyFunction there. Refer to your AutoGen version’s docs for the exact hook name.Building a custom orchestration loop
If you’re running your own agent loop, wrap every call inside the loop body and threadspanId values forward.