Skip to content

feat(llmobs): accept image_parts on messages - #9684

Merged
sabrenner merged 4 commits into
masterfrom
jose/mlob-7916-llmobs-image-parts
Aug 5, 2026
Merged

feat(llmobs): accept image_parts on messages#9684
sabrenner merged 4 commits into
masterfrom
jose/mlob-7916-llmobs-image-parts

Conversation

@joizddog

@joizddog joizddog commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds image support to the LLM Observability SDK. A message may carry imageParts, each { mimeType, content | attachmentKey }, which the tagger validates and emits as the snake_case wire shape image_parts: [{ mime_type, content | attachment_key }].

Message.imageParts and an ImagePart type are declared in both public typing surfaces, index.d.ts and index.d.v5.ts. ImagePart is an exclusive union, so a part carrying neither content nor attachmentKey, or both at once, fails to type-check rather than only throwing at runtime. docs/test.ts pins all four cases, two valid and two behind @ts-expect-error.

Manual annotation only: this is llmobs.annotate(), and an auto-instrumented OpenAI or Bedrock call that sends an image will not populate image_parts by itself. Provider auto-capture is a follow-up.

Motivation

This is the wire shape dd-trace-py already emits and the backend already types, so JS was the gap: an application could send images to a model but could not record them on the span. It mirrors audioParts, which landed earlier by the same route.

Additional Notes

The change is purely additive: 326 insertions across 6 files, no deletions, and no existing code path modified. #filterImageParts is a new private method; the only edits to existing functions are one destructured field and one guarded emit block in #tagMessages.

Validation rejects a non-object part, a missing or empty mimeType, neither content nor attachmentKey, both at once, and a non-string value for either. Each failure is tagged invalid_io_messages for telemetry, matching the audio path. An all-invalid list omits image_parts rather than emitting an empty array.

Three things deliberately left out of scope:

  • Provider auto-capture. formatImagePart was in an earlier revision of this branch but had no caller, so it is dropped here and will land with the instrumentation that uses it. That also leaves the shared util.js untouched by this PR. Note this differs from the audio precedent, where feat(llmobs): capture audio in messages and OpenAI chat completions #9083 shipped the tagger and the OpenAI capture together.
  • AudioPart in index.d.ts declares only content, though the tagger also accepts attachmentKey for audio. That is a pre-existing gap on the audio side and is not corrected here.
  • Media parts on non-llm span kinds. Only spanKind === 'llm' routes to tagLLMIO (sdk.js:278), so on a task, workflow or agent span an imageParts array falls through to tagTextIO and is stringified whole, with no validation failure and no telemetry. Pre-existing behaviour shared with audioParts, and worth its own fix(llmobs).

npm run lint is clean. npm run type:check is not clean on this branch, but nothing added here is responsible: index.d.ts reports zero errors, and the 18 in tagger.js all sit between lines 109 and 495, none of them in the regions this PR adds (699-751, 779, 821-828).

Two limits on what the type tooling proves, stated rather than implied. index.d.v5.ts is referenced by no tsconfig, so no CI job type-checks it; it was verified by compiling that surface standalone. And the @ts-expect-error assertions cover a directly annotated ImagePart but not the annotate() call site, since inputData and outputData include a { [key: string]: any } arm (index.d.ts:4136, :4144) that disables excess-property checking.

How to test

No credentials needed. Validation and wire shape are covered by unit tests:

npm run test:llmobs:sdk       # 524 passing; image cases under "tagging image parts appropriately"
npm run type:doc:test         # compiles docs/test.ts, including the ImagePart union assertions

End to end, if you want to see it render. Manual annotation needs no LLM provider key, only a Datadog key:

llmobs.trace({ kind: 'llm', name: 'image-parts-repro' }, () => {
  llmobs.annotate({
    inputData: [{ role: 'user', content: 'what is in this image?',
                  imageParts: [{ mimeType: 'image/png', content: '<base64>' }] }],
    outputData: [{ role: 'assistant', content: 'bands and a diagonal',
                   imageParts: [{ mimeType: 'image/png', attachmentKey: 'key-123' }] }]
  })
})

On master that same call records nothing. #tagMessages destructures a fixed key list ending at audioParts (tagger.js:725) and there is no unknown-key warning, so imageParts is dropped with no error and no telemetry. Silent data loss is the behaviour this fixes.

tagger.js is the only runtime file changed here (the other five are type definitions and tests), so a before/after is a one-file swap against the same install:

git checkout origin/master -- packages/dd-trace/src/llmobs/tagger.js   # before
git checkout HEAD -- packages/dd-trace/src/llmobs/tagger.js            # after

Before / after

Screenshot 2026-08-05 at 10 52 31 AM Screenshot 2026-08-05 at 10 53 29 AM

Adds image support to the LLM Observability SDK, mirroring audio_parts. A
message may carry imageParts, each `{mimeType, content | attachmentKey}`, which
the tagger validates and emits as the snake_case wire shape `image_parts:
[{mime_type, content | attachment_key}]` — the same shape dd-trace-py emits and
the backend already types.

formatAudioPart and formatImagePart share one builder, since audio and image
parts have an identical wire shape and the linter rejects the duplicate.

Manual annotation only; provider auto-capture is a follow-up.
@joizddog
joizddog requested a review from a team August 4, 2026 18:46
@dd-octo-sts

dd-octo-sts Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 7.85 MB
Deduped: 8.52 MB
No deduping: 8.52 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 441.68 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-official

datadog-official Bot commented Aug 4, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog retried 1 test - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.52% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f555ba2 | Docs | Datadog PR Page | Give us feedback!

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (d678882) to head (f555ba2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9684   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files         963      963           
  Lines      135796   135858   +62     
  Branches    11984    11925   -59     
=======================================
+ Hits       133785   133847   +62     
  Misses       2011     2011           
Flag Coverage Δ
aiguard 56.89% <3.22%> (-0.11%) ⬇️
aiguard-integration 55.75% <3.22%> (-0.07%) ⬇️
apm-bucket-0 57.13% <3.22%> (-0.11%) ⬇️
apm-bucket-1 63.22% <3.22%> (-0.11%) ⬇️
apm-bucket-2 62.02% <3.22%> (-0.11%) ⬇️
apm-bucket-3 59.57% <3.22%> (-0.11%) ⬇️
apm-capabilities-tracing 62.57% <3.22%> (-0.04%) ⬇️
apm-integrations-aerospike 56.19% <3.22%> (-0.11%) ⬇️
apm-integrations-confluentinc-kafka-javascript 60.84% <3.22%> (-0.15%) ⬇️
apm-integrations-couchbase 56.61% <3.22%> (-0.11%) ⬇️
apm-integrations-http 62.02% <3.22%> (-0.11%) ⬇️
apm-integrations-kafkajs 61.45% <3.22%> (-0.12%) ⬇️
apm-integrations-next 59.17% <3.22%> (-0.11%) ⬇️
apm-integrations-prisma 58.20% <3.22%> (-0.10%) ⬇️
appsec 71.94% <3.22%> (-0.11%) ⬇️
appsec-express_fastify_graphql 69.37% <3.22%> (-0.10%) ⬇️
appsec-integration 50.19% <3.22%> (-0.04%) ⬇️
appsec-kafka_ldapjs_lodash 63.25% <3.22%> (-0.10%) ⬇️
appsec-mongodb-core_mongoose_mysql 66.89% <3.22%> (-0.10%) ⬇️
appsec-next 56.61% <3.22%> (-0.09%) ⬇️
appsec-node-serialize_passport_postgres 66.53% <3.22%> (-0.10%) ⬇️
appsec-sourcing_stripe_template 64.91% <3.22%> (-0.10%) ⬇️
debugger 64.11% <3.22%> (-0.11%) ⬇️
instrumentations-bucket-0 51.49% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-1 59.51% <3.22%> (-0.11%) ⬇️
instrumentations-bucket-10 61.42% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-11 51.41% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-12 52.21% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-13 51.52% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-2 53.31% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-3 58.58% <3.22%> (-0.11%) ⬇️
instrumentations-bucket-4 52.04% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-5 57.08% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-6 60.15% <3.22%> (-0.11%) ⬇️
instrumentations-bucket-7 57.95% <3.22%> (-0.10%) ⬇️
instrumentations-bucket-8 58.91% <3.22%> (-0.11%) ⬇️
instrumentations-bucket-9 60.96% <3.22%> (-0.10%) ⬇️
instrumentations-instrumentation-couchbase 50.76% <3.22%> (-0.11%) ⬇️
instrumentations-integration-esbuild 33.93% <ø> (ø)
llmobs-ai_anthropic_bedrock 62.75% <17.74%> (-0.08%) ⬇️
llmobs-bucket-1 61.23% <17.74%> (-0.07%) ⬇️
llmobs-openai 61.71% <17.74%> (-0.08%) ⬇️
llmobs-openai-agents_vertex-ai 59.69% <17.74%> (-0.09%) ⬇️
llmobs-sdk 66.51% <100.00%> (+0.02%) ⬆️
master-coverage 98.51% <100.00%> (?)
openfeature 55.53% <3.22%> (-0.08%) ⬇️
openfeature-unit 53.06% <3.22%> (-0.11%) ⬇️
platform-core_esbuild_instrumentations-misc 40.51% <3.22%> (-0.05%) ⬇️
platform-integration 60.40% <3.22%> (-0.08%) ⬇️
platform-shimmer_unit-guardrails_webpack 38.77% <3.22%> (-0.05%) ⬇️
plugins-bucket-0 56.70% <3.22%> (-0.10%) ⬇️
plugins-bucket-1 53.84% <3.22%> (-0.08%) ⬇️
plugins-bucket-11 61.73% <3.22%> (-0.10%) ⬇️
plugins-bucket-18 61.27% <3.22%> (-0.10%) ⬇️
plugins-bucket-19 59.48% <3.22%> (-0.11%) ⬇️
plugins-bucket-20 61.48% <3.22%> (-0.11%) ⬇️
plugins-bucket-4 58.08% <3.22%> (-0.11%) ⬇️
plugins-bullmq_cassandra_cookie 61.13% <3.22%> (-0.11%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 56.24% <3.22%> (-0.11%) ⬇️
plugins-fetch_fs_generic-pool 58.10% <3.22%> (-0.11%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 63.97% <3.22%> (-0.11%) ⬇️
plugins-hapi_hono_ioredis 59.66% <3.22%> (-0.11%) ⬇️
plugins-jest_knex_langgraph 55.25% <3.22%> (-0.11%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 58.01% <3.22%> (-0.10%) ⬇️
plugins-lodash_mariadb_memcached 57.56% <3.22%> (-0.11%) ⬇️
plugins-moleculer_mongodb_mongodb-core 61.25% <3.22%> (-0.11%) ⬇️
plugins-mongoose_multer_mysql 58.55% <3.22%> (-0.11%) ⬇️
plugins-mysql2_nats_node-serialize 60.08% <3.22%> (-0.11%) ⬇️
plugins-opensearch_passport-http_pino 58.99% <3.22%> (-0.11%) ⬇️
plugins-postgres_process_pug 58.15% <3.22%> (-0.11%) ⬇️
plugins-redis_router_sequelize 61.33% <3.22%> (-0.11%) ⬇️
plugins-test-and-upstream-rhea_undici_url 60.86% <3.22%> (-0.11%) ⬇️
plugins-valkey_vm_winston 57.51% <3.22%> (-0.11%) ⬇️
plugins-ws 59.01% <3.22%> (-0.11%) ⬇️
profiling 61.36% <3.22%> (-0.11%) ⬇️
serverless-aws-sdk-aws-sdk 54.79% <3.22%> (-0.09%) ⬇️
serverless-aws-sdk-base-inject-field 50.71% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-bedrockruntime 54.43% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-client 56.02% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-dynamodb 55.28% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-eventbridge 49.30% <3.22%> (-0.09%) ⬇️
serverless-aws-sdk-kinesis 58.80% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-lambda 56.96% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-s3 55.38% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-serverless-peer-service 59.20% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-sns 59.62% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-sqs 60.05% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-stepfunctions 55.21% <3.22%> (-0.10%) ⬇️
serverless-aws-sdk-util 51.25% <3.22%> (-0.11%) ⬇️
serverless-bucket-0 53.91% <3.22%> (-0.08%) ⬇️
serverless-bucket-1 58.74% <3.22%> (-0.11%) ⬇️
test-optimization-cucumber 71.39% <3.22%> (-0.06%) ⬇️
test-optimization-cypress 65.17% <3.22%> (+0.03%) ⬆️
test-optimization-jest 72.88% <3.22%> (-0.20%) ⬇️
test-optimization-mocha 72.44% <3.22%> (-0.03%) ⬇️
test-optimization-playwright-playwright-atr 60.09% <3.22%> (-0.06%) ⬇️
test-optimization-playwright-playwright-efd 60.22% <3.22%> (-0.05%) ⬇️
test-optimization-playwright-playwright-final-status 60.39% <3.22%> (-0.06%) ⬇️
test-optimization-playwright-playwright-impacted-tests 59.92% <3.22%> (+0.09%) ⬆️
test-optimization-playwright-playwright-reporting 61.10% <3.22%> (-0.16%) ⬇️
test-optimization-playwright-playwright-test-management 61.13% <3.22%> (+0.06%) ⬆️
test-optimization-playwright-playwright-test-span 60.13% <3.22%> (-0.12%) ⬇️
test-optimization-selenium 59.33% <3.22%> (-0.19%) ⬇️
test-optimization-testopt 57.84% <3.22%> (+0.02%) ⬆️
test-optimization-vitest 73.49% <3.22%> (-0.03%) ⬇️
test-optimization-vitest-browser 58.91% <3.22%> (-0.05%) ⬇️
test-optimization-webdriverio 64.80% <3.22%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Aug 4, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-05 19:35:13

Comparing candidate commit f555ba2 in PR branch jose/mlob-7916-llmobs-image-parts with baseline commit d678882 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2316 metrics, 42 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-211.013ms; +207.636ms] or [-7.873%; +7.747%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-233.900ms; +236.148ms] or [-9.048%; +9.135%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-166785.035µs; +166620.068µs] or [-5.377%; +5.371%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-181.027ms; +186.281ms] or [-6.205%; +6.385%]

scenario:appsec-control-20

  • unstable execution_time [-114.765ms; +139.667ms] or [-6.964%; +8.476%]

scenario:appsec-control-24

  • unstable execution_time [-112737.402µs; +111781.302µs] or [-9.043%; +8.966%]

scenario:appsec-control-26

  • unstable execution_time [-126569.237µs; +127353.204µs] or [-10.152%; +10.215%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-14.228ms; +26.748ms] or [-5.344%; +10.048%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-13885.945µs; +15605.678µs] or [-5.257%; +5.908%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-12.415ms; +18.752ms] or [-4.866%; +7.351%]

scenario:appsec-iast-with-vulnerability-control-20

  • unstable execution_time [-26.733ms; +31.584ms] or [-4.869%; +5.753%]

scenario:appsec-iast-with-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-28.626ms; +34.901ms] or [-5.181%; +6.317%]

scenario:child_process-shell-string-24

  • unstable execution_time [-12.655ms; +22.440ms] or [-3.920%; +6.951%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-2.739s; +0.222s] or [-31.202%; +2.524%]
  • unstable execution_time [-2.757s; +0.235s] or [-29.085%; +2.481%]
  • unstable instructions [-23.4G instructions; +2.0G instructions] or [-32.641%; +2.735%]
  • unstable throughput [-53.411op/s; +793.945op/s] or [-1.506%; +22.390%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-393.790ms; +607.314ms] or [-4.438%; +6.845%]
  • unstable execution_time [-390.677ms; +611.939ms] or [-4.067%; +6.370%]
  • unstable instructions [-3113.5M instructions; +5031.0M instructions] or [-4.232%; +6.838%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-4589.250ms; +3117.386ms] or [-41.293%; +28.049%]
  • unstable execution_time [-4608.466ms; +3126.865ms] or [-38.866%; +26.371%]
  • unstable instructions [-41.0G instructions; +27.3G instructions] or [-43.895%; +29.235%]
  • unstable max_rss_usage [-13.926MB; +10.583MB] or [-8.505%; +6.463%]
  • unstable throughput [-618.376op/s; +882.614op/s] or [-21.152%; +30.190%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-1739.501ms; +575.597ms] or [-21.021%; +6.956%]
  • unstable execution_time [-1768.125ms; +563.990ms] or [-19.707%; +6.286%]
  • unstable instructions [-15.0G instructions; +4.9G instructions] or [-22.221%; +7.215%]
  • unstable throughput [-150.664op/s; +475.225op/s] or [-4.103%; +12.943%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-3672.472ms; +3652.920ms] or [-35.688%; +35.498%]
  • unstable execution_time [-3644.748ms; +3692.945ms] or [-33.053%; +33.490%]
  • unstable instructions [-32614.3M instructions; +32697.9M instructions] or [-37.719%; +37.816%]
  • unstable max_rss_usage [-11480.657KB; +13009.457KB] or [-7.117%; +8.065%]
  • unstable throughput [-731.474op/s; +711.091op/s] or [-23.710%; +23.049%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-384.909ms; +224.324ms] or [-8.290%; +4.832%]
  • unstable execution_time [-381.457ms; +226.968ms] or [-8.083%; +4.809%]
  • unstable throughput [-80370.634op/s; +136383.406op/s] or [-4.524%; +7.676%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-5.884%; +5.069%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-29.429MB; +32.221MB] or [-14.070%; +15.404%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-581.303ms; +603.662ms] or [-5.022%; +5.215%]
  • unstable execution_time [-591.854ms; +623.173ms] or [-5.012%; +5.277%]
  • unstable throughput [-3.609op/s; +3.438op/s] or [-5.296%; +5.045%]

@joizddog
joizddog marked this pull request as ready for review August 4, 2026 19:35
@joizddog
joizddog requested a review from a team as a code owner August 4, 2026 19:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54323e6397

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread index.d.ts
Comment thread index.d.ts Outdated
/**
* Key of an already-uploaded image, in place of inline content
*/
attachmentKey?: string,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Encode ImagePart as an exclusive union

For callers using the new TypeScript surface, the runtime rejects an image part when neither payload is set or when both content and attachmentKey are set, but the declaration makes both fields optional, so TypeScript accepts both invalid shapes and users only find out at runtime when llmobs.annotate() throws. Please model ImagePart as a union requiring exactly one payload field so the public type matches the validation contract.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@joizddog i would try giving this a shot!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Updated ImagePart to a union, matching the existing AssistantTextMessage pattern.

@cdfox

cdfox commented Aug 4, 2026

Copy link
Copy Markdown

Tried this branch out end to end on a real app — it works. Wiring up a vision step in the JS stock watchlist test app (DataDog/llm-observability#91) and the input image renders on the span in the trace view.
Screenshot 2026-08-04 at 4 18 33 PM

Setup

# in test-apps/stock-watchlist-agent-js
npm install ../../../dd-trace-js   # this branch, jose/mlob-7916-llmobs-image-parts
DD_LLMOBS_ML_APP=stock-watchlist-agent-js-chris dd-auth -- npm start -- logos/apple.png

The app takes a logo image, calls an OpenAI vision model to translate it into a ticker symbol, then runs its normal research flow on that ticker. The annotation on the vision span:

llmobs.annotate(span, {
  inputData: [
    { role: 'system', content: VISION_PROMPT },
    { role: 'user', content: 'Which publicly traded company does this image show?',
      imageParts: [{ mimeType: 'image/png', content: base64 }] },
  ],
})

The image shows up on the identify_ticker span next to the user message and the assistant's structured output. Verified the wire shape at the tagger too — image_parts: [{mime_type: "image/png", content: "<base64>"}], matching what the backend expects. Also confirmed a data:-prefixed value is not what you want in content; raw base64 is correct, which matches the JSDoc.

Two things worth calling out, both about discoverability rather than correctness:

  1. imageParts is silently dropped on non-llm span kinds. In sdk.js only spanKind === 'llm' routes to tagLLMIO#tagMessages, so on a task / workflow / agent span the message array goes through tagTextIO and gets stringified whole — imageParts survives as inert text inside the value with no #handleFailure and no telemetry:

    task span: "[{\"role\":\"user\",\"content\":\"hi\",\"imageParts\":[{\"mimeType\":\"image/png\",...}]}]"
    llm span:  [{"role":"user","content":"hi","image_parts":[{"mime_type":"image/png","content":"AAAA"}]}]
    

    My span started life as kind: 'task' and that is exactly why no image appeared on my first attempt — it took reading tagger.js to work out why. Same applies to the existing audioParts, so it is pre-existing behavior rather than anything new here. A warning when media parts are passed to a non-llm span would have saved the debugging round-trip.

  2. The commit message notes provider auto-capture is a follow-up, and that matches what I saw: the auto-instrumented OpenAI.createResponse child span carries no image even though the request had an input_image part. Worth stating in the user-facing docs alongside the SDK reference, since "I sent an image to OpenAI, why is there no image on the span" seems like the likely first question. Happy to test the auto-capture follow-up on the same app when it lands.

Nothing blocking from my side.

@sabrenner sabrenner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm other than copying the typescript definitions over and one other typing issue! will approve once those are addressed

Address review feedback on the public typing surface.

index.d.v5.ts now declares Message.imageParts and ImagePart. AGENTS.md
requires a new public type in both files unless the API is v6-only, and
this one is not: the runtime backports and audioParts already ships in
v5. No tsconfig references index.d.v5.ts, so it was verified by compiling
that surface standalone and resolving llmobs.ImagePart against it.

ImagePart becomes an exclusive union carrying exactly one of content or
attachmentKey, using the "?: never" shape already used by
AssistantTextMessage and AssistantToolCallMessage in the same file.
docs/test.ts pins all four cases, two valid and two behind
ts-expect-error. Those assertions are load-bearing: reverting the type to
all-optional fields fails type:doc:test with TS2578 twice.

The union is enforced on a directly annotated ImagePart but not on an
inline literal passed to annotate(), since inputData and outputData
include a "{ [key: string]: any }" arm that disables excess-property
checking. Narrowing that affects every annotate() shape and is left out.

Tests: the image non-string-content case now asserts the
invalid_io_messages telemetry tag that its audio counterpart already
asserted, closing a hole where deleting the tag argument kept the suite
green. An SDK-level image test mirrors the audio one, and three image
test names are aligned to the audio wording.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 032e10eb9a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread index.d.ts
/**
* Images attached to the message (e.g. vision input, generated output)
*/
imageParts?: ImagePart[],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Constrain image parts on annotate inputs

Fresh evidence after the ImagePart union change: actual llmobs.annotate({ inputData: ... }) calls with imageParts: [{ mimeType: 'image/png' }] or with both content and attachmentKey still type-check, because AnnotationOptions.inputData/outputData can fall through to the broad { [key: string]: any } union arm instead of this Message field. That means the public API still accepts the shapes the tagger now throws on at runtime; please tighten the annotation input types (and mirror the v5 surface) so object-literal annotate calls get the same exclusivity check.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed. inputData and outputData use an index signature ({ [key: string]: any }) that disables excess-property checks, matching existing AudioPart behavior. Narrowing this index signature impacts all annotate() shapes, so it is best handled in a separate PR to keep this change purely additive.

Comment thread index.d.ts
/**
* Images attached to the message (e.g. vision input, generated output)
*/
imageParts?: ImagePart[],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expose processor image parts in public span types

When a span processor is registered and an LLM span is annotated with imageParts, span_processor.js copies the tagger's normalized messages through to LLMObservabilitySpan.input/output, so processors receive messages containing image_parts. The public processor type still exposes only { content, role? }[], so TypeScript processors that need to inspect or redact image payloads (for example span.input[0].image_parts) fail to compile even though the runtime now sends that field; please add the processor message shape for image parts in both public declaration files.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed. LLMObservabilitySpan.input also omits audio_parts, tool_calls, and tool_results sent at runtime. I will open a follow-up PR to update the processor message type across all media and tool fields together rather than special-casing images.

Comment thread index.d.ts
/**
* Images attached to the message (e.g. vision input, generated output)
*/
imageParts?: ImagePart[],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid accepting image parts in prompt templates

Because Prompt.template is typed as string | Message[], adding imageParts to Message now lets TypeScript callers put images in prompt chat templates, but tagPrompt() serializes those templates with only { role, content }, so the image parts are silently dropped from meta.input.prompt.chat_template. In code that annotates a prompt template alongside image messages, users get a clean type-check but no recorded images; please either include image parts in the prompt wire shape or split the prompt-template message type to exclude media, mirroring the chosen public type change to v5 as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed. This is pre-existing behavior shared with audioParts, toolCalls, and toolResults. I will address prompt wire shapes for all media/tool fields in a dedicated follow-up PR to avoid scope creep here.

@sabrenner sabrenner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i think the new / remaining codex comments are OK to be left unaddressed here and are applicable potentially in follow ups

@sabrenner
sabrenner merged commit 742b647 into master Aug 5, 2026
680 of 681 checks passed
@sabrenner
sabrenner deleted the jose/mlob-7916-llmobs-image-parts branch August 5, 2026 20:40
This was referenced Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants