Skip to content

Commit b92db6d

Browse files
docstring
1 parent 0aeec72 commit b92db6d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ def setup_once() -> None:
9494
_check_minimum_version(AnthropicIntegration, version)
9595

9696
"""
97-
client.messages.create(stream=True) returns an instance of the Stream class, which implements the iterator protocol.
97+
client.messages.create(stream=True) can return an instance of the Stream class, which implements the iterator protocol.
9898
The underlying stream can be consumed using either __iter__ or __next__, so both are patched to intercept
9999
streamed events. The streamed events are used to populate output attributes on the AI Client Span.
100100
101-
The close() method is patched for situations in which the method is directly invoked by the user, and otherwise
102-
the finally block in the __iter__ patch closes the span.
101+
The span is finished in two possible places:
102+
- When the user exits the context manager or directly calls close(), the patched close() ends the span.
103+
- When iteration ends, the finally block in the __iter__ patch or the except block in the __next__ patch finishes the span.
104+
105+
Both paths may run, for example, when the iterator is exhausted and then the context manager exits.
103106
"""
104107
Messages.create = _wrap_message_create(Messages.create)
105108
Stream.__iter__ = _wrap_stream_iter(Stream.__iter__)
@@ -109,12 +112,15 @@ def setup_once() -> None:
109112
AsyncMessages.create = _wrap_message_create_async(AsyncMessages.create)
110113

111114
"""
112-
client.messages.stream() returns an instance of the MessageStream class, which implements the iterator protocol.
115+
client.messages.stream() can return an instance of the MessageStream class, which implements the iterator protocol.
113116
The underlying stream can be consumed using either __iter__ or __next__, so both are patched to intercept
114117
streamed events. The streamed events are used to populate output attributes on the AI Client Span.
115118
116-
The close() method is patched for situations in which the method is directly invoked by the user, and otherwise
117-
the finally block in the __iter__ patch closes the span.
119+
The span is finished in two possible places:
120+
- When the user exits the context manager or directly calls close(), the patched close() ends the span.
121+
- When iteration ends, the finally block in the __iter__ patch or the except block in the __next__ patch finishes the span.
122+
123+
Both paths may run, for example, when the iterator is exhausted and then the context manager exits.
118124
"""
119125
Messages.stream = _wrap_message_stream(Messages.stream)
120126
MessageStreamManager.__enter__ = _wrap_message_stream_manager_enter(

0 commit comments

Comments
 (0)