feat: add instrumentation around openai responses stream method.#131
Open
eternalcuriouslearner wants to merge 6 commits into
Conversation
- Introduced new YAML cassettes for streaming responses and user exceptions. - Implemented a conformance scenario for the OpenAI Responses API stream. - Enhanced existing tests to cover streaming behavior, including connection errors and user exceptions. - Updated response wrappers to handle enter errors and ensure proper exception propagation. - Added tests to validate the streaming manager's behavior and content capture. - Adjusted test configurations to support the latest experimental semantic conventions.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds instrumentation and conformance/test coverage for the OpenAI Responses API stream() manager, ensuring spans/metrics are emitted once (without double-instrumenting the internal create(stream=True) call).
Changes:
- Instrument
Responses.stream/AsyncResponses.streamand introduce aContextVarmarker to prevent double invocations whenstream()calls intocreate(stream=True). - Add new sync/async tests + VCR cassettes for
Responses.streambehaviors (content capture, error paths, user exceptions). - Add a new conformance scenario for streaming responses.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/response_wrappers.py | Adds ContextVar-based coordination and improves manager wrapper error handling to avoid double wrapping/invocation. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py | Adds wrappers for Responses.stream / AsyncResponses.stream and updates create wrappers to detect stream-manager context. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/init.py | Registers new wrappers for stream methods and updates uninstrumentation. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py | Adds sync Responses.stream tests + skip logic for SDKs without .stream; adjusts one token limit. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py | Adds async AsyncResponses.stream tests + skip logic for SDKs without .stream. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_response_wrappers.py | Updates unit tests for manager wrappers (enter failures, manager exit failures) and new invocation_factory contract. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_conformance.py | Registers a new streaming conformance scenario. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/conformance/responses_stream.py | New conformance scenario that exercises OpenAI().responses.stream(...).until_done(). |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/cassettes/* | Adds VCR recordings for new stream tests and streaming conformance scenario. |
…nses-stream-method
…nses-stream-method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Instrumentation around sync and async
responses.streammethodFixes # (issue)
Type of change
Please delete options that are not relevant.
How has this been tested?
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.