Skip to content

opentelemetry-instrumentation-botocore: fix handling of tool input chunked json in bedrock converse_stream #3544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 29, 2025

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented May 27, 2025

Description

We need to accumulate all the tool input as string before decoding it otherwise we may end up with invalid json.

Fixes #3537

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • tox -e py312-test-instrumentation-botocore-1

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

xrmx added 2 commits May 27, 2025 10:32
…unked json in converse_stream

We need to accumulate all the tool input as string before decoding it
otherwise we may end up with invalid json.
@xrmx xrmx requested a review from a team as a code owner May 27, 2025 08:41
@xrmx xrmx merged commit 3e0632c into open-telemetry:main May 29, 2025
625 checks passed
liustve added a commit to aws-observability/aws-otel-python-instrumentation that referenced this pull request Jul 25, 2025
*Description of changes:*

This PR applies temporary patches to address critical bugs in the AWS
Bedrock runtime botocore instrumentation (version 0.54b0) that affect
tool use functionality in non-streaming responses reported in:
strands-agents/sdk-python#488

These changes are temporary patches and should be removed once we
upgrade to `opentelemetry-instrumentation-botocore` version 0.56b0,
which includes official fixes for these issues.

See: 
open-telemetry/opentelemetry-python-contrib#3548
open-telemetry/opentelemetry-python-contrib#3544

*Testing Done*

- Unit tests added
- Validated with Bedrock AgentCore team that fixes work.
- Ran a sample app with Bedrock AgentCore and strands framework and
validated that expected toolUse output is correct:

Before fix:

```
Tool use: {"input": ""}
Tool use: {"input": "{\"input\": 99"}
Tool use: {"input": 999}
Tool use: {"input": 99999}
Tool use: {"input": 9999}
Tool use: {"input": 9999}
Tool use: {"input": ", \"input2"}
Tool use: {"input": "\": 8"}
Tool use: {"input": 888888888888}
Tool use: {"input": 888}
Tool use: {"input": "88}"}
```

After fix:

```
Tool use: {"input": ""}
Tool use: {"input": "{\"in"}
Tool use: {"input": "put\": 9"}
Tool use: {"input": "99"}
Tool use: {"input": "99"}
Tool use: {"input": "99"}
Tool use: {"input": "9999"}
Tool use: {"input": "99999"}
Tool use: {"input": "99"}
Tool use: {"input": ", \"input"}
Tool use: {"input": "2\":"}
Tool use: {"input": " 8"}
Tool use: {"input": "888888"}
Tool use: {"input": "888888888"}
Tool use: {"input": "88}"}
```

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
devmonkey22 pushed a commit to devmonkey22/opentelemetry-python-contrib that referenced this pull request Aug 5, 2025
…unked json in bedrock converse_stream (open-telemetry#3544)

* opentelemetry-instrumentation-botocore: fix handling of tool input chunked json in converse_stream

We need to accumulate all the tool input as string before decoding it
otherwise we may end up with invalid json.

* Add changelog

* Remove leftover print

* No need for too-many-statements disable
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.

Bedrock instrumentation strips quotes from JSON strings in ConverseStream tool_use responses (v1.31.0/0.52b0+)
3 participants