Skip to content

Commit 19d00c8

Browse files
authored
ref(socket): Use new scopes API (#2915)
1 parent aa92e2e commit 19d00c8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

sentry_sdk/integrations/socket.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import socket
2-
from sentry_sdk import Hub
2+
3+
import sentry_sdk
34
from sentry_sdk._types import MYPY
45
from sentry_sdk.consts import OP
56
from sentry_sdk.integrations import Integration
@@ -47,13 +48,11 @@ def create_connection(
4748
source_address=None,
4849
):
4950
# type: (Tuple[Optional[str], int], Optional[float], Optional[Tuple[Union[bytearray, bytes, str], int]])-> socket.socket
50-
hub = Hub.current
51-
if hub.get_integration(SocketIntegration) is None:
52-
return real_create_connection(
53-
address=address, timeout=timeout, source_address=source_address
54-
)
51+
integration = sentry_sdk.get_client().get_integration(SocketIntegration)
52+
if integration is None:
53+
return real_create_connection(address, timeout, source_address)
5554

56-
with hub.start_span(
55+
with sentry_sdk.start_span(
5756
op=OP.SOCKET_CONNECTION,
5857
description=_get_span_description(address[0], address[1]),
5958
) as span:
@@ -74,11 +73,11 @@ def _patch_getaddrinfo():
7473

7574
def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
7675
# type: (Union[bytes, str, None], Union[str, int, None], int, int, int, int) -> List[Tuple[AddressFamily, SocketKind, int, str, Union[Tuple[str, int], Tuple[str, int, int, int]]]]
77-
hub = Hub.current
78-
if hub.get_integration(SocketIntegration) is None:
76+
integration = sentry_sdk.get_client().get_integration(SocketIntegration)
77+
if integration is None:
7978
return real_getaddrinfo(host, port, family, type, proto, flags)
8079

81-
with hub.start_span(
80+
with sentry_sdk.start_span(
8281
op=OP.SOCKET_DNS, description=_get_span_description(host, port)
8382
) as span:
8483
span.set_data("host", host)

0 commit comments

Comments
 (0)