Skip to content

Commit d3f3d5b

Browse files
set errors on streamed spans
1 parent 515f38a commit d3f3d5b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

sentry_sdk/integrations/openai_agents/patches/error_tracing.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import sentry_sdk
55
from sentry_sdk.consts import SPANSTATUS
6+
from sentry_sdk.traces import SpanStatus
7+
from sentry_sdk.tracing_utils import has_span_streaming_enabled
68

79
if TYPE_CHECKING:
810
from typing import Any
@@ -54,9 +56,15 @@ def sentry_attach_error_to_current_span(
5456
the agents library swallows exceptions.
5557
"""
5658
# Set the current Sentry span to errored
57-
current_span = sentry_sdk.get_current_span()
58-
if current_span is not None:
59-
current_span.set_status(SPANSTATUS.INTERNAL_ERROR)
59+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
60+
if span_streaming:
61+
current_span = sentry_sdk.get_current_scope().streamed_span
62+
if current_span is not None:
63+
current_span.status = SpanStatus.ERROR
64+
else:
65+
current_span = sentry_sdk.get_current_span()
66+
if current_span is not None:
67+
current_span.set_status(SPANSTATUS.INTERNAL_ERROR)
6068

6169
# Call the original function
6270
return original_attach_error(error, *args, **kwargs)

0 commit comments

Comments
 (0)