rusen 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -23
- data/README.md +100 -110
- data/Rakefile +1 -12
- data/lib/rusen.rb +6 -2
- data/lib/rusen/middleware/rusen_rack.rb +8 -14
- data/lib/rusen/middleware/rusen_sidekiq.rb +15 -2
- data/lib/rusen/notifier.rb +2 -2
- data/lib/rusen/notifiers.rb +18 -13
- data/lib/rusen/notifiers/base_notifier.rb +36 -3
- data/lib/rusen/settings.rb +24 -7
- data/lib/rusen/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18a8ccbea67e8e8184a57efb47503278bf4879c
|
4
|
+
data.tar.gz: e8d36b8b4b9ab007e9680706adfdfcf806a5506e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fadc00a89b991a47da2460a9dacb3a360b47ca0549d03c9a7f0636e7aaa82e0ba4f4ce07e59100eecaee2f53c94a5d790f02188a9c22ef6e9a49887ec6b34b2e
|
7
|
+
data.tar.gz: ab9c7a8bf899b43dcd09cdb2a26e2651578c1c200d7b8475d1629f7a425372119088ccd58d9fa8e4040f23e6dbb3d0dad0fd139c51e65d2fc8d362fea25036cc
|
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
-
|
4
|
-
|
5
|
-
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [Unreleased](https://github.com/moove-it/rusen/tree/HEAD)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/moove-it/rusen/compare/v0.0.2...HEAD)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Allow sendmail [\#9](https://github.com/moove-it/rusen/issues/9)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Adding a png logo to use on the README.md [\#17](https://github.com/moove-it/rusen/pull/17) ([elpic](https://github.com/elpic))
|
14
|
+
- Update CI settings [\#16](https://github.com/moove-it/rusen/pull/16) ([adrian-gomez](https://github.com/adrian-gomez))
|
15
|
+
- New Rusen page [\#15](https://github.com/moove-it/rusen/pull/15) ([imNicoSuarez](https://github.com/imNicoSuarez))
|
16
|
+
- Allow to omit the optional arguments without errors in Rusen.notify [\#14](https://github.com/moove-it/rusen/pull/14) ([shhavel](https://github.com/shhavel))
|
17
|
+
- Change RusenRack to take into account :filter\_parameters option. [\#13](https://github.com/moove-it/rusen/pull/13) ([snmgian](https://github.com/snmgian))
|
18
|
+
- Not sending sensitive data on notifications [\#12](https://github.com/moove-it/rusen/pull/12) ([elpic](https://github.com/elpic))
|
19
|
+
- Add support for sidekiq. [\#11](https://github.com/moove-it/rusen/pull/11) ([adrian-gomez](https://github.com/adrian-gomez))
|
20
|
+
- Add email\_via setting. [\#10](https://github.com/moove-it/rusen/pull/10) ([adrian-gomez](https://github.com/adrian-gomez))
|
21
|
+
- Allow sending an instance of Rusen::Settings to the middleware [\#7](https://github.com/moove-it/rusen/pull/7) ([elpic](https://github.com/elpic))
|
22
|
+
- Mail notifier [\#6](https://github.com/moove-it/rusen/pull/6) ([pboling](https://github.com/pboling))
|
23
|
+
- Just housekeeping. [\#5](https://github.com/moove-it/rusen/pull/5) ([pboling](https://github.com/pboling))
|
24
|
+
- Add log4r support. [\#4](https://github.com/moove-it/rusen/pull/4) ([snmgian](https://github.com/snmgian))
|
25
|
+
- Fix Rusen::Notifier\#notifty default params. [\#3](https://github.com/moove-it/rusen/pull/3) ([snmgian](https://github.com/snmgian))
|
26
|
+
- Fix tests, minor refactoring. [\#2](https://github.com/moove-it/rusen/pull/2) ([snmgian](https://github.com/snmgian))
|
27
|
+
- improve some sintax and wording for README [\#1](https://github.com/moove-it/rusen/pull/1) ([ssuttner](https://github.com/ssuttner))
|
28
|
+
|
29
|
+
## [v0.0.2](https://github.com/moove-it/rusen/tree/v0.0.2) (2013-01-28)
|
30
|
+
[Full Changelog](https://github.com/moove-it/rusen/compare/v0.0.1...v0.0.2)
|
31
|
+
|
32
|
+
## [v0.0.1](https://github.com/moove-it/rusen/tree/v0.0.1) (2013-01-28)
|
33
|
+
|
34
|
+
|
35
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -1,23 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a href="http://moove-it.github.io/rusen/">
|
3
|
+
<img src="https://moove-it.github.io/rusen/images/logo.png" alt="Rusen" />
|
4
|
+
</a>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p align="center">
|
8
|
+
<a href="https://badge.fury.io/rb/rusen">
|
9
|
+
<img src="https://badge.fury.io/rb/rusen.png" alt="Gem Version">
|
10
|
+
</a>
|
11
|
+
<a href="https://codeclimate.com/github/Moove-it/rusen">
|
12
|
+
<img src="https://codeclimate.com/github/Moove-it/rusen.png" alt="Code Climate">
|
13
|
+
</a>
|
14
|
+
<a href="https://travis-ci.org/moove-it/rusen">
|
15
|
+
<img src="https://secure.travis-ci.org/moove-it/rusen.png?branch=master" alt="Build Status">
|
16
|
+
</a>
|
17
|
+
<a href="https://coveralls.io/github/moove-it/rusen?branch=master">
|
18
|
+
<img src="https://coveralls.io/repos/moove-it/rusen/badge.svg?branch=master&service=github" alt="Coverage Status">
|
19
|
+
</a>
|
20
|
+
<a href="https://inch-ci.org/github/moove-it/rusen">
|
21
|
+
<img src="https://inch-ci.org/github/moove-it/rusen.svg?branch=master" alt="Documentation Coverage">
|
22
|
+
</a>
|
23
|
+
<a href="http://www.rubydoc.info/github/moove-it/rusen">
|
24
|
+
<img src="https://img.shields.io/badge/yard-docs-blue.svg" alt="Documentation">
|
25
|
+
</a>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
The Ruby Simple Exception Notification (a.k.a Rusen) gem provides a simple way for logging and sending errors in any Ruby application.
|
29
|
+
|
30
|
+
Notifications include information about the current request, session, environment. They also provide a backtrace of the exception.
|
21
31
|
|
22
32
|
Installation
|
23
33
|
---
|
@@ -36,25 +46,25 @@ Usage
|
|
36
46
|
The easiest way to use it is with global configuration.
|
37
47
|
|
38
48
|
First you configure Rusen
|
49
|
+
|
39
50
|
```ruby
|
40
51
|
require 'rusen'
|
41
52
|
|
42
|
-
Rusen.settings.
|
43
|
-
Rusen.settings.
|
44
|
-
Rusen.settings.email_prefix = '[ERROR] '
|
45
|
-
Rusen.settings.sender_address = 'some_email@example.com'
|
46
|
-
Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
|
53
|
+
Rusen.settings.sender_address = 'oops@example.org'
|
54
|
+
Rusen.settings.exception_recipients = %w(dev_team@example.org)
|
47
55
|
Rusen.settings.smtp_settings = {
|
48
56
|
:address => 'smtp.gmail.com',
|
49
57
|
:port => 587,
|
50
58
|
:domain => 'example.org',
|
51
59
|
:authentication => :plain,
|
52
|
-
:user_name => 'dev_team@
|
60
|
+
:user_name => 'dev_team@example.org',
|
53
61
|
:password => 'xxxxxxx',
|
54
62
|
:enable_starttls_auto => true
|
55
63
|
}
|
56
64
|
```
|
57
|
-
|
65
|
+
|
66
|
+
And then you can start sending notifications:
|
67
|
+
|
58
68
|
```ruby
|
59
69
|
begin
|
60
70
|
method.call
|
@@ -62,54 +72,42 @@ rescue Exception => exception
|
|
62
72
|
Rusen.notify(exception)
|
63
73
|
end
|
64
74
|
```
|
65
|
-
|
75
|
+
|
76
|
+
This way, if you modify the notifications settings at runtime, every notification sent afterwards will use the new
|
77
|
+
settings.
|
66
78
|
|
67
79
|
### With local configuration
|
68
80
|
|
69
|
-
This method lets you have more control when notifying. You may want for example to send an email when a particular
|
81
|
+
This method lets you have more control when notifying. You may want for example to send an email when a particular
|
82
|
+
exception occurs and just print to stdout otherwise.
|
70
83
|
To achieve this you can do the following:
|
84
|
+
|
71
85
|
```ruby
|
72
|
-
@
|
73
|
-
|
74
|
-
|
75
|
-
@
|
76
|
-
|
77
|
-
@
|
78
|
-
@email_settings.smtp_settings = {
|
79
|
-
:address => 'smtp.gmail.com',
|
80
|
-
:port => 587,
|
81
|
-
:domain => 'example.org',
|
82
|
-
:authentication => :plain,
|
83
|
-
:user_name => 'dev_team@moove-it.com',
|
84
|
-
:password => 'xxxxxxx',
|
85
|
-
:enable_starttls_auto => true
|
86
|
-
}
|
87
|
-
|
88
|
-
@email_notifier = Notifier.new(@email_settings)
|
89
|
-
|
90
|
-
@stdout_settings = Settings.new
|
91
|
-
@stdout_settings.outputs = settings[:io]
|
92
|
-
Rusen.settings.sections = [:backtrace]
|
93
|
-
|
94
|
-
@stdout_notifier = Notifier.new(@stdout_settings)
|
86
|
+
@email_notifier = Rusen::Notifier.new(@email_settings)
|
87
|
+
|
88
|
+
@stdout_settings = Rusen::Settings.new
|
89
|
+
@stdout_settings.outputs = [:backtrace]
|
90
|
+
|
91
|
+
@stdout_notifier = Rusen::Notifier.new(@stdout_settings)
|
95
92
|
```
|
93
|
+
|
96
94
|
and then:
|
97
95
|
```ruby
|
98
96
|
begin
|
99
97
|
method.call
|
100
98
|
rescue SmallException => exception
|
101
99
|
@stdout_notifier.notify(exception)
|
102
|
-
rescue BigException => exception
|
103
|
-
@email_notifier.notify(exception)
|
104
100
|
end
|
105
101
|
```
|
106
102
|
|
107
103
|
Middleware
|
108
104
|
---
|
109
|
-
Rusen comes with a
|
105
|
+
Rusen comes with a Rack and rails special (soon to come) middleware for easy usage.
|
110
106
|
|
111
107
|
### Rack
|
112
|
-
To use Rusen in any
|
108
|
+
To use Rusen in any Rack application you just have to add the following code somewhere in your app
|
109
|
+
(ex: config/initializers/rusen.rb):
|
110
|
+
|
113
111
|
```ruby
|
114
112
|
require 'rusen/middleware/rusen_rack'
|
115
113
|
|
@@ -117,56 +115,71 @@ use Rusen::Middleware::RusenRack,
|
|
117
115
|
:outputs => [:io, :email],
|
118
116
|
:sections => [:backtrace, :request, :session, :environment],
|
119
117
|
:email_prefix => '[ERROR] ',
|
120
|
-
:sender_address => '
|
121
|
-
:exception_recipients => %w(dev_team@example.
|
118
|
+
:sender_address => 'oops@example.org',
|
119
|
+
:exception_recipients => %w(dev_team@example.org),
|
122
120
|
:smtp_settings => {
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
121
|
+
:address => 'smtp.gmail.com',
|
122
|
+
:port => 587,
|
123
|
+
:domain => 'example.org',
|
124
|
+
:authentication => :plain,
|
125
|
+
:user_name => 'dev_team@example.org',
|
126
|
+
:password => 'xxxxxxx',
|
127
|
+
:enable_starttls_auto => true
|
128
|
+
}
|
131
129
|
```
|
130
|
+
|
132
131
|
This will capture any unhandled exception, send an email and write a trace in stdout.
|
133
132
|
|
134
133
|
Settings
|
135
134
|
---
|
135
|
+
|
136
136
|
### Outputs
|
137
|
-
Currently supported outputs are :io, :lo4r, :pony and :mail. More outputs are easy to add so you can customize Rusen to your needs.
|
138
137
|
|
139
|
-
|
138
|
+
Currently supported outputs are :io, :lo4r, :pony and :mail. More outputs are easy to add so you can customize Rusen to
|
139
|
+
your needs.
|
140
|
+
|
141
|
+
Note: :io will only print to stdout for the time being, but there are plans to extend it to anything that Ruby::IO
|
142
|
+
supports.
|
140
143
|
|
141
144
|
Pony, lo4r and Mail outputs require additional gems to work.
|
142
145
|
|
143
|
-
To use
|
146
|
+
To use Pony add this to your Gemfile:
|
147
|
+
|
144
148
|
```ruby
|
145
149
|
gem 'pony'
|
146
150
|
```
|
147
151
|
|
148
|
-
To use mail add this to your Gemfile:
|
152
|
+
To use mail, add this to your Gemfile:
|
153
|
+
|
149
154
|
```ruby
|
150
155
|
gem 'mail'
|
151
156
|
```
|
152
157
|
|
153
|
-
To use log4r add this to your Gemfile:
|
158
|
+
To use log4r, add this to your Gemfile:
|
159
|
+
|
154
160
|
```ruby
|
155
161
|
gem 'log4r'
|
156
162
|
```
|
157
163
|
|
158
164
|
### Sections
|
165
|
+
|
159
166
|
You can choose the output sections simply by setting the appropriate values in the configuration.
|
160
167
|
|
161
168
|
### Exclude if
|
169
|
+
|
162
170
|
Here you can pass a block that will receive the error. If the block returns false, then the error will be notified.
|
163
171
|
|
164
172
|
### Email settings
|
165
|
-
|
173
|
+
|
174
|
+
All the email settings are self explanatory, but you can contact hello+rusen@moove-it.com if any of them needs clarification.
|
175
|
+
|
176
|
+
If you are running Rusen inside **Rails** and you have configured smtp_settings for your app
|
177
|
+
Rusen will use that settings by default.
|
166
178
|
|
167
179
|
### Log4r settings
|
180
|
+
|
168
181
|
* logger_name _(required)_: Logger used for logging errors.
|
169
|
-
* log4r_config_file _(optional)_: YAML file that contains Log4r configuration.
|
182
|
+
* log4r_config_file _(optional)_: YAML file that contains Log4r configuration.
|
170
183
|
|
171
184
|
Sample of Log4r configuration file contents:
|
172
185
|
|
@@ -191,22 +204,26 @@ log4r_config:
|
|
191
204
|
|
192
205
|
Sidekiq
|
193
206
|
---
|
207
|
+
|
194
208
|
Rusen comes with sidekiq integration builtin to use just add this to your sidekiq initializer:
|
209
|
+
|
195
210
|
```ruby
|
196
211
|
require 'rusen/sidekiq'
|
197
212
|
```
|
198
|
-
|
213
|
+
|
214
|
+
You can configure it with the global Rusen configuration, ex:
|
215
|
+
|
199
216
|
```ruby
|
200
217
|
require 'rusen/sidekiq'
|
201
218
|
|
202
|
-
Rusen.settings.sender_address = '
|
203
|
-
Rusen.settings.exception_recipients = %w(dev_team@example.
|
219
|
+
Rusen.settings.sender_address = 'oops@example.org'
|
220
|
+
Rusen.settings.exception_recipients = %w(dev_team@example.org)
|
204
221
|
Rusen.settings.smtp_settings = {
|
205
222
|
:address => 'smtp.gmail.com',
|
206
223
|
:port => 587,
|
207
224
|
:domain => 'example.org',
|
208
225
|
:authentication => :plain,
|
209
|
-
:user_name => 'dev_team@
|
226
|
+
:user_name => 'dev_team@example.org',
|
210
227
|
:password => 'xxxxxxx',
|
211
228
|
:enable_starttls_auto => true
|
212
229
|
}
|
@@ -214,17 +231,9 @@ Rusen.settings.smtp_settings = {
|
|
214
231
|
|
215
232
|
Rusen supports versions ~> 2 and ~> 3 of sidekiq.
|
216
233
|
|
217
|
-
Extending to more outputs
|
218
|
-
---
|
219
|
-
Soon to come!
|
220
|
-
|
221
|
-
## Authors
|
222
|
-
|
223
|
-
Adrian Gomez is the author of the code, and current maintainer.
|
224
|
-
|
225
234
|
## Contributors
|
226
235
|
|
227
|
-
See the [Network View](https://github.com/
|
236
|
+
See the [Network View](https://github.com/moove-it/rusen/network) and the [CHANGELOG](https://github.com/moove-it/rusen/blob/master/CHANGELOG.md)
|
228
237
|
|
229
238
|
## Contributing
|
230
239
|
|
@@ -232,31 +241,12 @@ See the [Network View](https://github.com/Moove-it/rusen/network) and the [CHANG
|
|
232
241
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
233
242
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
234
243
|
4. Push to the branch (`git push origin my-new-feature`)
|
235
|
-
5. Make sure to add tests for it. This is important so
|
236
|
-
6. Create new Pull Request
|
237
|
-
|
238
|
-
## Versioning
|
239
|
-
|
240
|
-
This library aims to adhere to [Semantic Versioning 2.0.0][semver].
|
241
|
-
Violations of this scheme should be reported as bugs. Specifically,
|
242
|
-
if a minor or patch version is released that breaks backward
|
243
|
-
compatibility, a new version should be immediately released that
|
244
|
-
restores compatibility. Breaking changes to the public API will
|
245
|
-
only be introduced with new major versions.
|
246
|
-
|
247
|
-
As a result of this policy, you can (and should) specify a
|
248
|
-
dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
249
|
-
|
250
|
-
For example:
|
251
|
-
|
252
|
-
spec.add_dependency 'rusen', '~> 0.0.2'
|
244
|
+
5. Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
|
245
|
+
6. Create a new Pull Request
|
253
246
|
|
254
247
|
## Legal
|
255
248
|
|
256
|
-
|
257
|
-
* Copyright (c) 2013 Adrian Gomez
|
249
|
+
Rusen is released under the [MIT License](http://opensource.org/licenses/MIT).
|
258
250
|
|
259
|
-
[
|
260
|
-
[
|
261
|
-
[documentation]: http://rdoc.info/github/Moove-it/rusen/frames
|
262
|
-
[homepage]: https://github.com/Moove-it/rusen
|
251
|
+
[documentation]: http://http://www.rubydoc.info/github/moove-it/rusen
|
252
|
+
[homepage]: http://moove-it.github.io/rusen/
|
data/Rakefile
CHANGED
@@ -51,15 +51,4 @@ namespace :test do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
#require 'rdoc'
|
56
|
-
#require 'rdoc/task'
|
57
|
-
#RDoc::Task.new do |rdoc|
|
58
|
-
# rdoc.rdoc_dir = 'rdoc'
|
59
|
-
# rdoc.title = "Rusen #{Rusen::VERSION}"
|
60
|
-
# rdoc.options << '--line-numbers'
|
61
|
-
# rdoc.rdoc_files.include('README*')
|
62
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
63
|
-
#end
|
64
|
-
|
65
|
-
Bundler::GemHelper.install_tasks
|
54
|
+
Bundler::GemHelper.install_tasks
|
data/lib/rusen.rb
CHANGED
@@ -2,6 +2,10 @@ require 'rusen/version'
|
|
2
2
|
require 'rusen/settings'
|
3
3
|
require 'rusen/notifier'
|
4
4
|
|
5
|
+
# Rusen is a util to help you with the tracking on the
|
6
|
+
# application exceptions, this could be used on any
|
7
|
+
# ruby project. The exceptions can be sent to different
|
8
|
+
# outputs depending on your apps requirements.
|
5
9
|
module Rusen
|
6
10
|
|
7
11
|
@settings = Settings.new
|
@@ -16,7 +20,7 @@ module Rusen
|
|
16
20
|
end
|
17
21
|
|
18
22
|
# (see Rusen::Notifier#notify)
|
19
|
-
def self.notify(exception, request =
|
23
|
+
def self.notify(exception, request = {}, environment = {}, session = {})
|
20
24
|
notifier.notify(exception, request, environment, session)
|
21
25
|
end
|
22
26
|
|
@@ -24,4 +28,4 @@ module Rusen
|
|
24
28
|
@notifier || Notifier.new(@settings)
|
25
29
|
end
|
26
30
|
|
27
|
-
end
|
31
|
+
end
|
@@ -11,28 +11,22 @@ module Rusen
|
|
11
11
|
@app = app
|
12
12
|
|
13
13
|
if settings.is_a?(::Rusen::Settings)
|
14
|
-
@
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
@rusen_settings.outputs = settings[:outputs]
|
19
|
-
@rusen_settings.sections = settings[:sections]
|
20
|
-
@rusen_settings.filter_parameters = settings[:filter_parameters]
|
21
|
-
@rusen_settings.email_prefix = settings[:email_prefix]
|
22
|
-
@rusen_settings.sender_address = settings[:sender_address]
|
23
|
-
@rusen_settings.exception_recipients = settings[:exception_recipients]
|
24
|
-
@rusen_settings.smtp_settings = settings[:smtp_settings]
|
25
|
-
@rusen_settings.exclude_if = settings[:exclude_if]
|
14
|
+
@settings = settings
|
15
|
+
elsif settings.is_a?(Hash)
|
16
|
+
@settings = ::Rusen::Settings.new(settings)
|
26
17
|
end
|
27
18
|
|
28
|
-
@notifier = Notifier.new(@
|
19
|
+
@notifier = ::Rusen::Notifier.new(@settings) if @settings
|
29
20
|
end
|
30
21
|
|
31
22
|
def call(env)
|
32
23
|
begin
|
33
24
|
@app.call(env)
|
34
25
|
rescue Exception => error
|
35
|
-
|
26
|
+
@notifier ||= Rusen.notifier
|
27
|
+
@settings ||= Rusen.settings
|
28
|
+
|
29
|
+
if @settings && !@settings.exclude_if.call(error)
|
36
30
|
request = Rack::Request.new(env)
|
37
31
|
@notifier.notify(error, request.GET.merge(request.POST), env, request.session)
|
38
32
|
end
|
@@ -3,10 +3,23 @@ require 'sidekiq'
|
|
3
3
|
|
4
4
|
module Rusen
|
5
5
|
module Middleware
|
6
|
+
|
7
|
+
# Intersect exceptions that happens on inside
|
8
|
+
# sidekiq workers. If an exception occurred
|
9
|
+
# on a worker Rusen will notify about that
|
10
|
+
# exception and will raised up.
|
6
11
|
class RusenSidekiq
|
7
12
|
include Sidekiq::Util
|
8
13
|
|
9
|
-
|
14
|
+
# Just yield the block and rescue from any
|
15
|
+
# exception that occurred on the call to
|
16
|
+
# the worker, and notify about that
|
17
|
+
# exception.
|
18
|
+
#
|
19
|
+
# @raise [Exception] if an exception occurred
|
20
|
+
# that exception was notified and raised
|
21
|
+
# again to allow the retry to happen.
|
22
|
+
def call(_, _, _, &block)
|
10
23
|
yield
|
11
24
|
rescue => error
|
12
25
|
Rusen.notify(error)
|
@@ -16,4 +29,4 @@ module Rusen
|
|
16
29
|
|
17
30
|
end
|
18
31
|
end
|
19
|
-
end
|
32
|
+
end
|
data/lib/rusen/notifier.rb
CHANGED
@@ -46,10 +46,10 @@ module Rusen
|
|
46
46
|
|
47
47
|
# We need to ignore all the exceptions thrown by the notifiers.
|
48
48
|
rescue Exception
|
49
|
-
warn(
|
49
|
+
warn('Rusen: Some or all the notifiers failed to sent the notification.')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
-
end
|
55
|
+
end
|
data/lib/rusen/notifiers.rb
CHANGED
@@ -8,22 +8,27 @@ module Rusen
|
|
8
8
|
:log4r => :Log4rNotifier,
|
9
9
|
}
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def load_klass(ident, klass_sym = nil)
|
14
|
+
klass_sym ||= NOTIFIERS[ident]
|
15
|
+
if klass_sym
|
16
|
+
require "rusen/notifiers/#{ident}_notifier" unless Notifiers.constants.include?(klass_sym)
|
17
|
+
Notifiers.const_get(klass_sym)
|
18
|
+
else
|
19
|
+
return nil
|
20
|
+
end
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def check_deprecation(ident)
|
24
|
+
if ident == :email
|
25
|
+
warn ':email is a deprecated output type. :pony replaces :email. A new alternative is :mail (mail gem).'
|
26
|
+
return :pony
|
27
|
+
end
|
28
|
+
return ident
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
end
|
32
|
+
|
28
33
|
end
|
29
34
|
end
|
@@ -4,16 +4,41 @@ require_relative '../utils/parameter_filter'
|
|
4
4
|
module Rusen
|
5
5
|
module Notifiers
|
6
6
|
|
7
|
+
# This class define all the base behaviour of all notifiers,
|
8
|
+
# for creating new notifiers this class should be
|
9
|
+
# extended.
|
7
10
|
class BaseNotifier
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# Symbol that represent the notifier, all subclasses must
|
15
|
+
# override this method to be correctly identified.
|
16
|
+
#
|
17
|
+
# @return [Symbol]
|
18
|
+
def identification_symbol
|
19
|
+
:base_notifier
|
20
|
+
end
|
21
|
+
|
11
22
|
end
|
12
23
|
|
24
|
+
# Create a new instance of a Notifier.
|
25
|
+
#
|
26
|
+
# @param [Rusen::Setting] settings the settings that will be
|
27
|
+
# used to notify, depending on this configuration is where
|
28
|
+
# the exception will be notified.
|
29
|
+
#
|
30
|
+
# @return [Rusen::Notifier::BaseNotifier]
|
13
31
|
def initialize(settings)
|
14
32
|
@settings = settings.dup
|
15
33
|
end
|
16
34
|
|
35
|
+
# Given the exception returns all the sessions that will be
|
36
|
+
# included on the notification.
|
37
|
+
#
|
38
|
+
# @param [Rusen::Notification] notification information that
|
39
|
+
# will be notified.
|
40
|
+
#
|
41
|
+
# @return [Hash<String, Object>]
|
17
42
|
def get_sessions(notification)
|
18
43
|
result = {}
|
19
44
|
|
@@ -25,6 +50,12 @@ module Rusen
|
|
25
50
|
result
|
26
51
|
end
|
27
52
|
|
53
|
+
# Some times when we try to notify exceptions an error could
|
54
|
+
# happen, for example if someone forgot to config the smtp
|
55
|
+
# settings, if that happens and an exception is raised then
|
56
|
+
# a warn is logged on the console saying the problem.
|
57
|
+
#
|
58
|
+
# @param [Exception] exception the error that was raised.
|
28
59
|
def handle_notification_exception(exception)
|
29
60
|
name = self.class.identification_symbol.to_s
|
30
61
|
|
@@ -33,6 +64,7 @@ module Rusen
|
|
33
64
|
|
34
65
|
private
|
35
66
|
|
67
|
+
# @private
|
36
68
|
def include_session(sessions, session, session_key)
|
37
69
|
@settings.sections
|
38
70
|
|
@@ -43,6 +75,7 @@ module Rusen
|
|
43
75
|
end
|
44
76
|
end
|
45
77
|
|
78
|
+
# @private
|
46
79
|
def parameter_filter
|
47
80
|
@parameter_filter ||= ParameterFilter.new(@settings.filter_parameters)
|
48
81
|
end
|
@@ -50,4 +83,4 @@ module Rusen
|
|
50
83
|
end
|
51
84
|
|
52
85
|
end
|
53
|
-
end
|
86
|
+
end
|
data/lib/rusen/settings.rb
CHANGED
@@ -16,13 +16,26 @@ module Rusen
|
|
16
16
|
attr_accessor :logger_name
|
17
17
|
attr_accessor :log4r_config_file
|
18
18
|
|
19
|
+
# Create a new Settings object using the given
|
20
|
+
# attributes.
|
21
|
+
#
|
22
|
+
# @param [Hash<String, Object>] attrs a hash with the
|
23
|
+
# options used to create a setting object.
|
24
|
+
def initialize(attrs = {})
|
25
|
+
(attrs || {}).each do |attr_name, value|
|
26
|
+
method_name = "#{attr_name}=".to_sym
|
27
|
+
|
28
|
+
self.send(method_name, value) if self.respond_to?(method_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
# Returns the configured outputs.
|
20
33
|
#
|
21
|
-
# Default: []
|
34
|
+
# Default: [:mail]
|
22
35
|
#
|
23
36
|
# @return [Array<Symbol>]
|
24
37
|
def outputs
|
25
|
-
@outputs || []
|
38
|
+
@outputs || [:mail]
|
26
39
|
end
|
27
40
|
|
28
41
|
# Returns the notification email prefix.
|
@@ -70,13 +83,17 @@ module Rusen
|
|
70
83
|
@sections || [:backtrace, :request, :session, :environment]
|
71
84
|
end
|
72
85
|
|
73
|
-
# Returns the email smtp settings
|
74
|
-
#
|
75
|
-
#
|
86
|
+
# Returns the email smtp settings, if Rusen is included on a Rails
|
87
|
+
# application the smtp settings for the application is returned,
|
88
|
+
# otherwise an empty has is returned.
|
76
89
|
#
|
77
90
|
# @return [Hash<Symbol, Object>]
|
78
91
|
def smtp_settings
|
79
|
-
@smtp_settings
|
92
|
+
if @smtp_settings
|
93
|
+
@smtp_settings
|
94
|
+
else
|
95
|
+
(defined?(Rails) && Rails.configuration.action_mailer.smtp_settings) || {}
|
96
|
+
end
|
80
97
|
end
|
81
98
|
|
82
99
|
# Returns whether to send or not the notification for a exception.
|
@@ -102,7 +119,7 @@ module Rusen
|
|
102
119
|
if @filter_parameters
|
103
120
|
@filter_parameters || []
|
104
121
|
else
|
105
|
-
defined?(Rails) && Rails.
|
122
|
+
defined?(Rails) && Rails.configuration.filter_parameters
|
106
123
|
end
|
107
124
|
end
|
108
125
|
|
data/lib/rusen/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rusen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Gomez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log4r
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
221
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.
|
222
|
+
rubygems_version: 2.4.5
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: RUby Simple Exception Notification
|