Updated Rack/Rails span error setting behavior #1162
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 addresses #1155 , when a user modifies or handles a Rails Controller exception in a
rescue_from
block. Since adding #1124, the instrumentation has been setting any rails errors upstream on the rack span. However, in cases where these exceptions get swallowed, or re-raised with a different exception, in arescue_from
, this causes the rack span to contain stale information, since we haven't been accounting forrescue_from
in our current rails instrumentation.By moving the rails => rack span upstream error propagation from the
action_controller
instrumentation, and into the datadog railsexception_middleware
, we ensure we're modifying the rack span as late as possible before the exception information is swallowed by rails internal exception handling. This means that we are not going to incorrectly set a handled exception on the rack span.Long term, adding more explicit instrumentation of the
rescue_from
code blocks (perhaps by patchingActionController::Rescue.process_action
) and Controller before/after hooks would also cover the above use case, but it's a little unclear what that would look like (are they child spans of the controller? part of the controller? child spans of rack? etc) and how to safely test and handle all the edge cases that come with that in a way we could release reliably. For now, the priority of this PR is to ensure the rack spans are not receiving stale error information.