You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(openai): keep input messages on base64 image prompts without an uploader - #4774
`OpenAIInstrumentor.__init__` set `upload_base64_image` to the sync `lambda *args: ""` by default, and the `Config` class default was also a sync lambda. Both are truthy, so `_set_prompts` always took the upload path, and `_process_image_item` then awaited the `str` the lambda returned. The resulting `TypeError` was caught by `@dont_throw`, so `_set_input_messages` never ran and `gen_ai.input.messages` was missing on every chat request with a base64 image. This happened whenever no async uploader was passed, for example with zero-code instrumentation or `OpenAIInstrumentor().instrument()` without traceloop-sdk.
Change
`upload_base64_image` now defaults to `None` in `OpenAIInstrumentor.__init__` and `Config`, typed as an optional async callable. The existing guards then skip the upload step and the image is recorded inline as a blob part. Uploaders stay async-only.
New tests in `tests/traces/test_vision.py` use a fixture that builds `OpenAIInstrumentor()` with no arguments, then restores `Config`. One checks the default is `None` (r11, r15). The others run `_handle_request` through the sync path (`run_async`; r1, r2, r5, r7, r9) and the async path (r3, r4, r6, r8, r10), and check for a text part plus an inline image blob part. All three failed before the fix and pass now.
`test_vision.py` and ruff pass. In `test_chat.py`, `test_chat_exception` and `test_chat_async_exception` fail with "Connection error.": they have no cassette and the runner is offline. This change doesn't touch them.
Behaviour changes: with no uploader passed, chat spans for base64 image requests now include `gen_ai.input.messages`, with the image inline as a blob part. `Config.upload_base64_image` now defaults to `None` instead of a lambda.
Not addressed: sync uploaders and a per-image fallback (maintainer ruled out of scope); the anthropic, google-generativeai and vertexai defaults (other packages).
Scope
slice 1 of 1
covers rows: 12 of 12 in rows
Out of scope:
Accepting sync uploaders (await only when inspect.isawaitable): Maintainer ruling 2026-11-24 (q1): uploaders stay async-only.
Per-image inline fallback when a user uploader raises or returns a non-str: Maintainer ruling 2026-11-24 (q2): this is a separate follow-up.
Changing the anthropic, google-generativeai and vertexai uploader defaults, or their raw-base64 attribute size: These are separate packages and none of them awaits a sync callable. The maintainer asked to keep this PR to the reported bug.
traceloop-sdk ImageUploader / Traceloop.init wiring: The SDK already passes an async uploader, and it is outside the allowed package.
Re-recording test_vision cassettes: The existing tests use an explicit async uploader and do not change. The new tests are request-path unit tests that make no API call.
Regression evidence
Each test below failed on the base commit and passes with this change, run offline in the heal harness:
[{"role": "user", "parts": [{"type": "text", "content": "What is in this image?"…
4 attributes unchanged
Review
Changes the default `upload_base64_image` to `None` in `OpenAIInstrumentor.__init__` and `Config`, and types it as an optional async callable. The existing guards in `_set_prompts` and `_process_image_item` then skip the upload, so base64 image prompts keep `gen_ai.input.messages` with the image inline as a blob part. New tests in test_vision.py check the default and run the sync (`run_async`) and async request paths. A fixture restores `Config` after each test. This follows the maintainer's ruling: async-only uploaders, no per-image fallback, other packages unchanged.
Before merging
CI green: Lint, Build Packages, Test Packages (3.10, 3.11, 3.12)
No actionable comments were generated in the recent review.
Walkthrough
The OpenAI instrumentor and its configuration now default upload_base64_image to None and type it as an optional coroutine-returning callable. Tests check that synchronous and asynchronous request handling records base64 images inline in span input.
Tests check that instrumentor initialization leaves the uploader unset and that synchronous and asynchronous request handling records the image as an inline PNG blob in span input.
traceloop/openllmetry#4692: Changes the same uploader default and inline image handling for the linked bug. It also adds synchronous uploader support, which this PR does not include.
Suggested reviewers:nirga, luizdmm
Merge Risk: Minimal · up to 6d92a
Base64 image prompts now keep their inline image in span input when no uploader is configured, which is what the linked issue asks for. No merge-blocking risk is evident.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title is a conventional-commit style summary that names the affected package (openai) and the behavior fixed: keeping input messages on base64 image prompts when no uploader is configured. The cha…
Linked Issues check
[#4690] Requirement: when no uploader is configured, chat spans with base64 image requests must keep gen_ai.input.messages, with the image inline. Root cause: the default upload_base64_image was a tru…
Out of Scope Changes check
The whole-PR change set (merge base 92ffa1c, head 6d92ad0) touches three files in packages/opentelemetry-instrumentation-openai: init.py (default changed from lambda to None), shared/config.py (de…
Full details: Title check
Explanation
The title is a conventional-commit style summary that names the affected package (openai) and the behavior fixed: keeping input messages on base64 image prompts when no uploader is configured. The changeset makes that change: upload_base64_image now defaults to None in OpenAIInstrumentor.init and Config, and new tests in test_vision.py check the default and the sync and async paths that keep the inline PNG blob in the span input. The title describes the main change.
Full details: Linked Issues check
Explanation
[#4690] Requirement: when no uploader is configured, chat spans with base64 image requests must keep gen_ai.input.messages, with the image inline. Root cause: the default upload_base64_image was a truthy sync lambda. The PR changes the default to None in OpenAIInstrumentor.init (openai/init.py) and in Config (shared/config.py), typed as Optional[Callable[..., Coroutine[..., str]]]. At the reviewed head, chat_wrappers.py _set_prompts only calls _preprocess_base64_images when Config.upload_base64_image is truthy, and _process_image_item returns the item unchanged when it is falsy. _set_input_messages therefore runs and records the image as an inline blob part. Uploaded-image behavior is unchanged when an async uploader is passed. New tests in tests/traces/test_vision.py cover the default value and the sync (run_async) and async request paths. The PR reports that these tests fail on the base commit and pass with the change. I did not run them. The issue's optional suggestion to check anthropic, google-generativeai and vertexai defaults is excluded by the PR and is not a stated OpenAI requirement.
Full details: Out of Scope Changes check
Explanation
The whole-PR change set (merge base 92ffa1c, head 6d92ad0) touches three files in packages/opentelemetry-instrumentation-openai: init.py (default changed from lambda to None), shared/config.py (default changed to None, Coroutine import added), and tests/traces/test_vision.py (new tests and a fixture that restores Config). Each change either implements the default-to-None fix or tests it. The PR excludes other packages, sync uploader support, per-image fallback, and traceloop-sdk wiring, and the diff does not include them. No unrelated change is evident.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
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
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.
Fixes #4690
Root cause
`OpenAIInstrumentor.__init__` set `upload_base64_image` to the sync `lambda *args: ""` by default, and the `Config` class default was also a sync lambda. Both are truthy, so `_set_prompts` always took the upload path, and `_process_image_item` then awaited the `str` the lambda returned. The resulting `TypeError` was caught by `
@dont_throw`, so `_set_input_messages` never ran and `gen_ai.input.messages` was missing on every chat request with a base64 image. This happened whenever no async uploader was passed, for example with zero-code instrumentation or `OpenAIInstrumentor().instrument()` without traceloop-sdk.Change
`upload_base64_image` now defaults to `None` in `OpenAIInstrumentor.__init__` and `Config`, typed as an optional async callable. The existing guards then skip the upload step and the image is recorded inline as a blob part. Uploaders stay async-only.
New tests in `tests/traces/test_vision.py` use a fixture that builds `OpenAIInstrumentor()` with no arguments, then restores `Config`. One checks the default is `None` (r11, r15). The others run `_handle_request` through the sync path (`run_async`; r1, r2, r5, r7, r9) and the async path (r3, r4, r6, r8, r10), and check for a text part plus an inline image blob part. All three failed before the fix and pass now.
`test_vision.py` and ruff pass. In `test_chat.py`, `test_chat_exception` and `test_chat_async_exception` fail with "Connection error.": they have no cassette and the runner is offline. This change doesn't touch them.
Behaviour changes: with no uploader passed, chat spans for base64 image requests now include `gen_ai.input.messages`, with the image inline as a blob part. `Config.upload_base64_image` now defaults to `None` instead of a lambda.
Not addressed: sync uploaders and a per-image fallback (maintainer ruled out of scope); the anthropic, google-generativeai and vertexai defaults (other packages).
Scope
inrowsOut of scope:
Regression evidence
Each test below failed on the base commit and passes with this change, run offline in the heal harness:
opentelemetry-instrumentation-openai:tests/traces/test_vision.py::test_instrumentor_default_upload_base64_image_is_none(failed before: assertion)opentelemetry-instrumentation-openai:tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob(failed before: exception)opentelemetry-instrumentation-openai:tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob_async(failed before: exception)Package suites: no new failures against the offline baseline.
Ruff: clean.
Telemetry evidence
tests/traces/test_vision.py::test_instrumentor_default_upload_base64_image_is_noneno telemetry change
tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob1 attribute added
4 attributes unchanged
tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob_async1 attribute added; 1 attribute changed
4 attributes unchanged
Review
Changes the default `upload_base64_image` to `None` in `OpenAIInstrumentor.__init__` and `Config`, and types it as an optional async callable. The existing guards in `_set_prompts` and `_process_image_item` then skip the upload, so base64 image prompts keep `gen_ai.input.messages` with the image inline as a blob part. New tests in test_vision.py check the default and run the sync (`run_async`) and async request paths. A fixture restores `Config` after each test. This follows the maintainer's ruling: async-only uploaders, no per-image fallback, other packages unchanged.
Before merging
🤖 Generated with Claude Code
Summary by CodeRabbit