Subject: Configuration option to ignore certain user agents...
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
+http://www.yoterra.com)" 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.
Support Staff 2 Posted by dcroak on 17 Dec, 2008 06:47 PM
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|
end
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|
end
That UserAgentError would do any kind of analysis you'd like.
Please do share this code back with us if you get it working.
3 Posted by philip on 18 Dec, 2008 05:47 PM
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?
4 Posted by tammersaleh on 18 Dec, 2008 06:08 PM
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.
http://github.com/thoughtbot/hoptoad_notifier
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
5 Posted by philip on 22 Dec, 2008 07:46 PM
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.
-philip
6 Posted by tammersaleh on 23 Dec, 2008 02:31 PM
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:
7 Posted by philip on 23 Dec, 2008 08:01 PM
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.
8 Posted by system on 29 Dec, 2008 06:27 PM
This discussion was assigned to ticket 179.
9 Posted by tammersaleh on 29 Dec, 2008 06:29 PM
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
10 Posted by system on 10 Mar, 2009 03:37 PM
Ticket # 179 was resolved by Nick Quaranto.
Support Staff 11 Posted by thoughtbot on 10 Mar, 2009 04:20 PM
Added the patch and a little blurb into the README about how to use it.
http://github.com/thoughtbot/hoptoad_notifier/commit/2e08e4440d5f1e1c3e9e36faa3ddf98b3feeb00c