Repository navigation
Capture OpenAI multimodal image content (image_url and Responses API input_image) as BlobPart, UriPart, or FilePart message parts - #540
Conversation
2ec1848 to
568ca8b
Compare
Pull request dashboard statusMerged · refreshed 2026-09-10 17:14 UTC Status above doesn't look right?
|
5698089 to
8564fb8
Compare
There was a problem hiding this comment.
🟡 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 intoMessagePartlists 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
left a comment
There was a problem hiding this comment.
Would this work for streaming? Do we have any test coverage for streaming / async multi-modal content?
e9af0ca to
35db213
Compare
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
left a comment
There was a problem hiding this comment.
Thanks for the update! It seems there is a regression my AI bot found, can you please check ?
…input_image) as BlobPart, UriPart, or FilePart message parts
35db213 to
7c5fbb8
Compare
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
Description
Fixes # (#348)
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. List any relevant details for your test
configuration.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.