Trace exceptions through Rack middleware #110
Closed
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.
We're currently running the latest version of the gem in our production Rails 4.2.8 application and in all of our errors in DataDog's UI we see the same stacktrace:
This is not the stacktrace of any of the errors thrown, but simply the callstack of the code that's reporting the error. The reason is because the code is using
caller
to populate the stacktrace andcaller
doesn't have much to do with exceptions. Even when we manually set the error from somewhere in code, that line overrides it with the same callstack, over and over.Examining the code a little closer it looks like it's actually hard to get the right stacktrace from the
ActiveSupport
's instrumentation. Looking at how do other gems get this information (Honeybadger, NewRelic, Sentry), it looks to us like using a custom middleware layer is the way to go.For us this also means we'll be able to trace errors thrown from our API layer, where we use Grape; Grape reuses the same Rack middleware stack, but does not go through ActiveController so we currently don't have a simple way of tracing those errors.
In order to make this change, we've changed some of the tests from being
ActionController::TestCase
to beActionDispatch::IntegrationTest
. The latter are said to be slower, but the former don't go through the middleware stack so the tests were failing.Let us know your thoughts on this. Thanks!