Skip to content

fix(llmobs): fix missing estimated cost on Bedrock LLM spans#7952

Merged
sabrenner merged 2 commits intomasterfrom
grace/fix-bedrock-llmobs-cost-estimation
Apr 8, 2026
Merged

fix(llmobs): fix missing estimated cost on Bedrock LLM spans#7952
sabrenner merged 2 commits intomasterfrom
grace/fix-bedrock-llmobs-cost-estimation

Conversation

@heyitsgrace996
Copy link
Copy Markdown
Contributor

@heyitsgrace996 heyitsgrace996 commented Apr 8, 2026

What does this PR do?

Fixes model_name and model_provider on Bedrock LLMObs span events so the backend cost estimator can match them to pricing entries.

Before:

  • model_provider: split vendor name (e.g., "anthropic", "amazon", "meta")
  • model_name: split model name (e.g., "claude-3-sonnet-20240229-v1:0", "nova-lite-v1:0")

After:

  • model_provider: "amazon_bedrock" (matches backend cost estimator and existing frontend icon mapping)
  • model_name: full modelId (e.g., "anthropic.claude-3-sonnet-20240229-v1:0", "amazon.nova-lite-v1:0")

Motivation

Estimated cost is missing or incorrect on Bedrock LLM spans. parseModelId() splits model IDs like "amazon.nova-lite-v1:0" into modelProvider="amazon" and modelName="nova-lite-v1:0" for APM span tags. The LLMObs plugin passed these split values through to registerLLMObsSpan(), which sends them to the backend cost estimator. The estimator couldn't match either:

  • Provider "amazon" doesn't match the AWS Bedrock provider (provider_match: contains "bedrock")
  • Model name "nova-lite-v1:0" doesn't match pricing entries (match: contains "amazon.nova-lite")

For vendors with their own direct-API provider (anthropic, mistral), the split provider name matched the wrong provider, resulting in direct-API pricing instead of Bedrock pricing.

This is the same issue fixed in the Python tracer: DataDog/dd-trace-py#17293.

Additional Notes

  • Why parseModelId() is still called: The split modelProvider/modelName values are still needed by extractRequestParams() and extractTextAndResponseReason(), which use the provider name to select the correct request/response body parser for each Bedrock provider.

  • "amazon_bedrock" was chosen over "bedrock" because the frontend already maps "amazon_bedrock" to the LlmType.AMAZON_BEDROCK icon [ref].

  • APM span tags (aws.bedrock.request.model_provider and aws.bedrock.request.model) are unchanged.

Testing:

  • Updated assertions in bedrockruntime.spec.js (32 passed, 4 skipped - pre-existing skips)
  • ESLint: clean
  • LLMObs SDK tests: 291 passed
  • Validated with repro app against 27 Bedrock models across 6 vendors (amazon, anthropic, meta, mistral, openai, qwen) - confirmed correct cost estimation in LLMObs traces explorer

Before
image

image

After
image

image

Risks:

  • Changes meta.model_provider and meta.model_name on LLMObs span events. Customers filtering by @meta.model_provider:anthropic for Bedrock models would need to update to @meta.model_provider:amazon_bedrock. However, those customers were getting incorrect pricing, so the filter was already misleading.
  • ARN-format model IDs will see the full ARN string as model_name. Cost matching still works for system inference profiles (the model name is embedded in the ARN and matched via contains clauses).

Pass the full modelId and "amazon_bedrock" as model_provider to
LLMObs instead of the split values from parseModelId(). The split
values prevented the backend cost estimator from matching Bedrock
pricing entries.

Mirrors the Python tracer fix in DataDog/dd-trace-py#17293.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

Overall package size

Self size: 5.48 MB
Deduped: 6.33 MB
No deduping: 6.33 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 8, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

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

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9ed911f | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.24%. Comparing base (91fa0f8) to head (05bc27f).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7952      +/-   ##
==========================================
- Coverage   74.25%   74.24%   -0.01%     
==========================================
  Files         769      769              
  Lines       36068    36076       +8     
==========================================
+ Hits        26783    26786       +3     
- Misses       9285     9290       +5     
Flag Coverage Δ
aiguard-macos 39.43% <ø> (-0.12%) ⬇️
aiguard-ubuntu 39.55% <ø> (-0.12%) ⬇️
aiguard-windows 39.22% <ø> (-0.12%) ⬇️
apm-capabilities-tracing-macos 49.55% <ø> (-0.01%) ⬇️
apm-capabilities-tracing-ubuntu 49.46% <ø> (-0.01%) ⬇️
apm-capabilities-tracing-windows 49.33% <ø> (+0.12%) ⬆️
apm-integrations-child-process 38.76% <ø> (-0.08%) ⬇️
apm-integrations-couchbase-18 37.51% <ø> (-0.11%) ⬇️
apm-integrations-couchbase-eol 38.03% <ø> (-0.11%) ⬇️
apm-integrations-oracledb 37.86% <ø> (-0.11%) ⬇️
appsec-express 55.39% <ø> (-0.06%) ⬇️
appsec-fastify 51.70% <ø> (-0.08%) ⬇️
appsec-graphql 51.86% <ø> (-0.09%) ⬇️
appsec-kafka 44.48% <ø> (-0.09%) ⬇️
appsec-ldapjs 44.10% <ø> (-0.09%) ⬇️
appsec-lodash 43.70% <ø> (-0.09%) ⬇️
appsec-macos 58.08% <ø> (-0.08%) ⬇️
appsec-mongodb-core 48.88% <ø> (-0.09%) ⬇️
appsec-mongoose 49.53% <ø> (-0.10%) ⬇️
appsec-mysql 51.07% <ø> (-0.08%) ⬇️
appsec-node-serialize 43.28% <ø> (-0.09%) ⬇️
appsec-passport 47.74% <ø> (-0.10%) ⬇️
appsec-postgres 50.69% <ø> (-0.19%) ⬇️
appsec-sourcing 42.53% <ø> (-0.09%) ⬇️
appsec-stripe 44.72% <ø> (-0.10%) ⬇️
appsec-template 43.44% <ø> (-0.09%) ⬇️
appsec-ubuntu 58.17% <ø> (-0.08%) ⬇️
appsec-windows 57.90% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-bluebird 32.32% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-body-parser 40.62% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-child_process 38.06% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-cookie-parser 34.35% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express 34.67% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.48% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-session 40.26% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-fs 32.00% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-generic-pool 29.41% <ø> (ø)
instrumentations-instrumentation-http 39.98% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-knex 32.38% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mongoose 33.50% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.37% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mysql2 38.39% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-passport 44.15% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-http 43.83% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-local 44.36% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-pg 37.83% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise 32.25% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.25% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-q 32.30% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-url 32.22% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.27% <ø> (-0.11%) ⬇️
llmobs-ai 41.37% <ø> (-0.10%) ⬇️
llmobs-anthropic 40.84% <ø> (-0.10%) ⬇️
llmobs-bedrock 39.32% <ø> (-0.09%) ⬇️
llmobs-google-genai 39.87% <ø> (-0.09%) ⬇️
llmobs-langchain 39.45% <ø> (+0.03%) ⬆️
llmobs-openai 44.11% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 40.13% <ø> (-0.09%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 34.11% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
platform-webpack 19.85% <ø> (-0.01%) ⬇️
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq 43.47% <ø> (-0.23%) ⬇️
plugins-cassandra 38.01% <ø> (-0.11%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.42% <ø> (-0.12%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.35% <ø> (-0.10%) ⬇️
plugins-fetch 38.50% <ø> (-0.11%) ⬇️
plugins-fs 38.74% <ø> (-0.11%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.67% <ø> (-0.10%) ⬇️
plugins-grpc 41.00% <ø> (-0.10%) ⬇️
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.26% <ø> (-0.11%) ⬇️
plugins-hono 40.73% <ø> (+0.03%) ⬆️
plugins-ioredis 38.59% <ø> (-0.11%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 37.98% <ø> (-0.11%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.60% <ø> (-0.11%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 39.60% <ø> (-0.11%) ⬇️
plugins-memcached 38.33% <ø> (-0.11%) ⬇️
plugins-microgateway-core 39.33% <ø> (-0.11%) ⬇️
plugins-moleculer 40.62% <ø> (-0.11%) ⬇️
plugins-mongodb 39.26% <ø> (-0.11%) ⬇️
plugins-mongodb-core 39.10% <ø> (-0.11%) ⬇️
plugins-mongoose 39.00% <ø> (-0.02%) ⬇️
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.44% <ø> (-0.11%) ⬇️
plugins-mysql2 39.39% <ø> (-0.11%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.73% <ø> (-0.11%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.53% <ø> (-0.09%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 39.03% <ø> (-0.11%) ⬇️
plugins-router 43.35% <ø> (-0.11%) ⬇️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 38.61% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-amqplib 44.35% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-apollo 39.23% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-avsc 38.68% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-bunyan 33.93% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-connect 40.92% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-graphql 40.26% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-koa 40.51% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-protobufjs 38.91% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-rhea 44.38% <ø> (-0.08%) ⬇️
plugins-undici 39.35% <ø> (-0.10%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.30% <ø> (-0.11%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 34.25% <ø> (-0.11%) ⬇️
plugins-ws 42.11% <ø> (-0.11%) ⬇️
profiling-macos 40.64% <ø> (-0.11%) ⬇️
profiling-ubuntu 40.76% <ø> (-0.11%) ⬇️
profiling-windows 42.28% <ø> (-0.11%) ⬇️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs 25.62% <ø> (ø)
serverless-azure-functions-servicebus 25.62% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

@heyitsgrace996 heyitsgrace996 marked this pull request as ready for review April 8, 2026 15:55
@heyitsgrace996 heyitsgrace996 requested a review from a team as a code owner April 8, 2026 15:55
@heyitsgrace996
Copy link
Copy Markdown
Contributor Author

@codex

@heyitsgrace996 heyitsgrace996 requested review from Yun-Kim and sabrenner and removed request for Yun-Kim April 8, 2026 15:56
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Apr 8, 2026

Benchmarks

Benchmark execution time: 2026-04-08 16:02:23

Comparing candidate commit 9ed911f in PR branch grace/fix-bedrock-llmobs-cost-estimation with baseline commit 7d5fa99 in branch master.

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

Copy link
Copy Markdown
Collaborator

@sabrenner sabrenner left a comment

Choose a reason for hiding this comment

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

awesome, lgtm!

@sabrenner sabrenner merged commit 2bac203 into master Apr 8, 2026
789 checks passed
@sabrenner sabrenner deleted the grace/fix-bedrock-llmobs-cost-estimation branch April 8, 2026 17:14
dd-octo-sts Bot pushed a commit that referenced this pull request Apr 9, 2026
Pass the full modelId and "amazon_bedrock" as model_provider to
LLMObs instead of the split values from parseModelId(). The split
values prevented the backend cost estimator from matching Bedrock
pricing entries.

Mirrors the Python tracer fix in DataDog/dd-trace-py#17293.
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Apr 9, 2026
juan-fernandez pushed a commit that referenced this pull request Apr 10, 2026
Pass the full modelId and "amazon_bedrock" as model_provider to
LLMObs instead of the split values from parseModelId(). The split
values prevented the backend cost estimator from matching Bedrock
pricing entries.

Mirrors the Python tracer fix in DataDog/dd-trace-py#17293.
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.

2 participants