🐛 Bug Report: OpenAI Responses API records no metrics (gen_ai.client.operation.duration, gen_ai.client.token.usage)

Đang mở
#4,585 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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.

  • #4596 của @zhaoruizhe81 — đang mở
  • #4697 của @doronkopit5 — đã đóng, không merge
  • #4713 của @doronkopit5 — đang mở

Đá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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của traceloop/openllmetry

Tất cả issue của traceloop/openllmetry

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.