[Rails] Sentry/Raven "works" but doesn't automatically report exceptions

Hey there,

I’ve setup Sentry for Rails, using the guide, but seem to not be getting any errors coming across into the Sentry UI.

Have set it up as such:

app/config/application.rb

module CoolAppName
  class Application < Rails::Application
    ...
    
    Raven.configure do |config|
      config.dsn = ENV['SENTRY_SECRET_DSN_URL']
    end
    
    ...
  end
end

app/config/initializers.rb

Raven.configure do |config|
  config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
end

Testing that it actually works manually, and connect using the config, using Rails console, is all good:

2.3.1 :001 > Raven.capture do
2.3.1 :003 >   1 / 0
2.3.1 :004?> end
Sending event f9a116a4d90c45dc9058134bc46f71c6 to Sentry
Raven HTTP Transport connecting to https://sentry.io
ZeroDivisionError: divided by 0

So that’s all good, but when I create an exception normally, through Rails in any environment (such as a failed GET to a non existent page), nothing is “Automatically” sent to Sentry?

eg: A failed GET 404 to test it out:

Started GET "/blaldlalsdlassl" for ::1 at 2017-04-15 11:00:53 +1000
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
User excluded error: #<ActionController::RoutingError: No route matches [GET] "/blaldlalsdlassl">

ActionController::RoutingError (No route matches [GET] "/blaldlalsdlassl"):

actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
sentry-raven (2.4.0) lib/raven/integrations/rack.rb:50:in `call'
railties (5.0.1) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
  Rendering /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
  Rendering /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms)
  Rendered collection of /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/routes/_route.html.erb [39 times] (11.7ms)
  Rendered /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/routes/_table.html.erb (7.9ms)
  Rendering /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (9.5ms)
  Rendered /Users/jonesleemac/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (102.0ms)

But this exception appears no-where in the Sentry UI?

This is the same story in Production environment.

If this is because Sentry excludes a standard 404 error, what errors could I use to test that Sentry is recording errors correctly?

Cheers,

Nick

You are correct that raven-ruby ignores ActionController::RoutingError by default. This can be seen in lib/raven/configuration.rb:

  1. The IGNORE_DEFAULT collection
  2. The excluded_exceptions setting

If you were to temporarily add

  config.excluded_exceptions = []

to your Raven.configure block, you would see that error be sent to Sentry in production.

@bcobb awesome! Thanks for confirming this, thought it was going crazy with this one and it wasn’t working!

Any ideas how to test out the JS Raven on the front end in a client?

Cheers,

@nickooolas I don’t have recent enough experience with the JS client to answer off the top, but I wouldn’t be surprised if similar configuration options existed!