2016-04-13 30 views

回答

1

看起來你正在使用rollbar-gem,所以你想使用Rollbar::Ignore告訴ROLLBAR忽略由蜘蛛導致的錯誤

handler = proc do |options| 
    raise Rollbar::Ignore if is_crawler_error(options) 
end 

Rollbar.configure do |config| 
    config.before_process << handler 
end 

其中is_crawler_error檢測是否導致錯誤的請求是來自一個爬蟲。

如果使用rollbar.js檢測客戶端JavaScript錯誤,那麼你可以使用checkIgnore選項,以過濾掉造成的殭屍客戶端錯誤:

_rollbarConfig = { 
    // current config... 
    checkIgnore: function(isUncaught, args, payload) { 
    if (window.navigator.userAgent && window.navigator.userAgent.indexOf('Baiduspider') !== -1) { 
     // ignore baidu spider 
     return true; 
    } 
    // no other ignores 
    return false; 
    } 
} 
+0

我可以在哪裏獲得關於is_crawler_error方法的更多細節? –

+0

嗨Alif - 抱歉不清楚這一點 - 你應該自己定義'is_crawler_error'(或任何方法來尋找蜘蛛)。它應該檢查請求上的用戶代理值,並將其與要阻止的已知蜘蛛列表進行比較。 –

+0

來到這裏尋找關於如何實現處理程序忽略某些請求的配方。不知道如果這是一個可接受的答案,如果它是從文檔完整複製粘貼。 –

0

這裏就是我所做的:

is_crawler_error = Proc.new do |options| 
    return true if options[:scope][:request]['From'] == 'bingbot(at)microsoft.com' 
    return true if options[:scope][:request]['From'] == 'googlebot(at)googlebot.com' 
    return true if options[:scope][:request]['User-Agent'] =~ /Facebot Twitterbot/ 
end 

handler = proc do |options| 
    raise Rollbar::Ignore if is_crawler_error.call(options) 
end 

config.before_process << handler 

根據these docs