-
Notifications
You must be signed in to change notification settings - Fork 120
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
Add exception_notification gem #1740
Conversation
Since this adds a new entry to |
5d70d7a
to
bfe2cc9
Compare
And here is what is included inside in the email:
|
config.add_notifier( | ||
:email, | ||
email_prefix: "[#{APP_NAME} EXCEPTION] ", | ||
sender_address: %("Exception Notifier" <[email protected]>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we i18n any of these, or make them configurable in application.yml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, doesn't seem worth it to to i18n? but it would probably be worth it to build the email address via the mail gem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say more. I haven't used the mail gem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can build this format of string programatically (which is useful if there are spaces or unicode)
require 'mail'
=> true
Mail::Address.new('[email protected]').tap { |a| a.display_name = 'fooooo barrrr' }.to_s
=> "fooooo barrrr <[email protected]>"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm misunderstanding, but is there a problem with the way the current sender address is implemented? I tested it with SES and it works fine. In what situations would the current implementation be problematic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case we wanted to make the email configurable without interpolation or escaping? It's not a big deal.
ExceptionNotification.configure do |config| | ||
config.add_notifier( | ||
:email, | ||
email_prefix: "[#{APP_NAME} EXCEPTION] ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add the environment in the prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat out of scope, but this would also be good to do in other places where we use APP_NAME, such as OTPs and user email. It would be good to be able to distinguish environments based on the received messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like you can add the current host in the subject. We'll need to submit a pull request to the gem. The gem currently only supports adding the controller name and action, and configuring whether or not the exception appears in the subject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait. We don't need the request to get the host name. We can read from Figaro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here: 7225dc5
config/application.yml.example
Outdated
@@ -9,6 +9,7 @@ | |||
# Figaro requires all values to be explicit strings. | |||
|
|||
email_from: '[email protected]' | |||
exception_recipients: '["[email protected]", "[email protected]"]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a comma separated string and then use split(',')
instead of JSON.parse
in the initializer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to say "yes".
ExceptionNotification.configure do |config| | ||
config.add_notifier( | ||
:email, | ||
email_prefix: "[#{APP_NAME} EXCEPTION - #{Figaro.env.domain_name}] ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still doesn't have the environment? We won't be able to tell staging apart from production?
We can use LoginGov::Hostdata.env
for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain_name
is unique per environment. In production, it is secure.login.gov
. In staging, it is idp.staging.login.gov
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Zach that it may be easier to read at a glance if we have the name of the env instead of the URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, by env
, you mean the short name, like staging
, dev
, int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here: 7a67adb
require 'exception_notification/rails' | ||
require 'exception_notification/sidekiq' | ||
|
||
EXCEPTION_RECIPIENTS = JSON.parse(Figaro.env.exception_recipients).freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks if Figaro.env.exception_recipients
is nil. Any thoughts on changing this up so that it works if exception_recipients
is nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently a required Figaro key, so it can't be nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but we need to make sure we've added the config before we merge.
@monfresh: I took the liberty of opening a devops PR to add the config https://github.com/18F/identity-devops/pull/663 |
Thank you, sir! |
**Why**: To allow us to receive real-time notifications via email any time an error occurs in production. The gem also has support for other notification channels, such as Slack. It also captures Sidekiq errors out of the box. Using this gem is a lot easier and cheaper than maintaining a self-hosted version of Sentry or Bugsnag, for example. Visit the gem's repo for more configuration options: https://github.com/smartinez87/exception_notification
7a67adb
to
1ce93e3
Compare
The devops PR has been merged. Can we merge this now, or should we wait until we've populated the config with some emails? |
Let's add the config now lest we forget later. |
Why: To allow us to receive real-time notifications via email
any time an error occurs in production. The gem also has support for
other notification channels, such as Slack. It also captures Sidekiq
errors out of the box.
Using this gem is a lot easier and cheaper than maintaining
a self-hosted version of Sentry or Bugsnag, for example.
Visit the gem's repo for more configuration options:
https://github.com/smartinez87/exception_notification