Skip to content

Commit 091506c

Browse files
Merge branch 'webb/anthropic/separate-output-handling' into webb/anthropic/only-raw-message-stream-events
2 parents 61a4cd0 + db5dbb9 commit 091506c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,14 @@ def _set_output_data(
402402
span.__exit__(None, None, None)
403403

404404

405-
def _set_streaming_output_data(
405+
def _patch_streaming_response_iterator(
406406
result: "AsyncStream[RawMessageStreamEvent]",
407407
span: "sentry_sdk.tracing.Span",
408-
):
409-
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
410-
408+
integration: "AnthropicIntegration",
409+
) -> None:
410+
"""
411+
Responsible for closing the `gen_ai.chat` span and setting attributes acquired during response consumption.
412+
"""
411413
old_iterator = result._iterator
412414

413415
def new_iterator() -> "Iterator[MessageStreamEvent]":
@@ -548,7 +550,7 @@ def _sentry_patched_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "A
548550

549551
is_streaming_response = kwargs.get("stream", False)
550552
if is_streaming_response:
551-
_set_streaming_output_data(result, span)
553+
_patch_streaming_response_iterator(result, span, integration)
552554
return result
553555

554556
with capture_internal_exceptions():

0 commit comments

Comments
 (0)