From c1cbda68be9f14a35806acf73300a77cc063c638 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 23 Jul 2020 13:56:27 +0100 Subject: [PATCH] Use BUGSNAG_RELEASE_STAGE by default Previously we read 'BUGSNAG_RELEASE_STAGE' only in the Rails integration, so other apps had to use 'RACK_ENV' (if they run in Rack) or set it manually in code Now we will always use the 'BUGSNAG_RELEASE_STAGE' environment variable if it's set --- lib/bugsnag/configuration.rb | 1 + lib/bugsnag/integrations/railtie.rb | 2 +- spec/configuration_spec.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index b8e8954f8..bd1b3fc11 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -116,6 +116,7 @@ def initialize self.runtime_versions["ruby"] = RUBY_VERSION self.runtime_versions["jruby"] = JRUBY_VERSION if defined?(JRUBY_VERSION) self.timeout = 15 + self.release_stage = ENV['BUGSNAG_RELEASE_STAGE'] self.notify_release_stages = nil self.auto_capture_sessions = true diff --git a/lib/bugsnag/integrations/railtie.rb b/lib/bugsnag/integrations/railtie.rb index 763ab7f16..cdcf067a3 100644 --- a/lib/bugsnag/integrations/railtie.rb +++ b/lib/bugsnag/integrations/railtie.rb @@ -25,7 +25,7 @@ class Railtie < ::Rails::Railtie # initializer. If not, the key will be validated in after_initialize. Bugsnag.configure(false) do |config| config.logger = ::Rails.logger - config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] || ::Rails.env.to_s + config.release_stage ||= ::Rails.env.to_s config.project_root = ::Rails.root.to_s config.middleware.insert_before Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::Rails3Request config.runtime_versions["rails"] = ::Rails::VERSION::STRING diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 9bc1d5345..8a2a3a942 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -24,6 +24,21 @@ end end + describe "release_stage" do + after(:each) do + ENV["BUGSNAG_RELEASE_STAGE"] = nil + end + + it "has no default value" do + expect(subject.release_stage).to be_nil + end + + it "uses the 'BUGSNAG_RELEASE_STAGE' environment variable if set" do + ENV["BUGSNAG_RELEASE_STAGE"] = "foobar" + expect(subject.release_stage).to eq("foobar") + end + end + describe "#notify_endpoint" do it "defaults to DEFAULT_NOTIFY_ENDPOINT" do expect(subject.notify_endpoint).to eq(Bugsnag::Configuration::DEFAULT_NOTIFY_ENDPOINT)