22
33from sentry_sdk import start_span
44from sentry_sdk .integrations .socket import SocketIntegration
5- from tests .conftest import ApproxDict
5+ from tests .conftest import ApproxDict , create_mock_http_server
6+
7+ PORT = create_mock_http_server ()
68
79
810def test_getaddrinfo_trace (sentry_init , capture_events ):
911 sentry_init (integrations = [SocketIntegration ()], traces_sample_rate = 1.0 )
1012 events = capture_events ()
1113
1214 with start_span (name = "socket" ):
13- socket .getaddrinfo ("example.com " , 443 )
15+ socket .getaddrinfo ("localhost " , PORT )
1416
1517 (event ,) = events
1618 (span ,) = event ["spans" ]
1719
1820 assert span ["op" ] == "socket.dns"
19- assert span ["description" ] == "example.com:443"
21+ assert span ["description" ] == f"localhost: { PORT } " # noqa: E231
2022 assert span ["data" ] == ApproxDict (
2123 {
22- "host" : "example.com " ,
23- "port" : 443 ,
24+ "host" : "localhost " ,
25+ "port" : PORT ,
2426 }
2527 )
2628
@@ -32,28 +34,28 @@ def test_create_connection_trace(sentry_init, capture_events):
3234 events = capture_events ()
3335
3436 with start_span (name = "socket" ):
35- socket .create_connection (("example.com " , 443 ), timeout , None )
37+ socket .create_connection (("localhost " , PORT ), timeout , None )
3638
3739 (event ,) = events
3840 (connect_span , dns_span ) = event ["spans" ]
3941 # as getaddrinfo gets called in create_connection it should also contain a dns span
4042
4143 assert connect_span ["op" ] == "socket.connection"
42- assert connect_span ["description" ] == "example.com:443"
44+ assert connect_span ["description" ] == f"localhost: { PORT } " # noqa: E231
4345 assert connect_span ["data" ] == ApproxDict (
4446 {
45- "address.host" : "example.com " ,
46- "address.port" : 443 ,
47+ "address.host" : "localhost " ,
48+ "address.port" : PORT ,
4749 "timeout" : timeout ,
4850 }
4951 )
5052
5153 assert dns_span ["op" ] == "socket.dns"
52- assert dns_span ["description" ] == "example.com:443"
54+ assert dns_span ["description" ] == f"localhost: { PORT } " # noqa: E231
5355 assert dns_span ["data" ] == ApproxDict (
5456 {
55- "host" : "example.com " ,
56- "port" : 443 ,
57+ "host" : "localhost " ,
58+ "port" : PORT ,
5759 }
5860 )
5961
@@ -66,7 +68,7 @@ def test_span_origin(sentry_init, capture_events):
6668 events = capture_events ()
6769
6870 with start_span (name = "foo" ):
69- socket .create_connection (("example.com " , 443 ), 1 , None )
71+ socket .create_connection (("localhost " , PORT ), 1 , None )
7072
7173 (event ,) = events
7274
0 commit comments