Skip to content

Commit 4de8902

Browse files
jdmajorgreys
authored andcommitted
bottle: fix query string embedded in URL (#921)
There was no test checking that the query string was not part of the URL and it was actually added. Fix that and add proper testing.
1 parent 79c1415 commit 4de8902

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ddtrace/contrib/bottle/trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def wrapped(*args, **kwargs):
5454
raise
5555
finally:
5656
s.set_tag(http.STATUS_CODE, code or response.status_code)
57-
s.set_tag(http.URL, request.url)
57+
s.set_tag(http.URL, request.urlparts._replace(query='').geturl())
5858
s.set_tag(http.METHOD, request.method)
5959

6060
return wrapped

tests/contrib/bottle/test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ def _trace_app(self, tracer=None):
3434
self.app.install(TracePlugin(service=SERVICE, tracer=tracer))
3535
self.app = webtest.TestApp(self.app)
3636

37-
def test_200(self):
37+
def test_200(self, query_string=''):
38+
if query_string:
39+
fqs = '?' + query_string
40+
else:
41+
fqs = ''
42+
3843
# setup our test app
3944
@self.app.route('/hi/<name>')
4045
def hi(name):
4146
return 'hi %s' % name
4247
self._trace_app(self.tracer)
4348

4449
# make a request
45-
resp = self.app.get('/hi/dougie')
50+
resp = self.app.get('/hi/dougie' + fqs)
4651
assert resp.status_int == 200
4752
assert compat.to_unicode(resp.body) == u'hi dougie'
4853
# validate it's traced
@@ -60,6 +65,12 @@ def hi(name):
6065
services = self.tracer.writer.pop_services()
6166
assert services == {}
6267

68+
def test_query_string(self):
69+
return self.test_200('foo=bar')
70+
71+
def test_query_string_multi_keys(self):
72+
return self.test_200('foo=bar&foo=baz&x=y')
73+
6374
def test_500(self):
6475
@self.app.route('/hi')
6576
def hi():

0 commit comments

Comments
 (0)