Skip to main content
Send traces from openai-agents-python to Tessary and tag each Runner.run() call with a call site. The SDK’s built-in tracing sends to the OpenAI dashboard rather than to OpenTelemetry, so you open one span by hand around Runner.run() and fill in its attributes from the RunResult the call returns.

Prerequisites

  • A running Tessary instance, with the Endpoint and Bearer Token from its connect gate. See Instrument your agent.
  • OPENAI_API_KEY set in the environment.
  • Python 3.10 or later, with openai-agents, opentelemetry-sdk, and opentelemetry-exporter-otlp-proto-http installed.

Add the exporter

Tessary receives spans over OTLP (OpenTelemetry Protocol). Point the exporter at your Tessary instance with environment variables:
Replace the host with your Tessary origin and <token> with the Bearer Token value from the connect gate. Then register an exporter that reads those variables. OTLPSpanExporter() with no arguments picks them up:
If your application already configures a TracerProvider, skip this block. Add the Tessary exporter to the existing provider as described in Configure an exporter, and use its tracer. A span opened on a second provider that has no Tessary exporter is never sent.

Tag the Runner.run() call

Each Runner.run() call is one call site. The call-site tag explains what counts as a call site and the rules for the id. Open a span around Runner.run(), set tessary.call_site.id as a literal, and fill in the fields Span requirements marks required. Set the request fields before the call, then read the output and token usage off the returned RunResult:
context_wrapper.usage totals the tokens for every model request in the run, so the span reports the whole run’s usage. OpenAI counts cached tokens inside input_tokens and reports them again under input_tokens_details.cached_tokens. Set the cache attribute too, or Tessary prices cached input as full-price input.
Keep tessary.call_site.id a literal string, never an f-string or a variable. The call-site tag explains why: a computed value cannot be traced back to the code that produced it.

Verify it works

Run the example. It prints the agent’s reply. Your text will differ:
The connect gate opens once the tagged span arrives, with 1 trace and the support.answer call site. On a project already past the gate, the call site appears in the project instead. If a span arrives without the tag, What done looks like describes the states you see instead.

The call-site tag

What counts as a call site, and the four non-negotiable rules for the id.

Span requirements

Every field Tessary reads off a span, beyond what this page sets.

Configure an exporter

The in-code and collector forms, and how to add Tessary to an exporter setup you already run.