🐛 Bug Report: openai-agents records every model call as two LLM spans (calls and tokens doubled)
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- observability, testing
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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!
- 主要语言
- Python
- 星标
- 7.5k
- 派生
- 1.2k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
traceloop/openllmetry 的其他 Issue
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returns可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug python
难度 2/5 1-3 小时 新手友好度 76/100
traceloop/openllmetry#4717 ·
维护者通常 1 天内回复
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentation可能已有人在做 @Quantum-Enigma-dot 于 21 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
traceloop/openllmetry#4665 · 1 条评论 ·
维护者通常 1 天内回复
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completions可能已有人在做 @jayfeng7 于 23 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
traceloop/openllmetry#4660 · 1 条评论 ·
维护者通常 1 天内回复
-
Bug Report: Failed dataset deletes still remove local rows and columns可能已有人在做 @inchang-ing 于 32 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
traceloop/openllmetry#4630 ·
维护者通常 1 天内回复
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penalty可能已有人在做 @shantam77 于 38 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
traceloop/openllmetry#4598 · 2 条评论 ·
维护者通常 1 天内回复
查看 traceloop/openllmetry 的全部 Issue
相似的 Issue
-
Layout accepts a step threshold of 0 or less, then in-toto-verify crashes with StopIteration可能已有人在做 @BahaaMattar 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
needs discussion
难度 2/5 1-3 小时 新手友好度 78/100
openfga/openfga.dev#1436 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
usb-device-hid: MouseInterface reports bInterfaceProtocol 1 (keyboard) instead of 2可能已有人在做 @Duhan07 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
micropython/micropython-lib#1176 ·