Skip to content

Commit e84a63f

Browse files
Merge branch 'webb/anthropic/sync-iterators' into webb/anthropic/async-iterators
2 parents a956644 + beb8f2c commit e84a63f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ def _wrap_stream_iter(
800800
) -> "Callable[..., Iterator[RawMessageStreamEvent]]":
801801
"""
802802
Accumulates output data while iterating. When the returned iterator ends, set
803-
output attributes on the AI Client Span and end the span.
803+
output attributes on the AI Client Span and ends the span (unless the `close()`
804+
or `__next__()` patches have already closed it).
804805
"""
805806

806807
def __iter__(self: "Stream") -> "Iterator[RawMessageStreamEvent]":
@@ -822,6 +823,7 @@ def _wrap_stream_next(
822823
) -> "Callable[..., RawMessageStreamEvent]":
823824
"""
824825
Accumulates output data from the returned event.
826+
Closes the AI Client Span if `StopIteration` is raised.
825827
"""
826828

827829
def __next__(self: "Stream") -> "RawMessageStreamEvent":
@@ -856,7 +858,8 @@ def _wrap_stream_close(
856858
f: "Callable[..., None]",
857859
) -> "Callable[..., None]":
858860
"""
859-
Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` runs first.
861+
Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` or
862+
the except block in the `__next__()` patch runs first.
860863
"""
861864

862865
def close(self: "Stream") -> None:

0 commit comments

Comments
 (0)