@@ -802,7 +802,8 @@ def _wrap_stream_iter(
802802) -> "Callable[..., Iterator[RawMessageStreamEvent]]" :
803803 """
804804 Accumulates output data while iterating. When the returned iterator ends, set
805- output attributes on the AI Client Span and end the span.
805+ output attributes on the AI Client Span and ends the span (unless the `close()`
806+ or `__next__()` patches have already closed it).
806807 """
807808
808809 def __iter__ (self : "Stream" ) -> "Iterator[RawMessageStreamEvent]" :
@@ -824,6 +825,7 @@ def _wrap_stream_next(
824825) -> "Callable[..., RawMessageStreamEvent]" :
825826 """
826827 Accumulates output data from the returned event.
828+ Closes the AI Client Span if `StopIteration` is raised.
827829 """
828830
829831 def __next__ (self : "Stream" ) -> "RawMessageStreamEvent" :
@@ -858,7 +860,8 @@ def _wrap_stream_close(
858860 f : "Callable[..., None]" ,
859861) -> "Callable[..., None]" :
860862 """
861- Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` runs first.
863+ Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` or
864+ the except block in the `__next__()` patch runs first.
862865 """
863866
864867 def close (self : "Stream" ) -> None :
0 commit comments