Skip to content

Commit ccb311f

Browse files
authored
ref(asyncio): Use new scopes API (#2895)
1 parent 076ca5d commit ccb311f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

sentry_sdk/integrations/asyncio.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

3+
import sentry_sdk
34
from sentry_sdk.consts import OP
4-
from sentry_sdk.hub import Hub
55
from sentry_sdk.integrations import Integration, DidNotEnable
66
from sentry_sdk._types import TYPE_CHECKING
77
from sentry_sdk.utils import event_from_exception, reraise
@@ -41,15 +41,16 @@ def _sentry_task_factory(loop, coro, **kwargs):
4141

4242
async def _coro_creating_hub_and_span():
4343
# type: () -> Any
44-
hub = Hub(Hub.current)
4544
result = None
4645

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+
):
4950
try:
5051
result = await coro
5152
except Exception:
52-
reraise(*_capture_exception(hub))
53+
reraise(*_capture_exception())
5354

5455
return result
5556

@@ -76,21 +77,20 @@ async def _coro_creating_hub_and_span():
7677
pass
7778

7879

79-
def _capture_exception(hub):
80-
# type: (Hub) -> ExcInfo
80+
def _capture_exception():
81+
# type: () -> ExcInfo
8182
exc_info = sys.exc_info()
8283

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()
8785

86+
integration = client.get_integration(AsyncioIntegration)
87+
if integration is not None:
8888
event, hint = event_from_exception(
8989
exc_info,
9090
client_options=client.options,
9191
mechanism={"type": "asyncio", "handled": False},
9292
)
93-
hub.capture_event(event, hint=hint)
93+
sentry_sdk.capture_event(event, hint=hint)
9494

9595
return exc_info
9696

0 commit comments

Comments
 (0)