Trace OpenAI Agents SDK runs from your TypeScript application.The auto-instrumentation example uses plain JavaScript so If you omit
Setup
Install the Braintrust and OpenAI Agents SDKs, then set your API keys.1
Install packages
2
Set environment variables
.env
Auto-instrumentation
To trace OpenAI Agents SDK runs without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook. The hook wires Braintrust’s trace processor into the OpenAI Agents SDK automatically, so you don’t need to install@braintrust/openai-agents or register a processor yourself. Requires @openai/agents v0.0.14 or later.1
Initialize Braintrust and run an agent
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.If you’re using a bundler, see Trace LLM calls for plugin and loader setup.
Manual instrumentation
To instrument OpenAI Agents SDK runs manually, add Braintrust’sOpenAIAgentsTraceProcessor yourself.logger, the processor uses the current Braintrust span, experiment, or logger when one is active.What Braintrust traces
Braintrust captures:- Run spans (the root trace span, named after the workflow), with the run’s first input, final output, and trace group and metadata.
- Agent spans (named after each agent), with the agent’s tools, handoffs, and output type.
- Model spans (
GenerationandResponse), with request input, response output, model and configuration details, token usage, and time to first token. - Tool call spans (named after the function), with the tool’s input and output.
- Guardrail spans (named after the guardrail), with whether the guardrail triggered.
- Handoff spans (
Handoff), with the source and destination agents. - MCP tool-listing spans (
MCP List ToolsorList Tools (<server>)), with the server and the tools it exposes. - Speech and transcription spans (
SpeechandTranscription) for voice agents, with their input, output, and model configuration, plus speech group spans (Speech Group) with their input. - Custom spans (named by you), with any data you attach.
- Token usage metrics on model spans (prompt, completion, and total tokens), including cached token counts when the model reports them.
- Base64 image inputs and generated images as Braintrust attachments.
- Errors on any span that fails.
- Parent-child nesting when you run the agent inside an existing Braintrust span.