Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-botocore`: bedrock: Add safety check for bedrock ConverseStream responses
([#3990](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3990))
- `opentelemetry-instrumentation-botocore`: bedrock: only decode JSON input buffer in Anthropic Claude streaming
([#3875](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3875))
- `opentelemetry-instrumentation-aiohttp-client`, `opentelemetry-instrumentation-aiohttp-server`: Fix readme links and text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ def __init__(
def from_converse(
cls, response: dict[str, Any], capture_content: bool
) -> _Choice:
orig_message = response["output"]["message"]
# be defensive about malformed responses, refer to #3958 for more context
output = response.get("output", {})
orig_message = output.get("message", {})
if role := orig_message.get("role"):
message = {"role": role}
else:
Expand All @@ -537,8 +539,8 @@ def from_converse(

if tool_calls := extract_tool_calls(orig_message, capture_content):
message["tool_calls"] = tool_calls
elif capture_content:
message["content"] = orig_message["content"]
elif capture_content and (content := orig_message.get("content")):
message["content"] = content

return cls(message, response["stopReason"], index=0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from opentelemetry.instrumentation.botocore.extensions.bedrock_utils import (
InvokeModelWithResponseStreamWrapper,
_Choice,
)
from opentelemetry.semconv._incubating.attributes.error_attributes import (
ERROR_TYPE,
Expand Down Expand Up @@ -3051,6 +3052,16 @@ def stream_error_callback(exc, ended):
assert "input" not in tool_block


def test_converse_stream_with_missing_output_in_response():
# Test malformed response missing "output" key
malformed_response = {"stopReason": "end_turn"}
choice = _Choice.from_converse(malformed_response, capture_content=True)

assert choice.finish_reason == "end_turn"
assert choice.message == {}
assert choice.index == 0


def amazon_nova_messages():
return [
{"role": "user", "content": [{"text": "Say this is a test"}]},
Expand Down