1111from sentry_sdk .consts import SPANDATA , SPANSTATUS , OP
1212from sentry_sdk .integrations import DidNotEnable
1313from sentry_sdk .scope import should_send_default_pii
14+ from sentry_sdk .tracing import Span
1415from sentry_sdk .tracing_utils import set_span_errored
1516from sentry_sdk .utils import event_from_exception , safe_serialize
1617from sentry_sdk .ai ._openai_completions_api import _transform_system_instructions
2223from typing import TYPE_CHECKING
2324
2425if TYPE_CHECKING :
25- from typing import Any
26+ from typing import Any , Union
2627 from agents import Usage , TResponseInputItem
2728
28- from sentry_sdk .tracing import Span
29+ from sentry_sdk .traces import StreamedSpan
2930 from sentry_sdk ._types import TextPart
3031
3132try :
@@ -46,8 +47,15 @@ def _capture_exception(exc: "Any") -> None:
4647 sentry_sdk .capture_event (event , hint = hint )
4748
4849
49- def _record_exception_on_span (span : "Span" , error : Exception ) -> "Any" :
50+ def _record_exception_on_span (
51+ span : "Union[Span, StreamedSpan]" , error : Exception
52+ ) -> "Any" :
5053 set_span_errored (span )
54+
55+ if not isinstance (span , Span ):
56+ # TODO[span-first]: make this work with streamedspans
57+ return
58+
5159 span .set_data ("span.status" , "error" )
5260
5361 # Optionally capture the error details if we have them
0 commit comments