File tree Expand file tree Collapse file tree
sentry_sdk/integrations/openai_agents/patches Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44import sentry_sdk
55from sentry_sdk .consts import SPANSTATUS
6+ from sentry_sdk .traces import SpanStatus
7+ from sentry_sdk .tracing_utils import has_span_streaming_enabled
68
79if 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 )
You can’t perform that action at this time.
0 commit comments