Skip to content

Commit d0740a0

Browse files
committed
requests: handle empty paths
1 parent 0d416da commit d0740a0

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

ddtrace/contrib/requests/patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def _apply_tags(span, method, url, response):
5757
parsed = urlparse.urlparse(url)
5858
span.service = parsed.netloc
5959
# FIXME[matt] how do we decide how do we normalize arbitrary urls???
60-
span.resource = "%s %s" % (method.upper(), parsed.path)
60+
path = parsed.path or "/"
61+
span.resource = "%s %s" % (method.upper(), path)
6162
except Exception:
6263
pass
6364

tests/contrib/requests/test_requests.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
class TestRequests(object):
1313

1414
@staticmethod
15-
def test_resources():
16-
# ensure all valid combinations of args / kwargs work
15+
def test_resource_path():
1716
tracer, session = get_traced_session()
1817
out = session.get('http://httpstat.us/200')
1918
eq_(out.status_code, 200)
@@ -22,6 +21,23 @@ def test_resources():
2221
s = spans[0]
2322
eq_(s.resource, 'GET /200')
2423

24+
@staticmethod
25+
def test_resource_empty_path():
26+
tracer, session = get_traced_session()
27+
out = session.get('http://httpstat.us')
28+
eq_(out.status_code, 200)
29+
spans = tracer.writer.pop()
30+
eq_(len(spans), 1)
31+
s = spans[0]
32+
eq_(s.resource, 'GET /')
33+
34+
out = session.get('http://httpstat.us/')
35+
eq_(out.status_code, 200)
36+
spans = tracer.writer.pop()
37+
eq_(len(spans), 1)
38+
s = spans[0]
39+
eq_(s.resource, 'GET /')
40+
2541
@staticmethod
2642
def test_tracer_disabled():
2743
# ensure all valid combinations of args / kwargs work

0 commit comments

Comments
 (0)