Configuration option to ignore certain user agents...

seattlesouthside's Avatar


16 Dec, 2008 07:16 PM

It would be cool if within hoptoad I could configure it to silently discard errors whose user agent (or any of the common fields maybe) matched a certain regex. I get some errors from a user agent "Mozilla/5.0 (compatible; heritrix/1.14.2 +" which are not worth fixing. That agent is simply botching urls and mangling them and trying to get lucky.

If I could just make those go away it would be nice.

  1. 2 Posted by Dan Croak on 17 Dec, 2008 06:47 PM

    Dan Croak's Avatar

    Hi Philip,

    Hoptoad ignores the following exceptions by default:

    ActiveRecord::RecordNotFound ActionController::RoutingError ActionController::InvalidAuthenticityToken CGI::Session::CookieStore::TamperedWithCookie

    To ignore errors in addition to those, specify their names in your Hoptoad configuration block.

    HoptoadNotifier.configure do |config|

    config.api_key      = '1234567890abcdef'
    config.ignore       << ActiveRecord::IgnoreThisError


    So, if you create a custom error class for your user agent errors (UserAgentError < Exception), you could then add it to your config/initializers/hoptoad.rb:

    HoptoadNotifier.configure do |config|

    config.api_key      = '1234567890abcdef'
    config.ignore       << UserAgentError


    That UserAgentError would do any kind of analysis you'd like.

    Please do share this code back with us if you get it working.

  2. 3 Posted by seattlesouthside on 18 Dec, 2008 05:47 PM

    seattlesouthside's Avatar

    I'm probably just not seeing it, but how would creating my own exception help? The exception that is getting raised comes from Rails (not me) and in one case is just "RuntimeError". Using the steps above wouldn't I have to catch all of those exceptions, evaluate the user agent, and then throw my own error which hoptoad could then catch? Or am I not reading things correctly (very possible :) ?

    If I am though, would you mind if I modified the plugin to add a similar "ignore" concept, but have it work on ENV? So in the configure block I could say something like:

    config.ignore_env << {'HTTP_USER_AGENT' => /some-bad-agent/}

    I know I can do it myself and it will work for this one project, but if I did something like that would you guys want the code?

  3. 4 Posted by tammersaleh on 18 Dec, 2008 06:08 PM

    tammersaleh's Avatar

    Hi Philip,

    I think you're right in that for this particular case, adding a custom
    exception class for the plugin to ignore would not be of any use to you.

    We're always very happy to see contributions to the hoptoad notifier.
    The notifier is on github, and can be forked/modified/etc as per any
    github project.

    The only thing we ask is that instead of sending us a pull request,
    you attach a patch (or reference a github url) in a new issue here,
    under the Hoptoad Notifier category.

    Cheers, Tammer

  4. 5 Posted by seattlesouthside on 22 Dec, 2008 07:46 PM

    seattlesouthside's Avatar

    Tammer -

    I've got it working, but wanted to get your input on how the
    configuration should work. I've simplified my goal to only deal with
    user agents as it occurs to me most of the ENV variables are static so
    not as useful to filter on.

    Right now you do this:

    config.ignore_user_agent = "MSIE|Googlebot"

    That gets converted into a Regexp in the code. Questions for you
    about your preference. Which of the below do you like best?

    config.ignore_user_agent = "string?" config.ignore_user_agent = /regexp?/ config.ignore_user_agent << "array of regexps?"

    The last one reads better and matches the existing ignore
    configuration option, but then again some folks might want to optimize
    the regexp themselves...

    Let me know what you think and I'll adjust it and kick you over a patch.


  5. 6 Posted by tammersaleh on 23 Dec, 2008 02:31 PM

    tammersaleh's Avatar

    Hi Philip,

    I think that the following would be good:

    config.ignore_user_agent << "String" config.ignore_user_agent << /regexp/

    So the ignore_user_agent parameter would be an array of either strings
    or regexps, and would default to the empty set.

    Thanks again for tackling this. I'm sure there are other Hoptoad
    users that will find this useful.

    Cheers, Tammer

    On Dec 22, 2008, at 1:46 PM, Tender Support wrote:

  6. 7 Posted by seattlesouthside on 23 Dec, 2008 08:01 PM

    seattlesouthside's Avatar

    Tammer -

    I've got it working using the "<<" and taking strings or regexp's. Tried to mirror the existing "ignore" functionality as best I could including setting up the DEFAULTs, etc. Patch is attached.

  7. 8 Posted by System on 29 Dec, 2008 06:27 PM

    System's Avatar

    This discussion was assigned to ticket 179.

  8. 9 Posted by tammersaleh on 29 Dec, 2008 06:29 PM

    tammersaleh's Avatar

    Hi Philip,

    Just letting you know that we've created an internal ticket for this, and we'll be adding your patch as soon as we have a chance.

    Thanks again for the contribution. Tammer

  9. 10 Posted by System on 10 Mar, 2009 03:37 PM

    System's Avatar

    Ticket # 179 was resolved by Nick Quaranto.

  10. 11 Posted by Nick Quaranto on 10 Mar, 2009 04:20 PM

    Nick Quaranto's Avatar

    Added the patch and a little blurb into the README about how to use it.

  11. Jonathan Siegel closed this discussion on 06 Nov, 2011 09:45 AM.

  12. Support Staff 12 Posted by Jonathan Siegel on 06 Nov, 2011 10:09 AM

    Jonathan Siegel's Avatar

    We are closing this as there has been no activity for over 60 days. Please re-open if the problem persists.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac