-
Notifications
You must be signed in to change notification settings - Fork 70
feat(genai-openai): instrument Responses.parse and AsyncResponses.parse #786
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
RichardoMrMu
wants to merge
18
commits into
open-telemetry:main
Choose a base branch
from
RichardoMrMu:responses-parse-instrumentation
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d211c6b
feat(genai-openai): instrument Responses.parse and AsyncResponses.par…
RichardoMrMu dbb1281
test(genai-openai): cover Responses.parse instrumentation (#659)
RichardoMrMu cc44c8c
test(genai-openai): cover AsyncResponses.parse instrumentation (#659)
RichardoMrMu f97acb5
fix(openai): point Responses.parse test at its own cassette (#786)
RichardoMrMu 4864c66
fix(openai): point AsyncResponses.parse test at its own cassette (#786)
RichardoMrMu 9008412
test(openai): add Responses.parse cassette with structured JSON body …
RichardoMrMu 404936f
test(openai): add AsyncResponses.parse cassette with structured JSON …
RichardoMrMu f689b5c
docs: regenerate instrumentation README (tox -e generate) (#786)
RichardoMrMu 5bfb4d9
chore(openai): add changelog fragment for Responses.parse (#786)
RichardoMrMu f721a08
fix(openai): point Responses.parse test at its own cassette (#786)
RichardoMrMu bdd4a28
fix(openai): point AsyncResponses.parse test at its own cassette (#786)
RichardoMrMu 831db95
test(openai): add Responses.parse cassette with structured JSON body …
RichardoMrMu be38cc7
test(openai): add AsyncResponses.parse cassette with structured JSON …
RichardoMrMu 05d2550
docs: regenerate instrumentation README (tox -e generate) (#786)
RichardoMrMu 070e951
chore(openai): add changelog fragment for Responses.parse (#786)
RichardoMrMu 72714f0
fix(genai-openai): map Responses.parse text_format to gen_ai.output.type
RichardoMrMu a64381d
test(genai-openai): assert gen_ai.output.type for Responses.parse and…
RichardoMrMu 3982601
test(genai-openai): restore Responses test file content lost to a bad…
RichardoMrMu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/786.added
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Instrument `Responses.parse` and `AsyncResponses.parse`, so structured-output calls emit GenAI spans like `Responses.create`, reporting `gen_ai.output.type` as `json` for the `text_format` argument. |
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
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
143 changes: 143 additions & 0 deletions
143
...ntation-genai-openai/tests/cassettes/test_async_responses_parse_basic[content_mode0].yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| interactions: | ||
| - request: | ||
| body: |- | ||
| { | ||
| "input": "Say this is a test", | ||
| "instructions": "You are a helpful assistant.", | ||
| "model": "gpt-4o-mini", | ||
| "stream": false, | ||
| "text": { | ||
| "format": { | ||
| "type": "json_schema", | ||
| "name": "_AsyncParseCalendarEvent", | ||
| "strict": true, | ||
| "schema": { | ||
| "properties": { | ||
| "name": { | ||
| "title": "Name", | ||
| "type": "string" | ||
| }, | ||
| "date": { | ||
| "title": "Date", | ||
| "type": "string" | ||
| }, | ||
| "participants": { | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "title": "Participants", | ||
| "type": "array" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name", | ||
| "date", | ||
| "participants" | ||
| ], | ||
| "title": "_AsyncParseCalendarEvent", | ||
| "type": "object", | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| headers: | ||
| Accept: | ||
| - application/json | ||
| Accept-Encoding: | ||
| - gzip, deflate | ||
| Connection: | ||
| - keep-alive | ||
| Content-Type: | ||
| - application/json | ||
| Host: | ||
| - api.openai.com | ||
| User-Agent: | ||
| - OpenAI/Python 1.109.1 | ||
| authorization: | ||
| - Bearer test_openai_api_key | ||
| method: POST | ||
| uri: https://api.openai.com/v1/responses | ||
| response: | ||
| body: | ||
| string: |- | ||
| { | ||
| "id": "resp_0f4faba17dcd0f1e0069e2f3e4907881909179832ba1237100", | ||
| "object": "response", | ||
| "created_at": 1776481253, | ||
| "status": "completed", | ||
| "background": false, | ||
| "error": null, | ||
| "frequency_penalty": 0.0, | ||
| "incomplete_details": null, | ||
| "instructions": "You are a helpful assistant.", | ||
| "max_output_tokens": null, | ||
| "max_tool_calls": null, | ||
| "model": "gpt-4o-mini-2024-07-18", | ||
| "output": [ | ||
| { | ||
| "id": "msg_0f4faba17dcd0f1e0069e2f3e7b2b88190bff23981628ac400", | ||
| "type": "message", | ||
| "status": "completed", | ||
| "content": [ | ||
| { | ||
| "type": "output_text", | ||
| "annotations": [], | ||
| "logprobs": [], | ||
| "text": "{\"name\":\"science fair\",\"date\":\"Friday\",\"participants\":[\"Alice\",\"Bob\"]}" | ||
| } | ||
| ], | ||
| "role": "assistant" | ||
| } | ||
| ], | ||
| "parallel_tool_calls": true, | ||
| "presence_penalty": 0.0, | ||
| "previous_response_id": null, | ||
| "reasoning": { | ||
| "effort": null, | ||
| "summary": null | ||
| }, | ||
| "safety_identifier": null, | ||
| "service_tier": "default", | ||
| "store": true, | ||
| "temperature": 1.0, | ||
| "text": { | ||
| "format": { | ||
| "type": "json_schema", | ||
| "name": "_AsyncParseCalendarEvent" | ||
| }, | ||
| "verbosity": "medium" | ||
| }, | ||
| "tool_choice": "auto", | ||
| "tools": [], | ||
| "top_logprobs": 0, | ||
| "top_p": 1.0, | ||
| "truncation": "disabled", | ||
| "usage": { | ||
| "input_tokens": 22, | ||
| "input_tokens_details": { | ||
| "cached_tokens": 0 | ||
| }, | ||
| "output_tokens": 6, | ||
| "output_tokens_details": { | ||
| "reasoning_tokens": 0 | ||
| }, | ||
| "total_tokens": 28 | ||
| }, | ||
| "user": null, | ||
| "metadata": {} | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| openai-organization: test_openai_org_id | ||
| openai-project: | ||
| - test_openai_project_id | ||
| openai-version: | ||
| - '2020-10-01' | ||
| set-cookie: | ||
| - test_set_cookie | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is covered in the latest version of the PR.
extract_params()now acceptstext_formatandresponse_extractors._extract_output_type_from_text_format()maps a Pydantic/dataclass type (whatResponses.parse(text_format=...)receives) togen_ai.output.type=json, mirroring thechat.completions.parsepath. The mapping is asserted by both parse tests via_assert_request_attrs(span, output_type="json"), andtest_responses_create_output_type_unchanged_by_parsekeeps a plaincreate()(notext_format) from spuriously recording an output type.