Skip to content

openai: async with_streaming_response.parse() produces a span with no response data #624

Description

@sfc-gh-zeningchen

Describe your environment

OS: Rocky Linux 9.8
Python version: Python 3.14.7
Package version: opentelemetry-instrumentation-genai-openai 1.2b0.dev (main)
GenAI library (e.g. anthropic, openai) and version: openai 3.1.0

What happened?

AsyncAPIResponse.parse() is a coroutine, and it is the only response class
where that is true. RawResponseStreamProxy.parse() checks
isinstance(parsed, (Stream, AsyncStream)), so it rejects the coroutine, takes
its "not a stream we can drive" branch, and hands it back unwrapped. The caller
awaits an uninstrumented stream and no response telemetry is recorded.
Only the async client's with_streaming_response is affected; the sync client
and both with_raw_response paths return a stream synchronously and work.
This is the path the OpenAI Agents SDK takes for streamed runs
(agents/models/openai_responses.py resolves
responses.with_streaming_response.create, then awaits parse()), so every
Runner.run_streamed produces an empty chat span.

Steps to Reproduce

import asyncio
from openai import AsyncOpenAI
from opentelemetry.instrumentation.genai.openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument()
async def main():
    client = AsyncOpenAI()
    async with client.responses.with_streaming_response.create(
        model="gpt-4o-mini", input="Say this is a test.", stream=True
    ) as raw_response:
        async for _event in await raw_response.parse():
            pass
asyncio.run(main())

Then inspect the finished span. chat.completions.with_streaming_response
behaves the same.

Expected Result

The chat span carries the same response attributes as
responses.create(..., stream=True): gen_ai.output.messages,
gen_ai.usage.*, gen_ai.response.finish_reasons, gen_ai.response.id,
gen_ai.response.model.

Actual Result

None of them are set. The span carries request-side attributes only and ends
with status UNSET.

Additional context

No response

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions