Skip to content

Commit 55e6448

Browse files
committed
Extract response output and stream content into helper functions
1 parent 7df8441 commit 55e6448

File tree

1 file changed

+12
-2
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions

1 file changed

+12
-2
lines changed

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/bedrock.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ def _converse_on_success(
500500
)
501501

502502
# In case of an early stream closure, the result may not contain outputs
503-
if "output" in result and "message" in result["output"]:
503+
if self._stream_has_output(result) and self._stream_has_content(
504+
result
505+
):
504506
event_logger = instrumentor_context.event_logger
505507
choice = _Choice.from_converse(result, capture_content)
506508
# this path is used by streaming apis, in that case we are already out of the span
@@ -786,7 +788,9 @@ def _handle_amazon_nova_response(
786788
)
787789

788790
# In case of an early stream closure, the result may not contain outputs
789-
if "output" in response_body and "message" in response_body["output"]:
791+
if self._stream_has_output(response_body) and self._stream_has_content(
792+
response_body
793+
):
790794
event_logger = instrumentor_context.event_logger
791795
choice = _Choice.from_converse(response_body, capture_content)
792796
event_logger.emit(choice.to_choice_event())
@@ -1010,3 +1014,9 @@ def on_error(
10101014
duration,
10111015
attributes=metrics_attributes,
10121016
)
1017+
1018+
def _stream_has_output(self, response_body: dict[str, Any]):
1019+
return "output" in response_body
1020+
1021+
def _stream_has_content(self, response_body: dict[str, Any]):
1022+
return "message" in response_body["output"]

0 commit comments

Comments
 (0)