2
2
3
3
from sentry_sdk import start_transaction
4
4
from 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 ()
6
8
7
9
8
10
def test_getaddrinfo_trace (sentry_init , capture_events ):
9
11
sentry_init (integrations = [SocketIntegration ()], traces_sample_rate = 1.0 )
10
12
events = capture_events ()
11
13
12
14
with start_transaction ():
13
- socket .getaddrinfo ("example.com " , 443 )
15
+ socket .getaddrinfo ("localhost " , PORT )
14
16
15
17
(event ,) = events
16
18
(span ,) = event ["spans" ]
17
19
18
20
assert span ["op" ] == "socket.dns"
19
- assert span ["description" ] == "example.com:443"
21
+ assert span ["description" ] == f"localhost: { PORT } " # noqa: E231
20
22
assert span ["data" ] == ApproxDict (
21
23
{
22
- "host" : "example.com " ,
23
- "port" : 443 ,
24
+ "host" : "localhost " ,
25
+ "port" : PORT ,
24
26
}
25
27
)
26
28
@@ -32,28 +34,28 @@ def test_create_connection_trace(sentry_init, capture_events):
32
34
events = capture_events ()
33
35
34
36
with start_transaction ():
35
- socket .create_connection (("example.com " , 443 ), timeout , None )
37
+ socket .create_connection (("localhost " , PORT ), timeout , None )
36
38
37
39
(event ,) = events
38
40
(connect_span , dns_span ) = event ["spans" ]
39
41
# as getaddrinfo gets called in create_connection it should also contain a dns span
40
42
41
43
assert connect_span ["op" ] == "socket.connection"
42
- assert connect_span ["description" ] == "example.com:443"
44
+ assert connect_span ["description" ] == f"localhost: { PORT } " # noqa: E231
43
45
assert connect_span ["data" ] == ApproxDict (
44
46
{
45
- "address" : ["example.com " , 443 ],
47
+ "address" : ["localhost " , PORT ],
46
48
"timeout" : timeout ,
47
49
"source_address" : None ,
48
50
}
49
51
)
50
52
51
53
assert dns_span ["op" ] == "socket.dns"
52
- assert dns_span ["description" ] == "example.com:443"
54
+ assert dns_span ["description" ] == f"localhost: { PORT } " # noqa: E231
53
55
assert dns_span ["data" ] == ApproxDict (
54
56
{
55
- "host" : "example.com " ,
56
- "port" : 443 ,
57
+ "host" : "localhost " ,
58
+ "port" : PORT ,
57
59
}
58
60
)
59
61
@@ -66,7 +68,7 @@ def test_span_origin(sentry_init, capture_events):
66
68
events = capture_events ()
67
69
68
70
with start_transaction (name = "foo" ):
69
- socket .create_connection (("example.com " , 443 ), 1 , None )
71
+ socket .create_connection (("localhost " , PORT ), 1 , None )
70
72
71
73
(event ,) = events
72
74
0 commit comments