Skip to content

Commit 288a065

Browse files
Merge branch 'webb/anthropic/sync-iterators' into webb/anthropic/async-iterators
2 parents e84a63f + 7ec95fe commit 288a065

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
@@ -1096,7 +1096,8 @@ def _wrap_message_stream_iter(
10961096
) -> "Callable[..., Iterator[MessageStreamEvent]]":
10971097
"""
10981098
Accumulates output data while iterating. When the returned iterator ends, set
1099-
output attributes on the AI Client Span and end the span.
1099+
output attributes on the AI Client Span and ends the span (unless the `close()`
1100+
or `__next__()` patches have already closed it).
11001101
"""
11011102

11021103
def __iter__(self: "MessageStream") -> "Iterator[MessageStreamEvent]":
@@ -1118,6 +1119,7 @@ def _wrap_message_stream_next(
11181119
) -> "Callable[..., MessageStreamEvent]":
11191120
"""
11201121
Accumulates output data from the returned event.
1122+
Closes the AI Client Span if `StopIteration` is raised.
11211123
"""
11221124

11231125
def __next__(self: "MessageStream") -> "MessageStreamEvent":
@@ -1152,7 +1154,8 @@ def _wrap_message_stream_close(
11521154
f: "Callable[..., None]",
11531155
) -> "Callable[..., None]":
11541156
"""
1155-
Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` runs first.
1157+
Closes the AI Client Span, unless the finally block in `_wrap_synchronous_message_iterator()` or
1158+
the except block in the `__next__()` patch runs first.
11561159
"""
11571160

11581161
def close(self: "MessageStream") -> None:

0 commit comments

Comments
 (0)