Add rails error msg,stack,type to rack spans #1124
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds instrumentation to propagate Rails partial errors such as
ActionView::Template::Error
to the rack span. Currently the error details from this error will get set on the relevant Rails ActionController and ActionView spans, but not on the rack span which is the root of the trace.Here's an example of this behavior:
The rack span gets set to
error:true
only because the status response code is>= 500
, but lacks the relevant error info.The underlying reason why these errors don't propagate to the Rails and Rack Middleware that dd-trace-rb instrumentation inserts is due to the default production behavior of the rails config setting
action_dispatch.show_exceptions
and theActionDispatch::ShowExceptions
middleware that the tracing middleware is inserted afterlink
Since
action_dispatch.show_exceptions
in practice defaults to true in production (technically it's unset in prod, butshow_exceptions?
explicitly checks if it'sfalse
.), The error gets swallowed before the Contrib::Rails::ErrorMiddlleware or the higher level Rack instrumentation can catch/re-raise it.By propagating the error to the Rack span from the
ActionController
, we work around this constraint.One tradeoff here is that, this might mean that if there's custom error handling middleware inserted in the Action Dispatcher middleware stack, we might not be honoring it by pre-emptively setting the rack span to be the same error as the actioncontroller.