我在我的Rails应用程序中使用Sidekiq和Airbrake。 我希望Airbrake能够捕获Sidekiq工作期间发生的任何错误。 根据我在网上找到的说明,我在sidekiq.rb中添加了以下内容:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }然后Airbrake能够在我的开发环境中发现错误。 但是,一旦我部署到更高的环境,Airbrake就无法捕获Sidekiq错误。 有什么理由会发生这种情况吗? 我需要在我的应用程序中配置什么?
我正在使用sidekiq gem版本〜> 3.0.2,airbrake gem版本〜> 4.0.0,以及rails 3.2.18
这是我的完整sidekiq.rb:
require 'sidekiq' require 'sidekiq-status' redis_connection = "redis://127.0.0.1:6379/0" Sidekiq.configure_server do |config| config.redis = { :url => redis_connection, :namespace => 'sidekiq' } config.server_middleware do |chain| chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes end config.client_middleware do |chain| chain.add Sidekiq::Status::ClientMiddleware end config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) } end Sidekiq.configure_client do |config| config.redis = { :url => redis_connection, :namespace => 'sidekiq' } config.client_middleware do |chain| chain.add Sidekiq::Status::ClientMiddleware end end这是我的完整airbrake.rb:
Airbrake.configure do |config| config.user_attributes = [:id, :email] config.api_key = '*my_api_key*' endI'm using Sidekiq and Airbrake in my Rails application. I would like Airbrake to catch any errors that occur during Sidekiq jobs. As per instructions I found online, I've added the following to sidekiq.rb:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }Airbrake then was able to catch errors when they occurred in my development environment. However, once I deployed to a higher environment, Airbrake stopped being able to catch Sidekiq errors. Is there any reason this would happen? Is there anything else I need to configure inside my app?
I'm using sidekiq gem version ~>3.0.2, airbrake gem version ~>4.0.0, and rails 3.2.18
Here is my full sidekiq.rb:
require 'sidekiq' require 'sidekiq-status' redis_connection = "redis://127.0.0.1:6379/0" Sidekiq.configure_server do |config| config.redis = { :url => redis_connection, :namespace => 'sidekiq' } config.server_middleware do |chain| chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes end config.client_middleware do |chain| chain.add Sidekiq::Status::ClientMiddleware end config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) } end Sidekiq.configure_client do |config| config.redis = { :url => redis_connection, :namespace => 'sidekiq' } config.client_middleware do |chain| chain.add Sidekiq::Status::ClientMiddleware end endAnd here is my full airbrake.rb:
Airbrake.configure do |config| config.user_attributes = [:id, :email] config.api_key = '*my_api_key*' end最满意答案
事实证明,如果您的应用程序也使用橡胶,那么您还必须更改橡胶sidekiq初始化程序(config / rubber / common / initializers / sidekiq)以包含该行:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }橡胶sidekiq初始化程序用于所有非开发环境,而sidekiq.rb文件用于开发环境。
It turns out that if your app is also using rubber, then you also have to change your rubber sidekiq initializer (config/rubber/common/initializers/sidekiq) to include the line:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }The rubber sidekiq initializer is used for all non-development environments, whereas the sidekiq.rb file is used for development environment.
更多推荐
发布评论