|
1 | 1 | import random
|
2 | 2 | from http.client import HTTPConnection, HTTPSConnection
|
| 3 | +from socket import SocketIO |
3 | 4 | from urllib.request import urlopen
|
4 | 5 | from unittest import mock
|
5 | 6 |
|
@@ -342,3 +343,35 @@ def test_span_origin(sentry_init, capture_events):
|
342 | 343 |
|
343 | 344 | assert event["spans"][0]["op"] == "http.client"
|
344 | 345 | assert event["spans"][0]["origin"] == "auto.http.stdlib.httplib"
|
| 346 | + |
| 347 | + |
| 348 | +def test_http_timeout(monkeypatch, sentry_init, capture_envelopes): |
| 349 | + mock_readinto = mock.Mock(side_effect=TimeoutError) |
| 350 | + monkeypatch.setattr(SocketIO, "readinto", mock_readinto) |
| 351 | + |
| 352 | + sentry_init(traces_sample_rate=1.0) |
| 353 | + |
| 354 | + envelopes = capture_envelopes() |
| 355 | + |
| 356 | + with start_transaction(op="op", name="name"): |
| 357 | + try: |
| 358 | + conn = HTTPSConnection("www.squirrelchasers.com") |
| 359 | + conn.request("GET", "/top-chasers") |
| 360 | + conn.getresponse() |
| 361 | + except Exception: |
| 362 | + pass |
| 363 | + |
| 364 | + items = [ |
| 365 | + item |
| 366 | + for envelope in envelopes |
| 367 | + for item in envelope.items |
| 368 | + if item.type == "transaction" |
| 369 | + ] |
| 370 | + assert len(items) == 1 |
| 371 | + |
| 372 | + transaction = items[0].payload.json |
| 373 | + assert len(transaction["spans"]) == 1 |
| 374 | + |
| 375 | + span = transaction["spans"][0] |
| 376 | + assert span["op"] == "http.client" |
| 377 | + assert span["description"] == "GET https://www.squirrelchasers.com/top-chasers" |
0 commit comments