Skip to content

fix: add missing [] defaults to 5 .get() calls in Bedrock span_utils#4334

Open
truecallerabreham wants to merge 1 commit into
traceloop:mainfrom
truecallerabreham:fix/bedrock-get-defaults
Open

fix: add missing [] defaults to 5 .get() calls in Bedrock span_utils#4334
truecallerabreham wants to merge 1 commit into
traceloop:mainfrom
truecallerabreham:fix/bedrock-get-defaults

Conversation

@truecallerabreham

@truecallerabreham truecallerabreham commented Jun 30, 2026

Copy link
Copy Markdown

Five .get() calls in span_utils.py iterate over the result without providing a default, so when the response body doesn't include the expected key you get a TypeError instead of gracefully skipping.

The pattern already exists on line 220 (response_body.get("generations", [])) but the other five sites using "generations", "completions", and "results" were missed. This hits Cohere, AI21, Meta/Llama, and Amazon Titan models in the non-streaming path.

Fix is adding [], nothing else changes.

Before / After:

terminal_screenshot

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Five span attribute helper functions in span_utils.py for the Bedrock instrumentation package were updated to use dict.get with an empty list default when reading "generations", "completions", or "results" keys from response bodies, preventing failures when those keys are absent.

Changes

Bedrock Response Field Defaulting

Layer / File(s) Summary
Null-safe iteration over response collections
packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/span_utils.py
Five helpers (_set_generations_span_attributes, _set_span_completions_attributes, _set_llama_response_span_attributes, _set_amazon_span_attributes, _set_amazon_response_span_attributes) now default to an empty list when "generations", "completions", or "results" keys are missing, avoiding errors during iteration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Five little loops once feared the void,
when "results" or "generations" got destroyed.
Now with a bracket, empty and bright,
they hop right past the missing byte. 🐇
No more crashes in burrows deep —
just safe, soft data, lulled to sleep. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change: adding [] defaults to five Bedrock span_utils .get() calls to avoid iteration errors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@truecallerabreham

Copy link
Copy Markdown
Author

CLA was signed but status shows pending — could someone trigger a recheck? Thanks.

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.

2 participants