🐛 Bug Report: openai-agents records every model call as two LLM spans (calls and tokens doubled)

Aperta
#4,609 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Jennycruzy ci sta già lavorando.

Dal 11/10/2026.

  • #4610 di @Jennycruzy — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Read the open PR linked to this issue and inspect the OpenAI Agents _hooks.py processor and responses_wrappers.py wrappers. Start by reproducing the span and token counts with the offline httpx.MockTransport example, then check the existing suppression handling in the chat, completion, embedding, and image wrappers. Done means one LLM span per non-streamed model call with the provider's token counts, including the listed failure and turn-limit cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Which component is this bug for?

OpenAI Agents Instrumentation (with the OpenAI instrumentation, as Traceloop.init() enables both by default)

📜 Description

With the default Traceloop.init(), every non-streamed model call made through the OpenAI Agents SDK is recorded as two LLM spans: one from the openai-agents processor and one from the OpenAI Responses wrapper. Call counts, latency and token usage in a dashboard are doubled.

Cause: the openai-agents processor does not set SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY while its generation/response span is open, and the Responses wrappers (responses_get_or_create_wrapper and its async twin) do not check that key. The chat, completion, embedding and image wrappers already check it.

👟 Reproduction steps

Standalone, offline (httpx.MockTransport), no API key:

"""OpenLLMetry + OpenAI Agents SDK: one model call is recorded as two LLM spans.
Needs traceloop-sdk and openai-agents. Offline: httpx.MockTransport answers. Leave OPENAI_API_KEY
unset so the Agents SDK's own exporter skips its upload."""
import asyncio

import httpx
from openai import AsyncOpenAI
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from traceloop.sdk import Traceloop

exporter = InMemorySpanExporter()
Traceloop.init(app_name="repro", exporter=exporter, disable_batch=True, telemetry_enabled=False)
from agents import Agent, OpenAIResponsesModel, Runner  # noqa: E402

BODY = {"id": "resp_1", "object": "response", "created_at": 0, "status": "completed", "model": "m",
        "output": [{"type": "message", "id": "msg_1", "role": "assistant", "status": "completed",
                    "content": [{"type": "output_text", "text": "Hello!", "annotations": []}]}],
        "parallel_tool_calls": True, "tool_choice": "auto", "tools": [],
        "usage": {"input_tokens": 11, "output_tokens": 7, "total_tokens": 18,
                  "input_tokens_details": {"cached_tokens": 0}, "output_tokens_details": {"reasoning_tokens": 0}}}
transport = httpx.MockTransport(lambda request: httpx.Response(200, json=BODY))
client = AsyncOpenAI(api_key="x", base_url="http://fake/v1", http_client=httpx.AsyncClient(transport=transport))
agent = Agent(name="helper", model=OpenAIResponsesModel("m", client))
asyncio.run(Runner.run(agent, "hi"))
llm = [s for s in exporter.get_finished_spans() if s.attributes.get("gen_ai.operation.name") == "chat"]
tokens = sum(s.attributes.get("gen_ai.usage.output_tokens", 0) for s in llm)
print(f"provider requests: 1; LLM spans: {len(llm)}; output tokens on LLM spans: {tokens} (provider sent 7)")
👍 Expected behavior

One LLM span per model call, with the tokens the provider sent (7).

👎 Actual Behavior with Screenshots
provider requests: 1; LLM spans: 2; output tokens on LLM spans: 14 (provider sent 7)

Cases checked (offline fake provider, LLM spans vs real provider requests):

case provider requests LLM spans today
plain agent run with one tool call 2 4
run whose tool raises 2 4
run whose model call fails 2 4
run that hits max_turns 3 6
model calls a tool that does not exist 1 2
streamed runs n n (correct)
🤖 Python Version

3.12

📃 Provide any additional context for the Bug.

traceloop-sdk 0.62.4, opentelemetry-instrumentation-openai-agents 0.62.4, openai-agents 0.23.1, openai 3.28.0. Still the same on main (17d0c5a) and with every open PR that touches _hooks.py or responses_wrappers.py (12 tested). #4060 mentions "double-instrumentation artifacts from two spans per LLM call" in passing; I could not find an issue for it.

I found this with Trueup, an AI agent I am building that runs instrumented apps against a fake provider and compares what really happened with what the trace says. The cases, the repro and the fix in the linked PR were produced by it.

👀 Have you spent some time to check if this bug has been raised before?
  • I checked and didn't find similar issue
Are you willing to submit PR?

Yes I am willing to submit a PR!

Lingua principale
Python
Stelle
7.5k
Fork
1.2k
Merge medio
2g 6h
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di traceloop/openllmetry

Tutte le issue di traceloop/openllmetry

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.