Skip to content

Commit 460b8d3

Browse files
committed
End span only if it's still recording in stream done callbacks. Assert that span status is unset.
1 parent 8423653 commit 460b8d3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ def stream_done_callback(response):
644644
self._converse_on_success(
645645
span, response, instrumentor_context, capture_content
646646
)
647-
span.end()
647+
if span.is_recording():
648+
span.end()
648649

649650
def stream_error_callback(exception):
650651
self._on_stream_error_callback(
@@ -684,7 +685,8 @@ def invoke_model_stream_done_callback(response):
684685
self._converse_on_success(
685686
span, response, instrumentor_context, capture_content
686687
)
687-
span.end()
688+
if span.is_recording():
689+
span.end()
688690

689691
def invoke_model_stream_error_callback(exception):
690692
self._on_stream_error_callback(

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_bedrock.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,7 @@ def test_converse_stream_close_before_consumption(
11571157
request_max_tokens=max_tokens,
11581158
request_stop_sequences=stop_sequences,
11591159
)
1160-
# No error status check - span should be closed normally
1161-
assert span.status.status_code != StatusCode.ERROR
1162-
1160+
assert span.status.status_code == StatusCode.UNSET
11631161
logs = log_exporter.get_finished_logs()
11641162

11651163
assert len(logs) == 1
@@ -2709,8 +2707,7 @@ def test_invoke_model_with_response_stream_close_before_consumption(
27092707
if model_family == "meta.llama"
27102708
else stop_sequences,
27112709
)
2712-
# No error status check - span should be closed normally
2713-
assert span.status.status_code != StatusCode.ERROR
2710+
assert span.status.status_code == StatusCode.UNSET
27142711

27152712
logs = log_exporter.get_finished_logs()
27162713
assert len(logs) == 1

0 commit comments

Comments
 (0)