Airbrake没有在开发之外的环境中捕获Rails应用程序中Sidekiq的错误(Airbrake not catching errors for Sidekiq in Rails app on a

编程入门 行业动态 更新时间:2024-10-24 12:21:42
Airbrake没有在开发之外的环境中捕获Rails应用程序中Sidekiq的错误(Airbrake not catching errors for Sidekiq in Rails app on an environment other than development)

我在我的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*' end

I'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 end

And 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.

更多推荐

本文发布于:2023-07-08 20:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   错误   环境   Sidekiq   Airbrake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!