Skip to content

Commit 081ca98

Browse files
author
Emanuele Palazzetti
committed
[pylons] add tests for the Exception re-raise regression
1 parent 349ea35 commit 081ca98

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ddtrace/contrib/pylons/middleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _start_response(status, *args, **kwargs):
4040
try:
4141
return self.app(environ, _start_response)
4242
except Exception as e:
43-
# "unexpected errors"
43+
# store current exceptions info so we can re-raise it later
4444
(typ, val, tb) = sys.exc_info()
4545

4646
# e.code can either be a string or an int
@@ -53,7 +53,8 @@ def _start_response(status, *args, **kwargs):
5353
code = 500
5454
span.set_tag(http.STATUS_CODE, code)
5555
span.error = 1
56-
# Re-raise the original exception with its original traceback
56+
57+
# re-raise the original exception with its original traceback
5758
raise typ, val, tb
5859
except SystemExit:
5960
span.set_tag(http.STATUS_CODE, 500)

tests/contrib/pylons/test_pylons.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def test_pylons():
7777
eq_(s.meta.get(http.STATUS_CODE), '200')
7878

7979
def test_pylons_exceptions():
80+
# ensures the reported status code is 500 even if a wrong
81+
# status code is set and that the stacktrace points to the
82+
# right function
8083
writer = DummyWriter()
8184
tracer = Tracer()
8285
tracer.writer = writer
@@ -107,10 +110,10 @@ def test_pylons_exceptions():
107110
s = spans[0]
108111

109112
eq_(s.error, 1)
110-
eq_(s.get_tag("error.msg"), "Some exception")
111-
sc = int(s.get_tag("http.status_code"))
112-
eq_(sc, 500)
113-
ok_(s.get_tag("error.stack"))
113+
eq_(s.get_tag('error.msg'), 'Some exception')
114+
eq_(int(s.get_tag('http.status_code')), 500)
115+
ok_('start_response_exception' in s.get_tag('error.stack'))
116+
ok_('Exception: Some exception' in s.get_tag('error.stack'))
114117

115118
def test_pylons_string_code():
116119
writer = DummyWriter()

0 commit comments

Comments
 (0)