π¨ Rails Error Notifier β Ruby Gem for Error Monitoring in Rails
Rails Error Notifier is an open-source Ruby gem for Rails 6+ applications that automatically captures unhandled exceptions and sends instant notifications. It integrates with Slack, Discord, Email, and WhatsApp (Twilio) so your team is immediately alerted to production errors.
π RubyGems page | π Source code on GitHub
β¨ Features
- π₯ Automatic error capturing in Rails via Rack middleware.
- π© Send error notifications to:
- Slack
- Discord
- WhatsApp (via Twilio API)
- βοΈ Easy setup with Rails generator.
- π Add custom context (current user, request path, environment).
- π‘οΈ Safe failover (wonβt crash if webhooks or configs are missing).
- π§© Works seamlessly with Rails 6, Rails 7, and above, and supports Ruby 2.0+.
π¦ Installation
Add this line to your Gemfile
:
gem 'rails_error_notifier'
Install the gem:
bundle install
Or install manually:
gem install rails_error_notifier
βοΈ Configuration
Generate initializer:
bin/rails generate rails_error_notifier:install
This creates config/initializers/rails_error_notifier.rb
:
RailsErrorNotifier.configure do |config|
# Slack + Discord
config.slack_webhook = ENV["SLACK_WEBHOOK_URL"] # "https://hooks.slack.com/services/T000/B000/XXXX"
config.discord_webhook = ENV["DISCORD_WEBHOOK_URL"] # "https://discord.com/api/webhooks/1234567890/abcXYZ"
# Email
config.error_email_to = ENV["ERROR_EMAIL_TO"] # e.g. "dev-team@example.com"
config.error_email_from = ENV["ERROR_EMAIL_FROM"] # e.g. "notifier@example.com"
# WhatsApp (via Twilio)
config.twilio_sid = ENV["TWILIO_SID"] #"AC1234567890abcdef1234567890abcd"
config.twilio_token = ENV["TWILIO_TOKEN"] #"your_auth_token_here"
config.twilio_from = ENV["TWILIO_FROM"] #"+14155552671"
config.twilio_to = ENV["TWILIO_TO"] # "whatsapp:+919876543210"
# Enable in production only
config.enabled = !Rails.env.development? && !Rails.env.test?
end
π Usage
Automatic Error Notifications
Rails middleware will automatically send alerts for any unhandled exception.
Manual Error Notifications
begin
risky_operation
rescue => e
RailsErrorNotifier.notify(e, context: { user_id: current_user.id, path: request.path })
end
π Example Notifications
Slack
π¨ Rails Error Notifier
Message: undefined method `foo' for nil:NilClass
Context: {:user_id=>42, :path=>"/dashboard"}
Discord
β‘ Rails Error Notifier
Error: PG::ConnectionBad
Message: could not connect to server: Connection refused
Context: {:host=>"db.example.com", :env=>"production"}
π§ͺ Development & Testing
Clone and setup:
git clone https://github.com/mrmalvi/rails_error_notifier.git
cd rails_error_notifier
bundle install
Run specs:
bundle exec rspec
Build gem locally:
bundle exec rake install
Release a version:
bundle exec rake release
π€ Contributing
Contributions, bug reports, and pull requests are welcome! See issues.
π License
Released under the MIT License.
π SEO Keywords
Rails error notifier gem, Ruby gem for error logging, Slack error notification Rails, Discord error notification Rails, Rails exception tracker, Rails monitoring gem, Ruby on Rails error reporting.