Skip to content

Commit

Permalink
ref(socket): Use new scopes API (#2915)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Mar 27, 2024
1 parent aa92e2e commit 19d00c8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions sentry_sdk/integrations/socket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import socket
from sentry_sdk import Hub

import sentry_sdk
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP
from sentry_sdk.integrations import Integration
Expand Down Expand Up @@ -47,13 +48,11 @@ def create_connection(
source_address=None,
):
# type: (Tuple[Optional[str], int], Optional[float], Optional[Tuple[Union[bytearray, bytes, str], int]])-> socket.socket
hub = Hub.current
if hub.get_integration(SocketIntegration) is None:
return real_create_connection(
address=address, timeout=timeout, source_address=source_address
)
integration = sentry_sdk.get_client().get_integration(SocketIntegration)
if integration is None:
return real_create_connection(address, timeout, source_address)

with hub.start_span(
with sentry_sdk.start_span(
op=OP.SOCKET_CONNECTION,
description=_get_span_description(address[0], address[1]),
) as span:
Expand All @@ -74,11 +73,11 @@ def _patch_getaddrinfo():

def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
# 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]]]]
hub = Hub.current
if hub.get_integration(SocketIntegration) is None:
integration = sentry_sdk.get_client().get_integration(SocketIntegration)
if integration is None:
return real_getaddrinfo(host, port, family, type, proto, flags)

with hub.start_span(
with sentry_sdk.start_span(
op=OP.SOCKET_DNS, description=_get_span_description(host, port)
) as span:
span.set_data("host", host)
Expand Down

0 comments on commit 19d00c8

Please sign in to comment.