@@ -182,6 +182,24 @@ def test_v1_bad_chat(sentry_init, capture_events):
182182 assert event ["level" ] == "error"
183183
184184
185+ def test_v1_streaming_error_propagates (sentry_init , capture_events ):
186+ """Stream errors must not be silently swallowed by capture_internal_exceptions."""
187+ sentry_init (integrations = [CohereIntegration ()], traces_sample_rate = 1.0 )
188+ events = capture_events ()
189+
190+ from sentry_sdk .integrations .cohere .v1 import _iter_stream_events
191+
192+ def failing_iterator ():
193+ yield "event1"
194+ raise ConnectionError ("stream interrupted" )
195+
196+ with start_transaction (name = "cohere tx" ) as tx :
197+ span = tx .start_child (op = "gen_ai.chat" )
198+ with pytest .raises (ConnectionError , match = "stream interrupted" ):
199+ list (_iter_stream_events (failing_iterator (), span , False ))
200+ span .finish ()
201+
202+
185203def test_v1_span_status_error (sentry_init , capture_events ):
186204 sentry_init (integrations = [CohereIntegration ()], traces_sample_rate = 1.0 )
187205 events = capture_events ()
@@ -410,6 +428,25 @@ def test_v2_streaming_chat(
410428# --- V2 Error ---
411429
412430
431+ @pytest .mark .skipif (not has_v2 , reason = "Cohere V2 client not available" )
432+ def test_v2_streaming_error_propagates (sentry_init , capture_events ):
433+ """Stream errors must not be silently swallowed by capture_internal_exceptions."""
434+ sentry_init (integrations = [CohereIntegration ()], traces_sample_rate = 1.0 )
435+ events = capture_events ()
436+
437+ from sentry_sdk .integrations .cohere .v2 import _iter_v2_stream_events
438+
439+ def failing_iterator ():
440+ yield "event1"
441+ raise ConnectionError ("stream interrupted" )
442+
443+ with start_transaction (name = "cohere tx" ) as tx :
444+ span = tx .start_child (op = "gen_ai.chat" )
445+ with pytest .raises (ConnectionError , match = "stream interrupted" ):
446+ list (_iter_v2_stream_events (failing_iterator (), span , False ))
447+ span .finish ()
448+
449+
413450@pytest .mark .skipif (not has_v2 , reason = "Cohere V2 client not available" )
414451def test_v2_bad_chat (sentry_init , capture_events ):
415452 sentry_init (integrations = [CohereIntegration ()], traces_sample_rate = 1.0 )
0 commit comments