Implement OpenAI Responses API instrumentation and examples#4166
Open
vasantteja wants to merge 6 commits intoopen-telemetry:mainfrom
Open
Implement OpenAI Responses API instrumentation and examples#4166vasantteja wants to merge 6 commits intoopen-telemetry:mainfrom
vasantteja wants to merge 6 commits intoopen-telemetry:mainfrom
Conversation
- Added instrumentation for the OpenAI Responses API, including tracing for `Responses.create` and `Responses.stream` methods. - Introduced example scripts demonstrating the usage of the Responses API with OpenTelemetry. - Created a `.env` file for configuration, including API keys and OpenTelemetry settings. - Updated README files to include instructions for running examples and configuring the environment. - Added unit tests for the new Responses API functionality, ensuring proper tracing and metrics collection. This update enhances the observability of OpenAI API interactions within the OpenTelemetry framework.
- Updated the OpenAIInstrumentor to conditionally wrap and unwrap the Responses API methods based on the installed OpenAI package version (>=1.66.0). - Added version checks in the test suite to skip tests if the Responses API is not available, ensuring compatibility with earlier versions of the OpenAI library. - Improved error handling for missing API methods to prevent runtime exceptions.
- Added pylint disable comments to suppress warnings for specific lines in the Responses API example and patch files. - Updated the `responses_create` and `responses_stream` methods with links to relevant OpenAI documentation for better reference. - Improved code formatting for readability by adjusting line breaks and indentation in the patch file.
- Reformatted code in the patch file to enhance readability by adjusting line breaks and indentation. - Ensured consistent style for model retrieval and span name updates in the ResponseStreamWrapper class. - Minor adjustments to import statements for clarity and organization.
- Updated the OpenAI package version in requirements.txt to 1.66.0 for compatibility. - Refactored span name retrieval in the patch.py file to directly format the span name using operation and model attributes, removing the redundant _get_span_name function. - Improved code clarity and consistency in the responses_create and responses_stream methods.
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
This PR adds OpenAI Responses API instrumentation (sync Responses.create and Responses.stream) to opentelemetry-instrumentation-openai-v2, including streaming span lifecycle handling, token metrics,
and request/response attributes. It also adds tests for Responses API behavior and updates docs/examples to show Responses usage.
Motivation: the Responses API is now a primary OpenAI interface; instrumentation should cover it just like chat completions and embeddings.
Dependencies: OpenAI SDK with Responses support (e.g., openai>=1.57.3) and jiter for streaming.
Fixes # (3436)
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. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.