-
Couldn't load subscription status.
- Fork 802
add OpenAI responses support #3901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
M-Hietala
wants to merge
12
commits into
open-telemetry:main
Choose a base branch
from
johanste:copilot/add-openai-responses-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add OpenAI responses support #3901
M-Hietala
wants to merge
12
commits into
open-telemetry:main
from
johanste:copilot/add-openai-responses-support
+3,741
−28
Conversation
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
Co-authored-by: johanste <[email protected]>
Co-authored-by: johanste <[email protected]>
Co-authored-by: johanste <[email protected]>
Co-authored-by: johanste <[email protected]>
…version) Co-authored-by: johanste <[email protected]>
….resources.chat.completions Co-authored-by: johanste <[email protected]>
…onversation_support updated responses and conversation support
|
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.
Summary
This PR adds instrumentation support for the OpenAI Responses API (structured outputs) to the
opentelemetry-instrumentation-openai-v2library, following the same monkeypatching pattern used for chat completions.Background
The OpenAI SDK introduced the Responses API (
client.responses.create) for structured outputs in version 1.66.0. This API was not previously instrumented, meaning calls to it would not generate telemetry data (spans, logs, or metrics).Changes
This PR instruments both synchronous and asynchronous versions of the Responses API:
Implementation Details
Version Checking:
_is_responses_api_supported()function to detect if OpenAI SDK >= 1.66.0packaging.versionfor reliable version comparisonNew wrapper functions in
patch.py:responses_create()- Wraps synchronousResponses.createmethodasync_responses_create()- Wraps asynchronousAsyncResponses.createmethod_set_responses_attributes()- Sets span attributes for responses_record_responses_metrics()- Records metrics for responses API callsInstrumentation hooks in
__init__.py:wrap_function_wrappercalls foropenai.resources.responses.responses.Responses.createwrap_function_wrappercalls foropenai.resources.responses.responses.AsyncResponses.createunwrapcalls in_uninstrument()methodTelemetry Captured
The instrumentation captures (when responses API is available):
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true)Tests
Added comprehensive test coverage with version-aware skipping:
test_responses.py- Tests for synchronous responses API with/without content capture (skipped if OpenAI < 1.66.0)test_async_responses.py- Tests for asynchronous responses API with/without content capture (skipped if OpenAI < 1.66.0)Documentation
Updated documentation to include responses API examples:
README.rst- Added usage example showing both chat completions and responses API__init__.py- Added responses API exampleBug Fixes
openai.types.chatinstead ofopenai.resources.chat.completionsTesting
Verified that:
Compatibility
Backward Compatibility
This implementation maintains full backward compatibility. Users with OpenAI SDK versions < 1.66.0 will continue to have chat completions instrumented while responses API instrumentation is gracefully skipped.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.