rails_error_notifier 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/rubyonrails.yml +26 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +160 -0
- data/Rakefile +8 -0
- data/lib/generators/rails_error_notifier/install_generator.rb +16 -0
- data/lib/generators/rails_error_notifier/templates/rails_error_notifier.rb +11 -0
- data/lib/rails_error_notifier/configuration.rb +9 -0
- data/lib/rails_error_notifier/middleware.rb +14 -0
- data/lib/rails_error_notifier/notifier.rb +35 -0
- data/lib/rails_error_notifier/railtie.rb +9 -0
- data/lib/rails_error_notifier/version.rb +5 -0
- data/lib/rails_error_notifier.rb +19 -0
- data/sig/rails_error_notifier.rbs +4 -0
- data/test/test_helper.rb +6 -0
- data/test/test_rails_error_notifier.rb +13 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e043018bdbcd628ab70a6da7152c49045be430fbdbe84b3abbb24cb9731f31ec
|
4
|
+
data.tar.gz: '021292217b6100ea47d1660e21c2f19e19b703fea4b2d4b8662241ce2cdb6e7c'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4aaa456e26009a3ce7dbfc8afd7c7ef5d18f576385707d2c825841e2f4efa9872aef813ff77cbaeb54e3e9514c8aae603dbe6b622aeb8077b3bdbb7435d47e85
|
7
|
+
data.tar.gz: 977f95bc1c6ed0db06a1567d458c08c41f34eeabae9e6ff773b0d90adf4774505c3df8f98c48c3ae90e94f9d5ea25e1da07f6555cc227dbc02e4fcbf48d6d080
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@78c01b705fd9d5ad960d432d3a0cfa341d50e410 # v1.179.1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.2.0
|
20
|
+
bundler-cache: true
|
21
|
+
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install
|
24
|
+
|
25
|
+
- name: Run RSpec tests
|
26
|
+
run: bundle exec rspec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 mrmalvi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# 🚨 RailsErrorNotifier
|
2
|
+
|
3
|
+
RailsErrorNotifier is a Ruby gem that automatically captures and notifies about errors in your Rails applications.
|
4
|
+
It integrates with **Slack** and **Discord** out of the box, so you never miss a critical error in production.
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
## ✨ Features
|
9
|
+
- 🔥 Capture unhandled exceptions in Rails automatically via Rack middleware.
|
10
|
+
- 📩 Send error notifications to **Slack** and **Discord**.
|
11
|
+
- ⚙️ Easy configuration through Rails initializers.
|
12
|
+
- 📝 Add custom context (e.g., current user, request path).
|
13
|
+
- 🛡️ Safe when disabled (no crashes if webhooks are missing).
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
## 📦 Installation
|
18
|
+
|
19
|
+
Add this line to your application's `Gemfile`:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rails_error_notifier', git: 'https://github.com/mrmalvi/rails_error_notifier.git'
|
23
|
+
```
|
24
|
+
|
25
|
+
Then execute:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
Or install it manually:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
gem install rails_error_notifier
|
35
|
+
```
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
## ⚙️ Configuration
|
40
|
+
|
41
|
+
Generate an initializer in your Rails app:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
bin/rails generate rails_error_notifier:install
|
45
|
+
```
|
46
|
+
|
47
|
+
This creates `config/initializers/rails_error_notifier.rb`:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# frozen_string_literal: true
|
51
|
+
|
52
|
+
RailsErrorNotifier.configure do |config|
|
53
|
+
# Configure your Slack and Discord webhooks via ENV variables
|
54
|
+
config.slack_webhook = ENV["SLACK_WEBHOOK_URL"]
|
55
|
+
config.discord_webhook = ENV["DISCORD_WEBHOOK_URL"]
|
56
|
+
|
57
|
+
# Optional: disable in development/test
|
58
|
+
config.enabled = !Rails.env.development? && !Rails.env.test?
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
---
|
63
|
+
|
64
|
+
## 🚀 Usage
|
65
|
+
|
66
|
+
### Automatic Error Notifications
|
67
|
+
Once installed, `RailsErrorNotifier` automatically hooks into Rails middleware.
|
68
|
+
Whenever an exception occurs, a notification is sent to your configured services.
|
69
|
+
|
70
|
+
### Manual Notifications
|
71
|
+
```ruby
|
72
|
+
begin
|
73
|
+
risky_operation
|
74
|
+
rescue => e
|
75
|
+
RailsErrorNotifier.notify(e, context: { user_id: current_user.id, path: request.path })
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
---
|
80
|
+
|
81
|
+
## 🔔 Example Notifications
|
82
|
+
|
83
|
+
### Slack
|
84
|
+
```
|
85
|
+
🚨 Rails Error Notifier
|
86
|
+
Message: undefined method `foo' for nil:NilClass
|
87
|
+
Context: {:user_id=>42, :path=>"/dashboard"}
|
88
|
+
Backtrace:
|
89
|
+
app/controllers/dashboard_controller.rb:12:in `index'
|
90
|
+
```
|
91
|
+
|
92
|
+
### Discord
|
93
|
+
```
|
94
|
+
⚡ Rails Error Notifier
|
95
|
+
Error: PG::ConnectionBad
|
96
|
+
Message: could not connect to server: Connection refused
|
97
|
+
Context: {:host=>"db.example.com", :env=>"production"}
|
98
|
+
```
|
99
|
+
|
100
|
+
---
|
101
|
+
|
102
|
+
## 🧪 Testing & Development
|
103
|
+
|
104
|
+
Clone the repository and install dependencies:
|
105
|
+
|
106
|
+
```bash
|
107
|
+
git clone https://github.com/mrmalvi/rails_error_notifier.git
|
108
|
+
cd rails_error_notifier
|
109
|
+
bundle install
|
110
|
+
```
|
111
|
+
|
112
|
+
Run the test suite:
|
113
|
+
|
114
|
+
```bash
|
115
|
+
bundle exec rspec
|
116
|
+
```
|
117
|
+
|
118
|
+
Start an interactive console to experiment:
|
119
|
+
|
120
|
+
```bash
|
121
|
+
bin/console
|
122
|
+
```
|
123
|
+
|
124
|
+
Build and install the gem locally:
|
125
|
+
|
126
|
+
```bash
|
127
|
+
bundle exec rake install
|
128
|
+
```
|
129
|
+
|
130
|
+
Release a new version (update `version.rb` first):
|
131
|
+
|
132
|
+
```bash
|
133
|
+
bundle exec rake release
|
134
|
+
```
|
135
|
+
|
136
|
+
This will:
|
137
|
+
- Create a Git tag for the version
|
138
|
+
- Push commits and tags
|
139
|
+
- Publish the `.gem` file to [rubygems.org](https://rubygems.org)
|
140
|
+
|
141
|
+
---
|
142
|
+
|
143
|
+
## 🤝 Contributing
|
144
|
+
|
145
|
+
Contributions are welcome!
|
146
|
+
|
147
|
+
1. Fork the repo
|
148
|
+
2. Create a new branch (`git checkout -b my-feature`)
|
149
|
+
3. Commit your changes (`git commit -am 'Add feature'`)
|
150
|
+
4. Push to the branch (`git push origin my-feature`)
|
151
|
+
5. Open a Pull Request
|
152
|
+
|
153
|
+
Bug reports and pull requests are welcome on GitHub:
|
154
|
+
👉 [https://github.com/mrmalvi/rails_error_notifier](https://github.com/mrmalvi/rails_error_notifier)
|
155
|
+
|
156
|
+
---
|
157
|
+
|
158
|
+
## 📜 License
|
159
|
+
|
160
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# lib/generators/rails_error_notifier/install_generator.rb
|
2
|
+
require "rails/generators"
|
3
|
+
|
4
|
+
module RailsErrorNotifier
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
desc "Creates a RailsErrorNotifier initializer in config/initializers"
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template "rails_error_notifier.rb", "config/initializers/rails_error_notifier.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is the initializer for RailsErrorNotifier
|
4
|
+
RailsErrorNotifier.configure do |config|
|
5
|
+
# Configure your Slack and Discord webhooks via ENV variables
|
6
|
+
config.slack_webhook = ENV["SLACK_WEBHOOK_URL"]
|
7
|
+
config.discord_webhook = ENV["DISCORD_WEBHOOK_URL"]
|
8
|
+
|
9
|
+
# Optional: disable in development/test
|
10
|
+
config.enabled = !Rails.env.development? && !Rails.env.test?
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module RailsErrorNotifier
|
5
|
+
class Notifier
|
6
|
+
attr_reader :exception, :context
|
7
|
+
|
8
|
+
def initialize(exception, context = {})
|
9
|
+
@exception = exception
|
10
|
+
@context = context
|
11
|
+
end
|
12
|
+
|
13
|
+
def deliver
|
14
|
+
return unless RailsErrorNotifier.configuration&.enabled
|
15
|
+
|
16
|
+
payload = {
|
17
|
+
error: exception.message,
|
18
|
+
backtrace: exception.backtrace,
|
19
|
+
context: context
|
20
|
+
}
|
21
|
+
|
22
|
+
send_to_webhook(RailsErrorNotifier.configuration.slack_webhook, payload)
|
23
|
+
send_to_webhook(RailsErrorNotifier.configuration.discord_webhook, payload)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def send_to_webhook(url, payload)
|
29
|
+
return unless url
|
30
|
+
|
31
|
+
uri = URI(url)
|
32
|
+
Net::HTTP.post(uri, payload.to_json, "Content-Type" => "application/json")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rails_error_notifier/configuration"
|
2
|
+
require "rails_error_notifier/notifier"
|
3
|
+
require "rails_error_notifier/middleware"
|
4
|
+
require "rails_error_notifier/railtie" if defined?(Rails::Railtie)
|
5
|
+
|
6
|
+
module RailsErrorNotifier
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield(configuration) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.notify(exception, context: {})
|
17
|
+
Notifier.new(exception, context).deliver
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class TestRailsErrorNotifier < Minitest::Test
|
6
|
+
def test_that_it_has_a_version_number
|
7
|
+
refute_nil ::RailsErrorNotifier::VERSION
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_it_does_something_useful
|
11
|
+
assert false
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_error_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mrmalvi
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: A gem to send Rails exceptions to Slack and Discord
|
13
|
+
email:
|
14
|
+
- malviyak00@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".github/workflows/rubyonrails.yml"
|
20
|
+
- ".ruby-version"
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/generators/rails_error_notifier/install_generator.rb
|
25
|
+
- lib/generators/rails_error_notifier/templates/rails_error_notifier.rb
|
26
|
+
- lib/rails_error_notifier.rb
|
27
|
+
- lib/rails_error_notifier/configuration.rb
|
28
|
+
- lib/rails_error_notifier/middleware.rb
|
29
|
+
- lib/rails_error_notifier/notifier.rb
|
30
|
+
- lib/rails_error_notifier/railtie.rb
|
31
|
+
- lib/rails_error_notifier/version.rb
|
32
|
+
- sig/rails_error_notifier.rbs
|
33
|
+
- test/test_helper.rb
|
34
|
+
- test/test_rails_error_notifier.rb
|
35
|
+
homepage: https://github.com/mrmalvi/rails_error_notifier
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata:
|
39
|
+
allowed_push_host: https://rubygems.org
|
40
|
+
homepage_uri: https://github.com/mrmalvi/rails_error_notifier
|
41
|
+
source_code_uri: https://github.com/mrmalvi/rails_error_notifier
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.5.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.6.9
|
57
|
+
specification_version: 4
|
58
|
+
summary: Notify Rails errors to Slack and Discord
|
59
|
+
test_files: []
|