bugsnag-ruby: Difficulty configuring Bugsnag in Rails before it configures itself

Here’s an example initializer in Rails:

# config/initializers/bugsnag.rb
puts "Bugsnag initializer reached"
Bugsnag.configure do |config|
  config.logger = Logger.new("/dev/null")
  config.api_key = ENV.fetch("BUGSNAG_API_KEY")
end

The Bugsnag ready message gets logged before this initializer runs:

$ rails c
** [Bugsnag] Bugsnag exception handler 5.5.0 ready
Bugsnag initializer reached
Loading development environment (Rails 5.1.4)

I want to change the Bugsnag logger and/or explicitly configure Bugsnag myself. I do not want the gem to try to automatically detect its own configuration. What is the correct way to do this in Rails and other Ruby environments when using Gemfiles/Rubygems to load this gem?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

We’re currently noticing similar behavior where the Railtie before_initialize runs prior to our Bugsnag initializer which sets the API key. This means on every boot of a non-development environment we see the No valid API key has been set, notifications will not be sent message.

@jfelchner a change has been made into how the API key validity is logged, which will be released shortly. This will fix the issues as noted here.

Can we reopen this issue until this gets fixed?

@csuhta I don’t want to disable autoconfiguration, I just don’t want a warning telling me that my API key is not valid when I’m setting my API key in the initializer.