🐛 Bug Report: openai-agents records every model call as two LLM spans (calls and tokens doubled)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- observability, testing
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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!
- Lenguaje dominante
- Python
- Estrellas
- 7.5k
- Forks
- 1.2k
- Merge medio
- 1 d 23 h
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de traceloop/openllmetry
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returnsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationPosiblemente ocupada @Quantum-Enigma-dot la tomó hace 21 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4665 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsPosiblemente ocupada @jayfeng7 la tomó hace 23 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
traceloop/openllmetry#4660 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Bug Report: Failed dataset deletes still remove local rows and columnsPosiblemente ocupada @inchang-ing la tomó hace 32 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
traceloop/openllmetry#4630 ·
Los mantenedores suelen responder en 1 día
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyPosiblemente ocupada @shantam77 la tomó hace 38 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
traceloop/openllmetry#4598 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de traceloop/openllmetry
Issues similares
-
CI flake: test-windows times out spawning Node in tests/test_antigravity_node_hooks.py (develop red)Abiertoarea/ci P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
benchmark
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
mozilla-ai/cq#601 ·
Los mantenedores suelen responder en 1 día
-
Bump Python to 3.14 or 3.15Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día