1
1
import socket
2
- from sentry_sdk import Hub
2
+
3
+ import sentry_sdk
3
4
from sentry_sdk ._types import MYPY
4
5
from sentry_sdk .consts import OP
5
6
from sentry_sdk .integrations import Integration
@@ -47,13 +48,11 @@ def create_connection(
47
48
source_address = None ,
48
49
):
49
50
# 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 )
55
54
56
- with hub .start_span (
55
+ with sentry_sdk .start_span (
57
56
op = OP .SOCKET_CONNECTION ,
58
57
description = _get_span_description (address [0 ], address [1 ]),
59
58
) as span :
@@ -74,11 +73,11 @@ def _patch_getaddrinfo():
74
73
75
74
def getaddrinfo (host , port , family = 0 , type = 0 , proto = 0 , flags = 0 ):
76
75
# 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 :
79
78
return real_getaddrinfo (host , port , family , type , proto , flags )
80
79
81
- with hub .start_span (
80
+ with sentry_sdk .start_span (
82
81
op = OP .SOCKET_DNS , description = _get_span_description (host , port )
83
82
) as span :
84
83
span .set_data ("host" , host )
0 commit comments