> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK traces

> Send OpenAI Agents SDK (TypeScript) traces to EvalGate with a trace processor.

# OpenAI Agents SDK traces

`@evalgate/sdk/integrations/openai-agents` provides a trace processor for the
[OpenAI Agents SDK](https://openai.github.io/openai-agents-js/guides/tracing/)
in TypeScript. Register it with `addTraceProcessor`, which keeps the SDK's
default exporter to OpenAI and adds EvalGate next to it.

```ts theme={null} theme={null}
import { addTraceProcessor } from "@openai/agents";
import { EvalGateAgentsProcessor } from "@evalgate/sdk/integrations/openai-agents";

addTraceProcessor(
  new EvalGateAgentsProcessor({ apiKey: process.env.EVALGATE_API_KEY }),
);
```

`setTraceProcessors` replaces the default processors, so traces would no
longer reach OpenAI unless you include its processor yourself.

## What is sent

The processor buffers the spans of a trace and sends them to
`/api/otel/v1/traces` when the trace ends. It sends:

| Span | Attributes |
| - | - |
| Agent | `gen_ai.operation.name` `invoke_agent`, `gen_ai.agent.name` |
| Generation | `gen_ai.operation.name` `chat`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |
| Response (Responses API) | `gen_ai.operation.name` `chat`, `gen_ai.response.model` and token counts, read only from the response's `model` and `usage` when tracing includes data |
| Function | `gen_ai.operation.name` `execute_tool`, `gen_ai.tool.name` |
| Handoff, guardrail, turn | Agent names, guardrail name and whether it triggered, turn token counts |

Span timing, parent links and an error status are kept. Model inputs and
outputs, tool arguments and results, response bodies and error messages are
never sent. A token count the SDK did not report is left out, not sent as
zero. Turn token counts are sent as GenAI usage only when no model span in the
batch reports usage, so tokens are never counted twice.

## Options

| Option | Default | Meaning |
| - | - | - |
| `apiKey` | `EVALGATE_API_KEY` | EvalGate key with `traces:write` |
| `baseUrl` | `EVALGATE_BASE_URL` or `https://www.evalgate.com` | EvalGate base URL |
| `serviceName` | `evalgate-app` | `service.name` on the trace |
| `onError` | ignore | Called when a send fails; the agent run is never affected |

## Status

Tested against the `TracingProcessor` interface of `@openai/agents-core`
0.22.0 with fixture spans. No live run has been recorded yet, so the adapter
is `fixture_qualified` in [Integration adapters](/docs/guides/integration-adapters.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.