Skip to content

Commit ea76599

Browse files
committed
fix some tests
1 parent e4a9827 commit ea76599

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

elasticapm/instrumentation/packages/urllib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ def call(self, module, method, wrapped, instance, args, kwargs):
9898
self._set_disttracing_headers(request_object, trace_parent, transaction)
9999
response = wrapped(*args, **kwargs)
100100
if response:
101+
status = getattr(response, "status", None) or response.getcode() # Python 2 compat
101102
if span.context:
102-
span.context["http"]["status_code"] = response.status
103-
span.set_success() if response.status < 400 else span.set_failure()
103+
span.context["http"]["status_code"] = status
104+
span.set_success() if status < 400 else span.set_failure()
104105
return response
105106

106107
def mutate_unsampled_call_args(self, module, method, wrapped, instance, args, kwargs, transaction):

tests/instrumentation/asyncio/aiohttp_client_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def test_http_get(instrument, event_loop, elasticapm_client, waiting_https
6262
assert span["subtype"] == "http"
6363
assert span["sync"] is False
6464
assert span["context"]["http"]["url"] == waiting_httpserver.url
65-
assert span["context"]["http"]["status_code"] == 200
65+
assert span["context"]["http"]["status_code"] == 204
6666
assert spans[0]["context"]["destination"]["service"] == {
6767
"name": "http://127.0.0.1:%d" % waiting_httpserver.server_address[1],
6868
"resource": "127.0.0.1:%d" % waiting_httpserver.server_address[1],

tests/instrumentation/urllib_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
getresponse_method = "http.client.HTTPConnection.getresponse"
4646
except ImportError:
4747
from urllib2 import urlopen
48-
from urllib2 import URLError
48+
from urllib2 import URLError, HTTPError
4949

5050
request_method = "httplib.HTTPConnection.request"
5151
getresponse_method = "httplib.HTTPConnection.getresponse"

0 commit comments

Comments
 (0)