11import inspect
2+ import sys
23from functools import wraps
34
45from sentry_sdk .consts import SPANDATA
56import sentry_sdk .utils
67from sentry_sdk import start_span
78from sentry_sdk .tracing import Span
8- from sentry_sdk .utils import ContextVar
9+ from sentry_sdk .utils import ContextVar , reraise , capture_internal_exceptions
910
1011from typing import TYPE_CHECKING
1112
@@ -44,13 +45,15 @@ def sync_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
4445 try :
4546 res = f (* args , ** kwargs )
4647 except Exception as e :
47- event , hint = sentry_sdk .utils .event_from_exception (
48- e ,
49- client_options = sentry_sdk .get_client ().options ,
50- mechanism = {"type" : "ai_monitoring" , "handled" : False },
51- )
52- sentry_sdk .capture_event (event , hint = hint )
53- raise e from None
48+ exc_info = sys .exc_info ()
49+ with capture_internal_exceptions ():
50+ event , hint = sentry_sdk .utils .event_from_exception (
51+ e ,
52+ client_options = sentry_sdk .get_client ().options ,
53+ mechanism = {"type" : "ai_monitoring" , "handled" : False },
54+ )
55+ sentry_sdk .capture_event (event , hint = hint )
56+ reraise (* exc_info )
5457 finally :
5558 _ai_pipeline_name .set (None )
5659 return res
@@ -72,13 +75,15 @@ async def async_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
7275 try :
7376 res = await f (* args , ** kwargs )
7477 except Exception as e :
75- event , hint = sentry_sdk .utils .event_from_exception (
76- e ,
77- client_options = sentry_sdk .get_client ().options ,
78- mechanism = {"type" : "ai_monitoring" , "handled" : False },
79- )
80- sentry_sdk .capture_event (event , hint = hint )
81- raise e from None
78+ exc_info = sys .exc_info ()
79+ with capture_internal_exceptions ():
80+ event , hint = sentry_sdk .utils .event_from_exception (
81+ e ,
82+ client_options = sentry_sdk .get_client ().options ,
83+ mechanism = {"type" : "ai_monitoring" , "handled" : False },
84+ )
85+ sentry_sdk .capture_event (event , hint = hint )
86+ reraise (* exc_info )
8287 finally :
8388 _ai_pipeline_name .set (None )
8489 return res
0 commit comments