Skip to content

Capture OpenAI multimodal image content (image_url and Responses API input_image) as BlobPart, UriPart, or FilePart message parts - #540

Merged
lmolkova merged 9 commits into
open-telemetry:mainfrom
rads-1996:multimodal-openai-changes
Sep 9, 2026
Merged

lmolkova merged 9 commits into
open-telemetry:mainfrom
rads-1996:multimodal-openai-changes

Conversation

@rads-1996

Copy link
Copy Markdown
Contributor

Description

Fixes # (#348)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.

  • uv run tox -e py312-test-instrumentation-genai-langchain -- -q
  • uv run tox -e py312-test-instrumentation-genai-langchain-conformance -- -q
  • uv run --python 3.12 tox -e lint-instrumentation-genai-langchain

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-10 17:14 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@rads-1996
rads-1996 force-pushed the multimodal-openai-changes branch 2 times, most recently from 5698089 to 8564fb8 Compare September 2, 2026 20:21
@rads-1996
rads-1996 marked this pull request as ready for review September 2, 2026 22:57
@rads-1996
rads-1996 requested a review from a team as a code owner September 2, 2026 22:57
Copilot AI lite review requested due to automatic review settings September 2, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

_content_to_parts() currently drops image_url values when they are objects with a .url attribute (only dict-mappings are handled), which can silently miss image parts for SDK-model style inputs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds multimodal (image) input capture to the OpenAI GenAI instrumentation by converting OpenAI image_url (Chat Completions) and input_image (Responses API) content blocks into structured MessagePart instances (BlobPart, UriPart, FilePart) so they can be emitted via the existing GenAI message content model.

Changes:

  • Introduces _content_to_parts() to parse mixed text/image content blocks into MessagePart lists and wires it into input-message extraction paths.
  • Expands unit and conformance coverage for multimodal image inputs, including new conformance scenarios and VCR cassettes.
  • Adds a towncrier changelog fragment documenting the new capability.
File summaries
File Description
instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/utils.py Adds _content_to_parts() and uses it when preparing input messages to capture text + image parts.
instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/response_extractors.py Reuses _content_to_parts() for Responses API input-message extraction (supports images + file IDs).
instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py Adds focused unit tests for _content_to_parts() across text, URL images, and data-URL images.
instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_response_extractors.py Updates/extends extraction tests to assert UriPart/BlobPart/FilePart results for multimodal inputs.
instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_conformance.py Registers new multimodal scenarios in the conformance suite.
instrumentation/opentelemetry-instrumentation-genai-openai/tests/conformance/multimodal.py Adds new conformance scenarios validating that an image blob part appears on input messages.
instrumentation/opentelemetry-instrumentation-genai-openai/tests/cassettes/chat_completions_multimodal_conformance.yaml VCR cassette for Chat Completions multimodal conformance scenario.
instrumentation/opentelemetry-instrumentation-genai-openai/tests/cassettes/responses_multimodal_conformance.yaml VCR cassette for Responses API multimodal conformance scenario.
instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/540.added Changelog fragment for the new multimodal capture behavior.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work for streaming? Do we have any test coverage for streaming / async multi-modal content?

@rads-1996
rads-1996 force-pushed the multimodal-openai-changes branch from e9af0ca to 35db213 Compare September 4, 2026 19:18
@rads-1996

Copy link
Copy Markdown
Contributor Author

Would this work for streaming? Do we have any test coverage for streaming / async multi-modal content?

Yes, this would work for streaming. I had missed adding the test coverage for it earlier. Added it now. Thanks for pointing it out.

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! It seems there is a regression my AI bot found, can you please check ?

@rads-1996
rads-1996 force-pushed the multimodal-openai-changes branch from 35db213 to 7c5fbb8 Compare September 9, 2026 15:42
@rads-1996
rads-1996 requested a review from lmolkova September 9, 2026 16:32
@lmolkova
lmolkova added this pull request to the merge queue Sep 9, 2026
Merged via the queue into open-telemetry:main with commit ed7b44c Sep 9, 2026
75 checks passed
@rads-1996
rads-1996 deleted the multimodal-openai-changes branch September 9, 2026 18:44
HQidea added a commit to HQidea/opentelemetry-python-genai that referenced this pull request Sep 11, 2026
open-telemetry#540 taught `_content_to_parts` about text and image parts. The rest of
the shapes are still dropped, which is the same bug as open-telemetry#357: a part the
converter does not recognize costs the whole part, and a message left
with none is omitted entirely.

Building on that converter:

- `{"type": "input_audio"}` -> an audio `BlobPart`, decoded with
  `decode_base64()` so a malformed payload is skipped rather than
  recorded as garbage bytes; `wav` -> `audio/wav`, `mp3` -> `audio/mpeg`
  (`audio/mp3` is not a registered media type), unknown format -> none
- `{"type": "file"}` (Chat Completions, descriptor nested under `file`)
  and `{"type": "input_file"}` (Responses API, fields on the part) ->
  a `FilePart` for `file_id`, or a document `BlobPart` for an inline
  `file_data` data: URL, mirroring how `input_image` handles both
- `{"type": "refusal"}` -> a `TextPart`

`_prepare_output_messages` now goes through `_content_to_parts` as well,
and records `choice.message.refusal`, which a refused completion carries
in place of `content` - that path produced an empty output message
before. `_is_text_part` was its last caller and is removed.

Implemented with Claude (Anthropic) assistance.

Fixes open-telemetry#357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants