feat(openai): OpenAI responses minimal instrumentation#3052
feat(openai): OpenAI responses minimal instrumentation#3052nirga merged 8 commits intotraceloop:mainfrom
Conversation
548b547 to
8ffd459
Compare
8ffd459 to
12165b7
Compare
There was a problem hiding this comment.
Caution
Changes requested ❌
Reviewed everything up to 5714d08 in 1 minute and 34 seconds. Click for details.
- Reviewed
1289lines of code in6files - Skipped
0files when reviewing. - Skipped posting
2draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/__init__.py:303
- Draft comment:
The _try_wrap calls for 'Responses.create' and 'Responses.retrieve' both use the same wrapper (responses_get_or_create_wrapper). Ensure this is intentional since these methods could potentially require different instrumentation logic. Consider adding a comment to document the rationale. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% This comment violates several rules. It's asking for confirmation of intention ("Ensure this is intentional") and requesting documentation. It's speculative ("could potentially require different instrumentation logic"). Without seeing the implementation of responses_get_or_create_wrapper, we can't know if this is actually an issue. The author likely had a good reason for using the same wrapper. Maybe there really is a bug here and these operations should be handled differently? The shared wrapper name is unusual. Even if there was a bug, asking for confirmation isn't helpful - the comment should point out the specific issue. The shared wrapper could be intentional if these operations are similar enough to share instrumentation logic. This comment should be deleted as it's primarily asking for confirmation and documentation rather than pointing out a clear issue that needs to be fixed.
2. packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py:446
- Draft comment:
The code uses the dictionary merge operator (|) to combine output_blocks from the parsed response and existing data. This requires Python 3.9 or later; ensure that this version requirement is documented and acceptable for the project. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%The comment is informative and suggests ensuring documentation of a version requirement, which is not allowed by the rules. It doesn't provide a specific code suggestion or ask for a test to be written.
Workflow ID: wflow_TgkmsYc5QmFqJGlM
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
...lemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py
Show resolved
Hide resolved
| response_model: Optional[str] = pydantic.Field(default=None) | ||
|
|
||
|
|
||
| responses: dict[str, TracedData] = {} |
There was a problem hiding this comment.
The module uses a global 'responses' dictionary to store traced data. In a multi-threaded or async environment, this could potentially lead to race conditions. Consider using a thread-safe or async-safe data structure, or document why this is acceptable in your use case.
nirga
left a comment
There was a problem hiding this comment.
Thanks @dinmukhamedm! Left a small nit
packages/opentelemetry-instrumentation-openai/tests/traces/test_responses.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Bug: Tracer API Parameter Errors
The tracer.start_span() calls within responses_cancel_wrapper and async_responses_cancel_wrapper contain two bugs:
- They incorrectly pass
record_exception=True, a parameter not supported by the OpenTelemetry Tracer API, which will cause aTypeError. Exceptions are already correctly recorded viaspan.record_exception(). - The
start_timeparameter is passed as a float (existing_data.start_time) instead of being converted to an integer (nanoseconds), which is inconsistent with otherstart_spancalls and may lead to aTypeErroror incorrect span timing.
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py#L581-L587
Bug: Sync/Async Wrapper Default Value Mismatch
The responses_get_or_create_wrapper (sync) and async_responses_get_or_create_wrapper (async) functions have inconsistent default value handling within their exception blocks.
Specifically:
instructions: The async version defaults to an empty string (""), while the sync version does not (resulting inNone).output_textandrequest_model: The sync version defaults to"", while the async version does not (resulting inNone).response_model: The sync version usesparsed_response.modelas a fallback, whereas the async version does not (resulting inNone).
This inconsistency can lead to different TracedData object creation and potential TypeError when None values are passed where strings are expected.
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py#L495-L511
BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
Co-authored-by: Nir Gazit <nirga@users.noreply.github.com>
Co-authored-by: Nir Gazit <nirga@users.noreply.github.com>
This is a basic instrumentation of OpenAI responses, supporting the following:
Things NOT supported, but that would be great to add:
feat(instrumentation): ...orfix(instrumentation): ....Important
Add instrumentation for OpenAI responses, including text inputs/outputs, tool calls, and async operations, with tests for verification.
responses_wrappers.py, handling text inputs/outputs, tool calls, and async operations.__init__.pyto integrate new response wrappers for synchronous and asynchronous operations.test_responses.pyto test response creation, input history, and tool calls.test_responses.yaml,test_responses_tool_calls.yaml, andtest_responses_with_input_history.yaml.This description was created by
for 5714d08. You can customize this summary. It will automatically update as commits are pushed.