Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rails): Log missing key warning after Rails initialization completes #444

Merged
merged 3 commits into from
Apr 6, 2018

Conversation

kattrali
Copy link
Contributor

When not initializing using the BUGSNAG_API_KEY environment variable,
the first time the Railtie integration is loaded, no API key is
available. At the bottom of the configure method, a warning is emitted
stating that no API key has been set, though this may not be true after
config/initializers/bugsnag.rb runs. This is the behavior being observed
in #391, causing concern that bugsnag is not working correctly when in
fact the log message is premature.

This change allows for Bugsnag.configure to be called without validating
the key, allowing the Railtie integration to add an additional check
once Rails initialization is complete.

Fixes #391

@kattrali kattrali requested a review from a team March 31, 2018 01:20
@@ -69,6 +69,7 @@ class Railtie < Rails::Railtie
end
end
end
Bugsnag.configure(true) # Validate API key is set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dont even need this because the previous configure will also validate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't another configure call if the generator was never run.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one above I mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you mean the immediately preceding line? Yes, that would be more logical.

@kattrali kattrali force-pushed the kattrali/fix-rails-init-warning branch 2 times, most recently from 06aad0d to a168884 Compare April 5, 2018 21:01
@kattrali kattrali force-pushed the kattrali/fix-rails-init-warning branch 6 times, most recently from cddf5f7 to 6d8f71f Compare April 6, 2018 06:09
When not initializing using the BUGSNAG_API_KEY environment variable,
the first time the Railtie integration is loaded, no API key is
available. At the bottom of the configure method, a warning is emitted
stating that no API key has been set, though this may not be true after
config/initializers/bugsnag.rb runs. This is the behavior being observed
in #391, causing concern that bugsnag is not working correctly when in
fact the log message is premature.

This change allows for Bugsnag.configure to be called without validating
the key, allowing the Railtie integration to add an additional check
once Rails initialization is complete.

Fixes #391
@kattrali kattrali force-pushed the kattrali/fix-rails-init-warning branch from 6d8f71f to 8389d2b Compare April 6, 2018 06:25
Copy link
Contributor

@martin308 martin308 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggestions/comments inline

@@ -37,14 +37,10 @@ class << self
# Configure the Bugsnag notifier application-wide settings.
#
# Yields a configuration object to use to set application settings.
def configure
def configure(validate_api_key=true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a named parameter as calling configure(false|true) is not obvious what it will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting Ruby 1.9.3 makes this difficult as 2.0.0 introduced named parameters. It could potentially be something for the next major release.

@@ -36,7 +36,7 @@ class Railtie < Rails::Railtie

config.before_initialize do
# Configure bugsnag rails defaults
Bugsnag.configure do |config|
Bugsnag.configure(false) do |config|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment might be good to explain why we are not validating the key here

end
expect(@logger.logs.size).to eq(0)
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth adding similar test cases for when we pass in the new method parameter in these scenarios?

expect(output).to include(key_warning)
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test in here where the env variable is provided but is not a valid api key and configure is not called might be a good addition

@kattrali kattrali force-pushed the kattrali/fix-rails-init-warning branch from 3ae6f7a to e7533e6 Compare April 6, 2018 22:44
@kattrali kattrali force-pushed the kattrali/fix-rails-init-warning branch from e7533e6 to 50c0525 Compare April 6, 2018 22:52
@kattrali kattrali merged commit beedcbe into master Apr 6, 2018
@kattrali kattrali deleted the kattrali/fix-rails-init-warning branch April 6, 2018 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants