Skip to content

Commit df1d4d4

Browse files
committed
Move stream output checks to a single method
1 parent 6a5b2ac commit df1d4d4

File tree

1 file changed

+6
-11
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions

1 file changed

+6
-11
lines changed

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

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

502502
# In case of an early stream closure, the result may not contain outputs
503-
if self._stream_has_output(result) and self._stream_has_content(
504-
result
505-
):
503+
if self._stream_has_output_content(result):
506504
event_logger = instrumentor_context.event_logger
507505
choice = _Choice.from_converse(result, capture_content)
508506
# this path is used by streaming apis, in that case we are already out of the span
@@ -792,9 +790,7 @@ def _handle_amazon_nova_response(
792790
)
793791

794792
# In case of an early stream closure, the result may not contain outputs
795-
if self._stream_has_output(response_body) and self._stream_has_content(
796-
response_body
797-
):
793+
if self._stream_has_output_content(response_body):
798794
event_logger = instrumentor_context.event_logger
799795
choice = _Choice.from_converse(response_body, capture_content)
800796
event_logger.emit(choice.to_choice_event())
@@ -1019,8 +1015,7 @@ def on_error(
10191015
attributes=metrics_attributes,
10201016
)
10211017

1022-
def _stream_has_output(self, response_body: dict[str, Any]):
1023-
return "output" in response_body
1024-
1025-
def _stream_has_content(self, response_body: dict[str, Any]):
1026-
return "message" in response_body["output"]
1018+
def _stream_has_output_content(self, response_body: dict[str, Any]):
1019+
return (
1020+
"output" in response_body and "message" in response_body["output"]
1021+
)

0 commit comments

Comments
 (0)