Getting Value from ActionController::RoutingError in your Error Tracking System
Photo by Pixabay from Pexels: https://www.pexels.com/photo/monitor-displaying-error-text-270557/

Getting Value from ActionController::RoutingError in your Error Tracking System

ActionController::RoutingError - the error thrown when someone tries to visit a url your rails application is not serving - can be one of the most annoying messages to see in your error tracking system.

If you're running a public internet facing web application, you'll get a flood of bots randomly probing urls (many for exploits), random people making typos in their browser address bars, and malformed shared links (bad copy and paste, emails or text messages chopping up urls).

All these errors are not meaningful and there really isn't anything to address or fix - they mostly end up being false alarms.

Article content

There are many articles that just recommend suppressing these errors by creating a catch all endpoint. This is good for getting rid of the error, but what about being notified about bad links that might exist on your website?

As an alternative, I propose setting up an alert threshold where you can receive alerts if it passes a certain level within a given period of time. If random bots hit random URLs, no error is sent to your error monitoring system while if there are over 1,000 "No route matches [GET] "/css/stylse.css", get alerted to fix the typo in the code.

Rollbar supports Adaptive Alerts which allows you to set a threshold of errors to receive during a certain period of time before alerting, but this is a paid feature only available on advanced and enterprise plans.

We can easily use redis to implement our own thresholds.

Here's how I did this in rollbar in my Ruby on Rails application:

# config/initializers/rollbar.rb

$ROLLBAR_REDIS = Redis.new(host: redis_host, port: redis_port, db: db)

Rollbar.configure do |config|
  ...

  config.exception_level_filters.merge!('ActionController::RoutingError' => lambda do |e|
    route=e.message[17..-1] # strip "No route matches"
    count = $ROLLBAR_REDIS.incr("rollbar:#{route}")
    $ROLLBAR_REDIS.expire("rollbar:#{route}", 1.day.to_i, nx: true) # reset the counter after a day

    if count > 1000 # threshold of events before sending to rollbar
      'warning'
    else
      'ignore'
    end
  end)

  ...
end        

This is pretty primitive, but it works well to bring some value back to RoutingErrors. I recommend this over ignoring RoutingErrors entirely.

To view or add a comment, sign in

More articles by Jonathan Chan

Explore content categories