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

Open
#4,585 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@zhaoruizhe81 is already working on this.

Since Oct 10, 2026.

  • #4596 by @zhaoruizhe81 — open
  • #4697 by @doronkopit5 — closed without merging
  • #4713 by @doronkopit5 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
observability

Research direction

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.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
7.5k
Forks
1.2k
Avg merge
2d 6h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from traceloop/openllmetry

All issues in traceloop/openllmetry

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.