Skip to content

Commit

Permalink
[rack]: fix rubocop for rack error setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmustin committed Sep 1, 2020
1 parent bb65188 commit 8addf5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions lib/ddtrace/contrib/rails/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ def call(env)
rescue Exception => e
tracer = Datadog.configuration[:rails][:tracer]
span = tracer.active_span
unless span.nil?
if !span.nil? && ActionPack::Utils.exception_is_error?(e)
# Only set error if it's supposed to be flagged as such
# e.g. we don't want to flag 404s.
# You can add custom errors via `config.action_dispatch.rescue_responses`
if ActionPack::Utils.exception_is_error?(e)
span.set_error(e)
span.set_error(e)

# 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.
env[:datadog_rack_request_span].set_error(e) if env[:datadog_rack_request_span]
end
# 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.
env[:datadog_rack_request_span].set_error(e) if env[:datadog_rack_request_span]
end
raise e
end
Expand Down
2 changes: 1 addition & 1 deletion test/contrib/rails/apps/controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ApplicationController < ActionController::Base; end

class TracingController < ActionController::Base
rescue_from 'ActionController::RenderError' do
rescue_from 'ActionController::RenderError' do
render 'views/tracing/index.html.erb'
end

Expand Down
3 changes: 1 addition & 2 deletions test/contrib/rails/rack_middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ class FullStackTest < ActionDispatch::IntegrationTest
assert_equal(request_span.status, 0, 'rack span should not be flagged as an error')
assert_nil(request_span.get_tag('error.type'))
assert_nil(request_span.get_tag('error.msg'))
assert_nil(request_span.get_tag('error.stack'))
assert_nil(request_span.get_tag('error.stack'))
end


test 'custom error controllers should not override trace resource names' do
# Simulate an error being passed to the exception controller
# (Syntax depends on Rails integration test version)
Expand Down

0 comments on commit 8addf5e

Please sign in to comment.