🐛 Bug Report: OpenAI Responses API records no metrics (gen_ai.client.operation.duration, gen_ai.client.token.usage)
Maintainer thường phản hồi trong vòng 1 ngày
@zhaoruizhe81 đang làm issue này rồi.
Từ ngày 10/10/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 70/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- observability
Hướng nghiên cứu
Start with the wrappers in opentelemetry/instrumentation/openai/v1/init.py (responses_get_or_create_wrapper and async_responses_get_or_create_wrapper) and with v1/responses_wrappers.py, then compare them with the Chat Completions path that already records gen_ai.client.operation.duration and gen_ai.client.token.usage. Run the reproduction script in the issue: it should show new gen_ai metric points for responses.create, sync and async, on success and on the InternalServerError path, with error.type set on failure. Streaming should record metrics too.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Which component is this bug for?
OpenAI Instrumentation
📜 Description
For Chat Completions, the OpenAI instrumentation records gen_ai.client.operation.duration and gen_ai.client.token.usage, including a duration point with error.type when the call fails. For the Responses API (client.responses.create), no metric is recorded at all, neither on success nor on failure. Spans are created normally.
In opentelemetry/instrumentation/openai/v1/__init__.py, the Responses wrappers (responses_get_or_create_wrapper, async_responses_get_or_create_wrapper) only receive the tracer, and v1/responses_wrappers.py never records to the duration or token histograms. So an application that moves from Chat Completions to the Responses API loses its latency and token-usage metrics without any warning.
gen_ai.client.operation.duration is a required metric in the OpenTelemetry GenAI semantic conventions, and gen_ai.client.token.usage is recommended whenever token counts are available. The Responses API returns them in usage, and the span already records them.
👟 Reproduction steps
pip install openai httpx opentelemetry-sdk opentelemetry-instrumentation-openai
import httpx, openai
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
from opentelemetry.sdk.trace import TracerProvider
def respond(request): # local stand-in for the OpenAI API
if request.url.path.endswith("/responses"):
return httpx.Response(200, json={
"id": "resp_1", "object": "response", "created_at": 0, "status": "completed", "model": "gpt-4o-mini",
"output": [{"type": "message", "id": "msg_1", "status": "completed", "role": "assistant",
"content": [{"type": "output_text", "text": "hi", "annotations": []}]}],
"parallel_tool_calls": True, "tool_choice": "auto", "tools": [],
"usage": {"input_tokens": 7, "output_tokens": 3, "total_tokens": 10,
"input_tokens_details": {"cached_tokens": 0}, "output_tokens_details": {"reasoning_tokens": 0}}})
return httpx.Response(200, json={
"id": "chatcmpl-1", "object": "chat.completion", "created": 0, "model": "gpt-4o-mini",
"choices": [{"index": 0, "message": {"role": "assistant", "content": "hi"}, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 7, "completion_tokens": 3, "total_tokens": 10}})
reader = InMemoryMetricReader()
OpenAIInstrumentor().instrument(tracer_provider=TracerProvider(),
meter_provider=MeterProvider(metric_readers=[reader]))
client = openai.OpenAI(api_key="x", max_retries=0,
http_client=httpx.Client(transport=httpx.MockTransport(respond)))
def gen_ai_points():
data = reader.get_metrics_data()
return sum(p.count for rm in (data.resource_metrics if data else []) for sm in rm.scope_metrics
for m in sm.metrics if m.name.startswith("gen_ai.client.") for p in m.data.data_points)
before = gen_ai_points()
client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": "hello"}])
print("chat.completions.create: new gen_ai metric points =", gen_ai_points() - before)
before = gen_ai_points()
client.responses.create(model="gpt-4o-mini", input="hello")
print("responses.create: new gen_ai metric points =", gen_ai_points() - before)
👍 Expected behavior
responses.create (sync and async, streaming and non-streaming) records gen_ai.client.operation.duration for every call, with error.type when the call fails, and gen_ai.client.token.usage (input and output) from response.usage, as Chat Completions does.
👎 Actual Behavior with Screenshots
chat.completions.create ok new metric points: gen_ai.client.token.usage (output) +1, gen_ai.client.token.usage (input) +1, gen_ai.client.operation.duration +1
responses.create ok new metric points: NONE
chat.completions.create InternalServerError new metric points: gen_ai.client.operation.duration (error.type=InternalServerError) +1
responses.create InternalServerError new metric points: NONE
🤖 Python Version
3.12
📃 Provide any additional context for the Bug.
opentelemetry-instrumentation-openai 0.62.4 (also main at df4921a), openai 2.54.0.
👀 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?
None
- Ngôn ngữ chính
- Python
- Star
- 7.5k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của traceloop/openllmetry
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returnsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationCó thể đã có người làm @Quantum-Enigma-dot đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4665 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsCó thể đã có người làm @jayfeng7 đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
traceloop/openllmetry#4660 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Report: Failed dataset deletes still remove local rows and columnsCó thể đã có người làm @inchang-ing đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
traceloop/openllmetry#4630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyCó thể đã có người làm @shantam77 đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
traceloop/openllmetry#4598 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của traceloop/openllmetry
Issue tương tự
-
CI flake: test-windows times out spawning Node in tests/test_antigravity_node_hooks.py (develop red)Đang mởarea/ci P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
benchmark
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
mozilla-ai/cq#601 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump Python to 3.14 or 3.15Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày