Skip to content

fix(openai): keep input messages on base64 image prompts without an uploader - #4774

Draft
doronkopit5 wants to merge 1 commit into
mainfrom
heal/issue-4690-a1
Draft

doronkopit5 wants to merge 1 commit into
mainfrom
heal/issue-4690-a1

Conversation

@doronkopit5

@doronkopit5 doronkopit5 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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

  • 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:

  • 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_none

no telemetry change

tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob

1 attribute added

span / metric field before after
openai.chat gen_ai.input.messages absent [{"role": "user", "parts": [{"type": "text", "content": "What is in this image?"…

4 attributes unchanged

tests/traces/test_vision.py::test_vision_base64_default_uploader_keeps_inline_blob_async

1 attribute added; 1 attribute changed

span / metric field before after
openai.chat gen_ai.headers {'traceparent': '00-b6b9101a65435b5e23b838ddf79b1a29-60c7811abd96c733-03'} {'traceparent': '00-20e26ea99935acfb5dac7ab0ebc93f7a-46e11dfafe97b36a-03'}
openai.chat gen_ai.input.messages absent [{"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)
  • Approved by a maintainer other than the author
  • CodeRabbit review read

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • OpenAI request traces now retain base64-encoded images as inline PNG data for both synchronous and asynchronous requests.
    • Image upload callbacks are no longer configured by default, avoiding a placeholder callback when none is provided.

@doronkopit5

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Changes: OpenAI image input handling

Layer / File(s) Summary
Optional image uploader default
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/__init__.py, packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/config.py
The instrumentor and Config now default upload_base64_image to None. The Config annotation now specifies an optional coroutine-returning callable.
Inline image span tests
packages/opentelemetry-instrumentation-openai/tests/traces/test_vision.py
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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed [#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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d0e6d89-7de5-4d72-b495-5d7a190da01f
Commits

Reviewing files that changed from the base of the PR and between b870d8a and 6d92ad0.

Files selected for processing: 3

  • packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/__init__.py
  • packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/config.py
  • packages/opentelemetry-instrumentation-openai/tests/traces/test_vision.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

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.

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.

🐛 Bug Report: OpenAI instrumentation drops gen_ai.input.messages on image requests when no uploader is configured

1 participant