rnotifier 0.1.2 → 0.1.3
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -1
- data/LICENSE.txt +1 -1
- data/README.md +2 -0
- data/lib/rnotifier/config.rb +4 -2
- data/lib/rnotifier/event_data.rb +5 -2
- data/lib/rnotifier/exception_code.rb +2 -2
- data/lib/rnotifier/exception_data.rb +9 -2
- data/lib/rnotifier/rack_middleware.rb +1 -1
- data/lib/rnotifier/version.rb +1 -1
- data/lib/rnotifier.rb +2 -2
- data/spec/config_spec.rb +18 -0
- data/spec/event_data_spec.rb +9 -4
- data/spec/exception_code_spec.rb +19 -1
- data/spec/exception_data_spec.rb +27 -0
- data/spec/{code.text → fixtures/code.text} +0 -0
- data/spec/fixtures/rnotifier.yaml +1 -0
- data/spec/fixtures/rnotifier_ignore_env.yaml +1 -0
- data/spec/fixtures/{fake_app.rb → test_sinatra_app.rb} +1 -1
- data/spec/mock_exception_helper.rb +13 -0
- data/spec/spec_helper.rb +17 -11
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 230323fb6bf53cf96bb51c161db128e700ee4418
|
4
|
+
data.tar.gz: 1d6ae42ba52711eb1dcf22f276d8ba6f1c08b83f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 689155f28d570e40a98551e59b23e5837c82dd9a6fd85c67df1f383d60fc78a8c3e0fb315ab328d2bf350e64cb5516c2fc9ef47837b15b7f92898ee2fbed3260
|
7
|
+
data.tar.gz: e0ca66d1a5c13467fc94f2fe3effb39aa67095d6fb7b185ce2ea8ec9f66c1d6c4d13cc57aadd05cbd40bc3aef693583d99f68b3e39f8bf46cd2848b3d2b1399c
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,8 @@ Or install it yourself as:
|
|
28
28
|
environments: development,test #default is production
|
29
29
|
capture_code: true #default false
|
30
30
|
api_host: 'http://yourapp.com' #default http://rnotifier.com
|
31
|
+
ignore_exceptions: ActiveRecord::RecordNotFound,AbstractController::ActionNotFound,ActionController::RoutingError
|
32
|
+
ignore_bots: Googlebot
|
31
33
|
|
32
34
|
### To test config
|
33
35
|
|
data/lib/rnotifier/config.rb
CHANGED
@@ -14,7 +14,7 @@ module Rnotifier
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
attr_accessor :api_key, :exception_path, :event_path, :environments, :current_env,
|
17
|
-
:valid, :app_env, :api_host, :ignore_exceptions, :capture_code
|
17
|
+
:valid, :app_env, :api_host, :ignore_exceptions, :capture_code, :ignore_bots
|
18
18
|
|
19
19
|
def [](val)
|
20
20
|
DEFAULT[val]
|
@@ -48,8 +48,10 @@ module Rnotifier
|
|
48
48
|
self.api_host ||= DEFAULT[:api_host]
|
49
49
|
self.exception_path = '/' + [DEFAULT[:api_version], DEFAULT[:exception_path]].join('/')
|
50
50
|
self.app_env = get_app_env
|
51
|
-
self.ignore_exceptions = self.ignore_exceptions.split(',') if self.ignore_exceptions.is_a?(String)
|
52
51
|
|
52
|
+
self.ignore_exceptions = self.ignore_exceptions.split(',').map(&:strip) if self.ignore_exceptions.is_a?(String)
|
53
|
+
self.ignore_bots = self.ignore_bots.split(',').map(&:strip) if self.ignore_bots.is_a?(String)
|
54
|
+
|
53
55
|
self.event_path = '/' + [DEFAULT[:api_version], DEFAULT[:event_path]].join('/')
|
54
56
|
self.valid = true
|
55
57
|
end
|
data/lib/rnotifier/event_data.rb
CHANGED
@@ -14,16 +14,19 @@ module Rnotifier
|
|
14
14
|
:rnotifier_client => Config::CLIENT,
|
15
15
|
:type => type,
|
16
16
|
}
|
17
|
-
|
17
|
+
|
18
18
|
@data[:tags] = tags if tags
|
19
19
|
end
|
20
20
|
|
21
21
|
def notify
|
22
|
+
return false unless Config.valid?
|
23
|
+
|
22
24
|
begin
|
23
|
-
Notifier.send(data,
|
25
|
+
Notifier.send(data, Config.event_path)
|
24
26
|
rescue Exception => e
|
25
27
|
Rlogger.error("[EVENT NOTIFY] #{e.message}")
|
26
28
|
Rlogger.error("[EVENT NOTIFY] #{e.backtrace}")
|
29
|
+
false
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -8,8 +8,8 @@ module Rnotifier
|
|
8
8
|
def get(exception)
|
9
9
|
return unless exception.backtrace
|
10
10
|
|
11
|
-
if exception.class == SyntaxError && exception.message.match(SYNTAX_ERROR_REGX)
|
12
|
-
bline =
|
11
|
+
if exception.class == SyntaxError && m = exception.message.match(SYNTAX_ERROR_REGX)
|
12
|
+
bline = m[1]
|
13
13
|
else
|
14
14
|
bline = exception.backtrace.find do |l|
|
15
15
|
l.index(Config.app_env[:app_root]) == 0 && !Gem.path.any?{|path| l.index(path) == 0}
|
@@ -13,8 +13,9 @@ module Rnotifier
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def notify
|
16
|
-
return
|
17
|
-
return if Config.ignore_exceptions && Config.ignore_exceptions.include?(exception.class.to_s)
|
16
|
+
return false unless Config.valid?
|
17
|
+
return false if Config.ignore_exceptions && Config.ignore_exceptions.include?(exception.class.to_s)
|
18
|
+
return false if @options[:type] == :rack && is_bot?(@request.user_agent)
|
18
19
|
|
19
20
|
begin
|
20
21
|
data = options[:type] == :rack ? self.rack_exception_data : {:extra => self.env }
|
@@ -85,6 +86,12 @@ module Rnotifier
|
|
85
86
|
headers
|
86
87
|
end
|
87
88
|
|
89
|
+
def is_bot?(agent)
|
90
|
+
return false if agent.nil? || Config.ignore_bots.nil? || Config.ignore_bots.empty?
|
91
|
+
|
92
|
+
Config.ignore_bots.each { |bot| return true if (agent =~ Regexp.new(bot)) }
|
93
|
+
false
|
94
|
+
end
|
88
95
|
|
89
96
|
end
|
90
97
|
end
|
data/lib/rnotifier/version.rb
CHANGED
data/lib/rnotifier.rb
CHANGED
@@ -18,7 +18,7 @@ require 'rnotifier/railtie' if defined?(Rails)
|
|
18
18
|
module Rnotifier
|
19
19
|
class << self
|
20
20
|
def config(&block)
|
21
|
-
yield(Rnotifier::Config)
|
21
|
+
yield(Rnotifier::Config) if block_given?
|
22
22
|
Rnotifier::Config.init
|
23
23
|
end
|
24
24
|
|
@@ -28,7 +28,7 @@ module Rnotifier
|
|
28
28
|
self.config do |c|
|
29
29
|
c.api_key = config_yaml['apikey']
|
30
30
|
|
31
|
-
['environments', 'api_host', 'ignore_exceptions', 'capture_code'].each do |f|
|
31
|
+
['environments', 'api_host', 'ignore_exceptions', 'ignore_bots', 'capture_code'].each do |f|
|
32
32
|
c.send("#{f}=", config_yaml[f]) if config_yaml[f]
|
33
33
|
end
|
34
34
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -60,4 +60,22 @@ describe Rnotifier::Config do
|
|
60
60
|
expect(Rnotifier::Config.valid?).to be_true
|
61
61
|
end
|
62
62
|
|
63
|
+
it 'set config invalid if environments not set in config and app env is test or development' do
|
64
|
+
clear_config
|
65
|
+
ENV['RACK_ENV'] = 'test'
|
66
|
+
|
67
|
+
Rnotifier.load_config("#{Dir.pwd}/spec/fixtures/rnotifier_ignore_env.yaml")
|
68
|
+
|
69
|
+
expect(Rnotifier::Config.valid?).to be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'set api key from the ENV variable RNOTIFIER_API_KEY' do
|
73
|
+
clear_config
|
74
|
+
ENV['RNOTIFIER_API_KEY'] = 'ENV-API-KEY'
|
75
|
+
Rnotifier::Config.init
|
76
|
+
|
77
|
+
expect(Rnotifier::Config.api_key).to eq 'ENV-API-KEY'
|
78
|
+
ENV['RNOTIFIER_API_KEY'] = nil
|
79
|
+
end
|
80
|
+
|
63
81
|
end
|
data/spec/event_data_spec.rb
CHANGED
@@ -32,16 +32,21 @@ describe Rnotifier::EventData do
|
|
32
32
|
|
33
33
|
it 'sends event data to server' do
|
34
34
|
stubs = stub_faraday_request({:path => Rnotifier::Config.event_path})
|
35
|
-
Rnotifier::EventData.new(@name, @data).notify
|
35
|
+
status = Rnotifier::EventData.new(@name, @data).notify
|
36
36
|
|
37
|
+
expect(status).to be_true
|
37
38
|
expect { stubs.verify_stubbed_calls }.to_not raise_error
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'sends event data with tags to server' do
|
41
|
-
|
42
|
-
|
42
|
+
[:event, :alert].each do |e|
|
43
|
+
stubs = stub_faraday_request({:path => Rnotifier::Config.event_path})
|
43
44
|
|
44
|
-
|
45
|
+
status = Rnotifier.send(e, @name, @data, {:tags => [:new]})
|
46
|
+
|
47
|
+
expect(status).to be_true
|
48
|
+
expect { stubs.verify_stubbed_calls }.to_not raise_error
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
end
|
data/spec/exception_code_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe Rnotifier::ExceptionCode do
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
@file = Dir.pwd + '/spec/code.text'
|
7
|
+
@file = Dir.pwd + '/spec/fixtures/code.text'
|
8
8
|
@lines = File.readlines(@file)
|
9
9
|
@total_lines = 18
|
10
10
|
end
|
@@ -44,5 +44,23 @@ describe Rnotifier::ExceptionCode do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'collect code lines for exception' do
|
48
|
+
rnotifier_init
|
49
|
+
code = Rnotifier::ExceptionCode.get(mock_exception)
|
50
|
+
|
51
|
+
lines = File.readlines(File.dirname(__FILE__) + "/mock_exception_helper.rb")[0..5]
|
52
|
+
|
53
|
+
expect(code).to eq([0].concat(lines))
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'collect code lines for systax error' do
|
57
|
+
rnotifier_init
|
58
|
+
e = mock_syntax_error
|
59
|
+
code = Rnotifier::ExceptionCode.get(e)
|
60
|
+
|
61
|
+
lines = File.readlines(File.dirname(__FILE__) + "/mock_exception_helper.rb")[6..-1]
|
62
|
+
|
63
|
+
expect(code).to eq([6].concat(lines))
|
64
|
+
end
|
47
65
|
|
48
66
|
end
|
data/spec/exception_data_spec.rb
CHANGED
@@ -56,5 +56,32 @@ describe Rnotifier::ExceptionData do
|
|
56
56
|
expect(params).to include({'useranme' => 'bar'})
|
57
57
|
end
|
58
58
|
|
59
|
+
it 'match the user agent is bot or not' do
|
60
|
+
e_data = Rnotifier::ExceptionData.new(@exception, @env, @options)
|
61
|
+
expect(e_data.is_bot?(nil)).to be_false
|
62
|
+
|
63
|
+
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1'
|
64
|
+
expect(e_data.is_bot?(user_agent)).to be_false
|
65
|
+
|
66
|
+
user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
67
|
+
env = Rack::MockRequest.env_for(@url, @vars.merge({'HTTP_USER_AGENT' => user_agent}))
|
68
|
+
|
69
|
+
e_data = Rnotifier::ExceptionData.new(@exception, env, @options)
|
70
|
+
expect(e_data.is_bot?(user_agent)).to be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'ignores error for unwanted bot request' do
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'sends exception manually' do
|
78
|
+
stubs = stub_faraday_request
|
79
|
+
params = {:manual_exception => true}
|
80
|
+
|
81
|
+
status = Rnotifier.exception(@exception, params)
|
82
|
+
|
83
|
+
expect(status).to be_true
|
84
|
+
expect {stubs.verify_stubbed_calls }.to_not raise_error
|
85
|
+
end
|
59
86
|
|
60
87
|
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
apikey: API-KEY
|
@@ -0,0 +1,13 @@
|
|
1
|
+
def mock_exception
|
2
|
+
begin
|
3
|
+
1 + '2'
|
4
|
+
rescue Exception => e
|
5
|
+
return e
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def mock_syntax_error
|
10
|
+
e = SyntaxError.new("#{File.dirname(__FILE__)}/mock_exception_helper.rb:#{__LINE__}: syntax error, unexpected ||, expecting '}'")
|
11
|
+
e.set_backtrace([])
|
12
|
+
return e
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,14 +7,22 @@ require 'rack'
|
|
7
7
|
require 'rack/request'
|
8
8
|
require 'rack/mock'
|
9
9
|
require 'rack/test'
|
10
|
+
require 'simplecov'
|
10
11
|
require 'coveralls'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
SimpleCov.start do
|
14
|
+
add_filter '/spec/'
|
15
|
+
add_group 'gem', 'lib'
|
16
|
+
end
|
15
17
|
|
16
18
|
Coveralls.wear!
|
17
19
|
|
20
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib/')
|
21
|
+
|
22
|
+
require 'rnotifier'
|
23
|
+
require File.dirname(__FILE__) + '/mock_exception_helper'
|
24
|
+
require File.dirname(__FILE__) + '/fixtures/test_sinatra_app'
|
25
|
+
|
18
26
|
RSpec.configure do |config|
|
19
27
|
config.color_enabled = true
|
20
28
|
#config.tty = true
|
@@ -22,7 +30,7 @@ RSpec.configure do |config|
|
|
22
30
|
config.include Rack::Test::Methods
|
23
31
|
|
24
32
|
def app
|
25
|
-
Rack::Lint.new(RnotifierTest::
|
33
|
+
Rack::Lint.new(RnotifierTest::TestSinatraApp.new)
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
@@ -46,11 +54,9 @@ def stub_faraday_request(opts = {})
|
|
46
54
|
stubs
|
47
55
|
end
|
48
56
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
57
|
+
def clear_config
|
58
|
+
[:api_key, :exception_path, :event_path, :environments, :current_env,
|
59
|
+
:app_env, :api_host, :ignore_exceptions, :capture_code].each do |m|
|
60
|
+
Rnotifier::Config.send("#{m}=", nil)
|
61
|
+
end
|
55
62
|
end
|
56
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rnotifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiren Patel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -138,14 +138,16 @@ files:
|
|
138
138
|
- lib/rnotifier/rlogger.rb
|
139
139
|
- lib/rnotifier/version.rb
|
140
140
|
- rnotifier.gemspec
|
141
|
-
- spec/code.text
|
142
141
|
- spec/config_spec.rb
|
143
142
|
- spec/event_data_spec.rb
|
144
143
|
- spec/exception_code_spec.rb
|
145
144
|
- spec/exception_data_spec.rb
|
146
|
-
- spec/fixtures/
|
145
|
+
- spec/fixtures/code.text
|
147
146
|
- spec/fixtures/rnotifier.yaml
|
147
|
+
- spec/fixtures/rnotifier_ignore_env.yaml
|
148
148
|
- spec/fixtures/rnotifier_test.yaml
|
149
|
+
- spec/fixtures/test_sinatra_app.rb
|
150
|
+
- spec/mock_exception_helper.rb
|
149
151
|
- spec/rack_middleware_spec.rb
|
150
152
|
- spec/spec_helper.rb
|
151
153
|
homepage: https://github.com/jiren/rnotifier
|
@@ -173,13 +175,15 @@ signing_key:
|
|
173
175
|
specification_version: 4
|
174
176
|
summary: Exception catcher for Rails and other Rack apps
|
175
177
|
test_files:
|
176
|
-
- spec/code.text
|
177
178
|
- spec/config_spec.rb
|
178
179
|
- spec/event_data_spec.rb
|
179
180
|
- spec/exception_code_spec.rb
|
180
181
|
- spec/exception_data_spec.rb
|
181
|
-
- spec/fixtures/
|
182
|
+
- spec/fixtures/code.text
|
182
183
|
- spec/fixtures/rnotifier.yaml
|
184
|
+
- spec/fixtures/rnotifier_ignore_env.yaml
|
183
185
|
- spec/fixtures/rnotifier_test.yaml
|
186
|
+
- spec/fixtures/test_sinatra_app.rb
|
187
|
+
- spec/mock_exception_helper.rb
|
184
188
|
- spec/rack_middleware_spec.rb
|
185
189
|
- spec/spec_helper.rb
|