Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rails error msg,stack,type to rack spans #1124

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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