Skip to content

Commit

Permalink
Merge pull request #1124 from DataDog/add_rails_errors_to_rack
Browse files Browse the repository at this point in the history
Add rails error msg,stack,type to rack spans
  • Loading branch information
ericmustin authored Jul 29, 2020
2 parents f6eb36d + 2046d90 commit 82001c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def finish_processing(payload)
span.status = 1 if status.starts_with?('5')
elsif Utils.exception_is_error?(exception)
span.set_error(exception)

# Some exception gets handled by Rails middleware before it can be set on Rack middleware
# The rack span is the root span of the request and should make sure it has the full exception
# set on it.
if env[:datadog_rack_request_span]
env[:datadog_rack_request_span].set_error(exception)
end
end
ensure
span.finish
Expand Down
23 changes: 23 additions & 0 deletions test/contrib/rails/rack_middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,27 @@ class FullStackTest < ActionDispatch::IntegrationTest
assert_equal(request_span.get_tag('http.status_code'), '404')
assert_equal(request_span.status, 0)
end

test 'the rack span has all exception span tags set on rails ActionView Errors' do
get '/error_partial'

assert_response :error

# get spans
assert_operator(spans.length, :>=, 2, 'there should be at least 2 span')

rack_span = spans.first
controller_span = spans.last

# Rack span
assert_equal(rack_span.status, 1)
assert_equal(rack_span.get_tag('error.type'), 'ActionView::Template::Error')
refute_nil(rack_span.get_tag('error.stack'))
refute_nil(rack_span.get_tag('error.msg'))
refute_equal(rack_span.resource, controller_span.resource) # We expect the resource hasn't been overriden

# Controller span
assert_equal(controller_span.status, 1, 'span should be flagged as an error')
assert_equal(controller_span.get_tag('error.type'), 'ActionView::Template::Error')
end
end

0 comments on commit 82001c9

Please sign in to comment.