Skip to content

Commit

Permalink
Merge pull request #176 from matt/pyramid-errs
Browse files Browse the repository at this point in the history
Pyramid errors
  • Loading branch information
Emanuele Palazzetti authored Feb 15, 2017
2 parents 5f5b2ab + d97e2d4 commit 1572712
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ namespace :pypi do
FileUtils.rm_rf(RELEASE_DIR)
end

task :install do
sh 'pip install twine'
end

task :build => :clean do
puts "building release in #{RELEASE_DIR}"
sh "python setup.py -q sdist -d #{RELEASE_DIR}"
end

task :release => :build do
task :release => [:install, :build] do
builds = Dir.entries(RELEASE_DIR).reject {|f| f == '.' || f == '..'}
if builds.length == 0
fail "no build found in #{RELEASE_DIR}"
Expand Down
3 changes: 2 additions & 1 deletion ddtrace/contrib/pyramid/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def trace_tween(request):
# set response tags
if response:
span.set_tag(http.STATUS_CODE, response.status_code)
span.error = 500 <= response.status_code < 600
if 500 <= response.status_code < 600:
span.error = 1
return response
return trace_tween

Expand Down
7 changes: 7 additions & 0 deletions ddtrace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def to_dict(self):
'error': self.error,
}

# a common mistake is to set the error field to a boolean instead of an
# int. let's special case that here, because it's sure to happen in
# customer code.
err = d.get('error')
if err and type(err) == bool:
d['error'] = 1

if self.start:
d['start'] = int(self.start * 1e9) # ns

Expand Down
1 change: 1 addition & 0 deletions tests/contrib/pyramid/test_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_500():
eq_(s.span_type, 'http')
eq_(s.meta.get('http.status_code'), '500')
eq_(s.meta.get('http.url'), '/error')
assert type(s.error) == int

def test_json():
app, tracer = _get_test_app(service='foobar')
Expand Down
13 changes: 13 additions & 0 deletions tests/test_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def test_span_to_dict():
eq_(d["parent_id"], s.parent_id)
eq_(d["meta"], {"a": "1", "b": "2"})
eq_(d["type"], "foo")
eq_(d["error"], 0)
eq_(type(d["error"]), int)

def test_span_boolean_err():
s = Span(tracer=None, name="foo.bar", service="s", resource="r")
s.error = True
s.finish()

d = s.to_dict()
assert d
eq_(d["error"], 1)
eq_(type(d["error"]), int)



class DummyTracer(object):
Expand Down

0 comments on commit 1572712

Please sign in to comment.