(Openinference Migration: Langchain): Capture multimodal image content (OpenAI image_url and Anthropic image blocks) as Blob/Uri message parts. - #296
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-08-07 17:26 UTC Two things need attention:
Status above doesn't look right?
|
There was a problem hiding this comment.
Pull request overview
Adds multimodal image support to the LangChain GenAI instrumentation by converting OpenAI image_url and Anthropic image blocks into Blob / Uri message parts, and extends the unit test suite to validate the new parsing behavior.
Changes:
- Add multimodal image parsing helpers (
_media_part,_image_from_url) to convert LangChain image blocks intoBlob/Uriparts. - Extend callback-handler tests to cover OpenAI and Anthropic image content shapes (including data URIs and base64 sources).
- Add a changelog fragment documenting the new capability.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/utils.py | Adds image block parsing and base64 decoding to emit Blob/Uri message parts. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py | Adds unit tests for data-URI, HTTP-URI, and Anthropic image/source parsing into message parts. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/296.added | Documents the new multimodal image capture support. |
aa26c4f to
ed3949d
Compare
d72b64e to
501725d
Compare
|
@rads-1996 One thing I wanted to check on ordering. In That means a config that doesn't record content still copies large images. If that isn't intended, either skip the media decode when capture is off, or add a test asserting If the parse is meant to run unconditionally so the completion hook has something to work with, that's fine, I just wanted to confirm that's the assumption. |
@AgentGymLeader Thanks for the callout. I have gated decoding and will skipped when the content capture mode is |
9cd26fe to
1b98bc4
Compare
aaea6b5 to
d9fe119
Compare
d9fe119 to
a61da13
Compare
…mage` blocks) as `Blob`/`Uri` message parts.
9ae1c71 to
0c19a81
Compare
There was a problem hiding this comment.
can you please add conformance test? thanks!
| @@ -0,0 +1 @@ | |||
| (Openinference Migration: Langchain) - Capture multimodal image content (OpenAI ``image_url`` and Anthropic ``image`` blocks) as ``Blob``/``Uri`` message parts. | |||
There was a problem hiding this comment.
please update openai and anthropic instrumentations to hahve feature parity. Ok to do in a separate PR. Thanks!
| def _decode_base64(data: str) -> bytes | None: | ||
| # Skip the decode entirely when message content is not being captured; | ||
| # the resulting bytes would never be emitted under ``NO_CONTENT``. | ||
| if get_content_capturing_mode() is ContentCapturingMode.NO_CONTENT: |
There was a problem hiding this comment.
this one actually checks env var and is now used on a hot path, please use handler.should_capture_content() somewhere up the stack and don't call this method when content capturing is disabled
| return None | ||
|
|
||
|
|
||
| def _image_from_url(url: str) -> MessagePart | None: |
There was a problem hiding this comment.
should we have this whole method in utils? the data:// is pretty generic approach, nothing specific to openai https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data
There was a problem hiding this comment.
Yeah make sense, I can then reuse it for openai and anthropic.
| gen_ai_attributes as GenAIAttributes, | ||
| ) | ||
| from opentelemetry.util.genai.types import ( | ||
| Blob, |
There was a problem hiding this comment.
it's the first time we're using this type in this repo, mind renaming it to BlobPart? Same with Uri, can we rename it to UriPart - that's how they are called in semconv and it seems we're inconsistent - https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/non-normative/models.py
There was a problem hiding this comment.
Sounds good. I will make changes in the utils. I believe the same change is needed for some other data classes as well. I think I will make a separate PR to address that.
There was a problem hiding this comment.
@lmolkova Blob and Uri both have previously been used in other instrumentations, Blob has been used in the anthropic and google-genai instrumentation and Uri in google-genai. I have a PR out which aligns the names with semconv - #365. Should we have backward compatibility aliases for downstream users with deprecation messages?
Description
Part of the langchain migration PRs - #272
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.