【问题标题】:Bugsnag: No API key configured, couldn't notify when deployed on herokuBugsnag:未配置 API 密钥,部署在 heroku 上时无法通知
【发布时间】:2016-06-27 12:32:41
【问题描述】:

我在 heroku 上部署了一个标准的 rails 4 应用程序。

我正在尝试向它添加错误。

第一:

宝石文件

gem 'bugsnag'

config/initializers/bugsnag.rb

Bugsnag.configure do |config|
  config.api_key = '<API_KEY_FROM_BUGSNAG_UI>'
end

lib/tasks/test_exception.rake

namespace :myapp do

  desc 'Test task that raises an exception'
  task :test_exception do
    raise 'This is a sample exception'
  end

end
  • 然后我使用git push heroku master 提交、推送和部署
  • 确保 heroku 是最新的 heroku restart

然后heroku run rake myapp:test_exception

=>

Running rake myapp:test_exception on ⬢ myapp... up, run.2877 
W, [2016-06-27T12:23:56.017117 #3]  
WARN -- : ** [Bugsnag] No API key configured, couldn't notify rake aborted! 
This is a sample exception 
/app/lib/tasks/test_exception.rake:9:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/2.2.0/gems/bugsnag-4.2.1/lib/bugsnag/rake.rb:12:in `execute_with_bugsnag' 
Tasks: TOP => jd:sample_exception 
(See full trace by running task with --trace)

我希望 heroku 向 bugsnag 发送异常。我错过了什么?

注意:如果我在本地运行命令,则 bugsnag 集成工作正常(我在 bugsnag UI 中看到异常),例如:rake myapp:test_exception

【问题讨论】:

    标签: ruby-on-rails-4 heroku bugsnag


    【解决方案1】:

    我的任务缺少 :environment,导致 heroku 在执行任务之前加载初始化程序。

    如果我这样重写任务,bugsnag 会收到异常:

    namespace :myapp do
    
      desc 'Test task that raises an exception'
      task test_exception: :environment do # <- added :environment here
        raise 'This is a sample exception'
      end
    
    end
    

    bugsnag 未收到您的错误的另一个原因是,如果您在另一个上下文或测功机中运行。

    例如,在 sidekiq 作业中,您需要使用特定的 gem(参见 Handle exception in Sidekiq 3 jobs)。

    就我而言,我正在使用clockwork 运行后台作业。为了检测它们,我必须执行以下操作(这是特定于发条的):

    # File config/clock.rb
    
    require 'clockwork'
    require './config/boot'
    require './config/environment'
    
    module Clockwork
    
      error_handler do |error|
        Bugsnag.auto_notify(error)
      end
    
      # Check bugsnag is not dead
      every(1.day, 'ping_bugsnag', at: '09:00') do
        raise 'ping bugsnag'
      end
    
      # ... Other jobs here
    
    end
    

    有关更多自定义 bugsnag 检测,请参阅 https://github.com/bugsnag/bugsnag-ruby/blob/master/lib/bugsnag/sidekiq.rb

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 2019-09-30
      • 2014-11-15
      • 2019-11-19
      • 2020-07-24
      • 2017-09-01
      • 2012-08-02
      • 1970-01-01
      相关资源
      最近更新 更多