1
1
import sys
2
2
3
+ import sentry_sdk
3
4
from sentry_sdk .consts import OP
4
- from sentry_sdk .hub import Hub
5
5
from sentry_sdk .integrations import Integration , DidNotEnable
6
6
from sentry_sdk ._types import TYPE_CHECKING
7
7
from sentry_sdk .utils import event_from_exception , reraise
@@ -41,15 +41,16 @@ def _sentry_task_factory(loop, coro, **kwargs):
41
41
42
42
async def _coro_creating_hub_and_span ():
43
43
# type: () -> Any
44
- hub = Hub (Hub .current )
45
44
result = None
46
45
47
- with hub :
48
- with hub .start_span (op = OP .FUNCTION , description = get_name (coro )):
46
+ with sentry_sdk .isolation_scope ():
47
+ with sentry_sdk .start_span (
48
+ op = OP .FUNCTION , description = get_name (coro )
49
+ ):
49
50
try :
50
51
result = await coro
51
52
except Exception :
52
- reraise (* _capture_exception (hub ))
53
+ reraise (* _capture_exception ())
53
54
54
55
return result
55
56
@@ -76,21 +77,20 @@ async def _coro_creating_hub_and_span():
76
77
pass
77
78
78
79
79
- def _capture_exception (hub ):
80
- # type: (Hub ) -> ExcInfo
80
+ def _capture_exception ():
81
+ # type: () -> ExcInfo
81
82
exc_info = sys .exc_info ()
82
83
83
- integration = hub .get_integration (AsyncioIntegration )
84
- if integration is not None :
85
- # If an integration is there, a client has to be there.
86
- client = hub .client # type: Any
84
+ client = sentry_sdk .get_client ()
87
85
86
+ integration = client .get_integration (AsyncioIntegration )
87
+ if integration is not None :
88
88
event , hint = event_from_exception (
89
89
exc_info ,
90
90
client_options = client .options ,
91
91
mechanism = {"type" : "asyncio" , "handled" : False },
92
92
)
93
- hub .capture_event (event , hint = hint )
93
+ sentry_sdk .capture_event (event , hint = hint )
94
94
95
95
return exc_info
96
96
0 commit comments