rnotifier 0.1.1 → 0.1.2
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/README.md +21 -2
- data/bin/rnotifier +1 -0
- data/lib/rnotifier/config.rb +4 -15
- data/lib/rnotifier/event_data.rb +9 -3
- data/lib/rnotifier/exception_code.rb +14 -4
- data/lib/rnotifier/exception_data.rb +11 -12
- data/lib/rnotifier/notifier.rb +2 -2
- data/lib/rnotifier/rlogger.rb +1 -0
- data/lib/rnotifier/version.rb +1 -1
- data/lib/rnotifier.rb +8 -4
- data/spec/config_spec.rb +8 -5
- data/spec/event_data_spec.rb +19 -3
- data/spec/fixtures/fake_app.rb +6 -0
- data/spec/fixtures/rnotifier.yaml +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdc39bc4bb388b4f04a7da32a3a1c78f94f02776
|
4
|
+
data.tar.gz: 416474803f5349c511b8fd5f95b38cccc2208ffc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d8f7981351c4a9ced9be049a1f7732b77b5eaf55d8fb29cb1d837cea7165d795ad81d1261f6981371a118f34f80c256adede6935b622ae7eeaef281c5dc7b97
|
7
|
+
data.tar.gz: 8af20c69d211af538a61f6da359f95cded4cbd778c790fc5f30c7d398039f1e5b29083803773d3152a6926c36752ecb37918d8150f6e56ec74c21d63658f83a1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rnotifier
|
2
2
|
|
3
|
-
Exception catcher
|
3
|
+
Events and Exception catcher libraray.
|
4
4
|
|
5
5
|
[](https://travis-ci.org/jiren/rnotifier)
|
6
6
|
[](https://coveralls.io/r/jiren/rnotifier?branch=master)
|
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
rnotifier install 'API-KEY' # This will create 'config/rnotifier.yaml' file.
|
24
|
+
rnotifier install 'API-KEY' # This will create 'config/rnotifier.yaml' file.
|
25
25
|
|
26
26
|
### Config file options
|
27
27
|
|
@@ -33,6 +33,25 @@ rnotifier install 'API-KEY' # This will create 'config/rnotifier.yaml' file.
|
|
33
33
|
|
34
34
|
rnotifier test #this will send test exception to rnotifier.
|
35
35
|
|
36
|
+
|
37
|
+
### Send events and alerts
|
38
|
+
|
39
|
+
Rnotifier.event(:sign_up, {:username => 'Jiren', :email => 'jiren@example.com', :using => 'facebook' })
|
40
|
+
|
41
|
+
Rnotifier.alert(:order_fail, {:user => 'Jiren', :product => 'PS3', :order_id => '321' })
|
42
|
+
|
43
|
+
|
44
|
+
You can also sends tags with 'event' and 'alert'
|
45
|
+
i.e
|
46
|
+
|
47
|
+
Rnotifier.event(
|
48
|
+
:sign_up,
|
49
|
+
{:username => 'Jiren', :email => 'jiren@example.com', :using => 'facebook' },
|
50
|
+
{:tags => ['newsletter']}
|
51
|
+
)
|
52
|
+
|
53
|
+
|
54
|
+
|
36
55
|
## Contributing
|
37
56
|
|
38
57
|
1. Fork it
|
data/bin/rnotifier
CHANGED
@@ -15,6 +15,7 @@ install api-key [environments] #Create config/rnotifier.yaml with api_key and en
|
|
15
15
|
require 'rack'
|
16
16
|
require 'rnotifier'
|
17
17
|
require 'rnotifier/config_test.rb'
|
18
|
+
ENV['RACK_ENV'] = 'rnotifier_test'
|
18
19
|
Rnotifier.load_config('config/rnotifier.yaml')
|
19
20
|
if Rnotifier::Config.valid?
|
20
21
|
Rnotifier::ConfigTest.test
|
data/lib/rnotifier/config.rb
CHANGED
@@ -3,7 +3,7 @@ module Rnotifier
|
|
3
3
|
DEFAULT = {
|
4
4
|
:api_host => 'http://api.rnotifier.com',
|
5
5
|
:api_version => 'v1',
|
6
|
-
:
|
6
|
+
:exception_path => 'exception',
|
7
7
|
:event_path => 'event',
|
8
8
|
:ignore_env => ['development', 'test'],
|
9
9
|
:http_open_timeout => 2,
|
@@ -13,7 +13,7 @@ module Rnotifier
|
|
13
13
|
CLIENT = "RRG:#{Rnotifier::VERSION}"
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_accessor :api_key, :
|
16
|
+
attr_accessor :api_key, :exception_path, :event_path, :environments, :current_env,
|
17
17
|
:valid, :app_env, :api_host, :ignore_exceptions, :capture_code
|
18
18
|
|
19
19
|
def [](val)
|
@@ -46,12 +46,11 @@ module Rnotifier
|
|
46
46
|
return if self.api_key.to_s.length == 0
|
47
47
|
|
48
48
|
self.api_host ||= DEFAULT[:api_host]
|
49
|
-
self.
|
49
|
+
self.exception_path = '/' + [DEFAULT[:api_version], DEFAULT[:exception_path]].join('/')
|
50
50
|
self.app_env = get_app_env
|
51
51
|
self.ignore_exceptions = self.ignore_exceptions.split(',') if self.ignore_exceptions.is_a?(String)
|
52
52
|
|
53
|
-
self.event_path = '/' + [DEFAULT[:api_version], DEFAULT[:event_path]
|
54
|
-
|
53
|
+
self.event_path = '/' + [DEFAULT[:api_version], DEFAULT[:event_path]].join('/')
|
55
54
|
self.valid = true
|
56
55
|
end
|
57
56
|
|
@@ -83,16 +82,6 @@ module Rnotifier
|
|
83
82
|
(defined?(Rails) && Rails.respond_to?(:root)) ? Rails.root.to_s : Dir.pwd
|
84
83
|
end
|
85
84
|
|
86
|
-
def event_app_env
|
87
|
-
{
|
88
|
-
:env => self.current_env,
|
89
|
-
:pid => $$,
|
90
|
-
:host => (Socket.gethostname rescue ''),
|
91
|
-
:language => 'ruby',
|
92
|
-
:platform => (RUBY_PLATFORM rescue '')
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
85
|
end
|
97
86
|
end
|
98
87
|
end
|
data/lib/rnotifier/event_data.rb
CHANGED
@@ -5,16 +5,17 @@ module Rnotifier
|
|
5
5
|
EVENT = 0
|
6
6
|
ALERT = 1
|
7
7
|
|
8
|
-
def initialize(name, type, data = {})
|
8
|
+
def initialize(name, type, data = {}, tags = nil)
|
9
9
|
@data = {
|
10
10
|
:name => name,
|
11
11
|
:data => data,
|
12
12
|
:app_env => EventData.app_env,
|
13
|
-
:occurred_at => Time.now.
|
13
|
+
:occurred_at => Time.now.to_i,
|
14
14
|
:rnotifier_client => Config::CLIENT,
|
15
15
|
:type => type,
|
16
16
|
}
|
17
17
|
@data[:context_data] = Thread.current[:rnotifier_context] if Thread.current[:rnotifier_context]
|
18
|
+
@data[:tags] = tags if tags
|
18
19
|
end
|
19
20
|
|
20
21
|
def notify
|
@@ -27,7 +28,12 @@ module Rnotifier
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def self.app_env
|
30
|
-
@
|
31
|
+
@app_env ||= {
|
32
|
+
:env => Config.current_env,
|
33
|
+
:pid => $$,
|
34
|
+
:host => (Socket.gethostname rescue ''),
|
35
|
+
:language => 'ruby'
|
36
|
+
}
|
31
37
|
end
|
32
38
|
|
33
39
|
end
|
@@ -1,13 +1,23 @@
|
|
1
1
|
module Rnotifier
|
2
2
|
class ExceptionCode
|
3
|
+
|
4
|
+
SYNTAX_ERROR_REGX = /\A(.*:\d*):/
|
5
|
+
|
3
6
|
class << self
|
4
7
|
|
5
|
-
def get(
|
6
|
-
return unless backtrace
|
7
|
-
|
8
|
-
|
8
|
+
def get(exception)
|
9
|
+
return unless exception.backtrace
|
10
|
+
|
11
|
+
if exception.class == SyntaxError && exception.message.match(SYNTAX_ERROR_REGX)
|
12
|
+
bline = $1
|
13
|
+
else
|
14
|
+
bline = exception.backtrace.find do |l|
|
15
|
+
l.index(Config.app_env[:app_root]) == 0 && !Gem.path.any?{|path| l.index(path) == 0}
|
16
|
+
end
|
9
17
|
end
|
18
|
+
|
10
19
|
filename, line, method = (bline|| backtrace[0]).split(':')
|
20
|
+
|
11
21
|
self.find(filename, line.to_i, 3)
|
12
22
|
end
|
13
23
|
|
@@ -13,19 +13,19 @@ module Rnotifier
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def notify
|
16
|
-
return
|
16
|
+
return if !Config.valid?
|
17
17
|
return if Config.ignore_exceptions && Config.ignore_exceptions.include?(exception.class.to_s)
|
18
18
|
|
19
19
|
begin
|
20
20
|
data = options[:type] == :rack ? self.rack_exception_data : {:extra => self.env }
|
21
21
|
data[:app_env] = Rnotifier::Config.app_env
|
22
|
-
data[:occurred_at] = Time.now.
|
22
|
+
data[:occurred_at] = Time.now.to_i
|
23
23
|
data[:exception] = self.exception_data
|
24
24
|
data[:context_data] = Thread.current[:rnotifier_context] if Thread.current[:rnotifier_context]
|
25
25
|
data[:data_from] = options[:type]
|
26
26
|
data[:rnotifier_client] = Config::CLIENT
|
27
27
|
|
28
|
-
return Notifier.send(data)
|
28
|
+
return Notifier.send(data, Config.exception_path)
|
29
29
|
rescue Exception => e
|
30
30
|
Rlogger.error("[NOTIFY] #{e.message}")
|
31
31
|
Rlogger.error("[NOTIFY] #{e.backtrace}")
|
@@ -36,15 +36,14 @@ module Rnotifier
|
|
36
36
|
def rack_exception_data
|
37
37
|
data = {}
|
38
38
|
data[:request] = {
|
39
|
-
:url
|
40
|
-
:referer_url
|
41
|
-
:ip
|
42
|
-
:http_method
|
43
|
-
:params
|
44
|
-
:headers
|
45
|
-
:session
|
39
|
+
:url => request.url,
|
40
|
+
:referer_url => request.referer,
|
41
|
+
:ip => request.ip,
|
42
|
+
:http_method => "#{request.request_method}#{' # XHR' if request.xhr?}",
|
43
|
+
:params => filtered_params,
|
44
|
+
:headers => self.headers,
|
45
|
+
:session => request.session
|
46
46
|
}
|
47
|
-
|
48
47
|
data
|
49
48
|
end
|
50
49
|
|
@@ -55,7 +54,7 @@ module Rnotifier
|
|
55
54
|
:backtrace => exception.backtrace,
|
56
55
|
:fingerprint => (self.fingerprint rescue nil)
|
57
56
|
}
|
58
|
-
e_data[:code] = ExceptionCode.get(
|
57
|
+
e_data[:code] = ExceptionCode.get(exception) if Config.capture_code
|
59
58
|
e_data
|
60
59
|
end
|
61
60
|
|
data/lib/rnotifier/notifier.rb
CHANGED
@@ -8,9 +8,9 @@ module Rnotifier
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def send(data,
|
11
|
+
def send(data, path)
|
12
12
|
response = self.connection.post do |req|
|
13
|
-
req.url(
|
13
|
+
req.url(path)
|
14
14
|
req.headers['Content-Type'] = 'application/json'
|
15
15
|
req.headers['Api-Key'] = Config.api_key
|
16
16
|
req.options[:timeout] = Config[:http_open_timeout]
|
data/lib/rnotifier/rlogger.rb
CHANGED
data/lib/rnotifier/version.rb
CHANGED
data/lib/rnotifier.rb
CHANGED
@@ -50,12 +50,16 @@ module Rnotifier
|
|
50
50
|
Rnotifier::ExceptionData.new(exception, params, {:type => :rescue}).notify
|
51
51
|
end
|
52
52
|
|
53
|
-
def event(name, params = {})
|
54
|
-
|
53
|
+
def event(name, params, tags = {})
|
54
|
+
if Rnotifier::Config.valid? && params.is_a?(Hash)
|
55
|
+
Rnotifier::EventData.new(name, Rnotifier::EventData::EVENT, params, tags[:tags]).notify
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def alert(name, params = {})
|
58
|
-
|
59
|
+
def alert(name, params, tags = {})
|
60
|
+
if Rnotifier::Config.valid? && params.is_a?(Hash)
|
61
|
+
Rnotifier::EventData.new(name, Rnotifier::EventData::ALERT, params, tags[:tags]).notify
|
62
|
+
end
|
59
63
|
end
|
60
64
|
|
61
65
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -4,9 +4,11 @@ require 'spec_helper'
|
|
4
4
|
describe Rnotifier::Config do
|
5
5
|
before(:all) do
|
6
6
|
@api_key = 'API-KEY'
|
7
|
-
@
|
8
|
-
|
9
|
-
|
7
|
+
@exception_path = '/' + [ Rnotifier::Config::DEFAULT[:api_version],
|
8
|
+
Rnotifier::Config::DEFAULT[:exception_path]].join('/')
|
9
|
+
|
10
|
+
@event_path = '/' + [ Rnotifier::Config::DEFAULT[:api_version],
|
11
|
+
Rnotifier::Config::DEFAULT[:event_path]].join('/')
|
10
12
|
end
|
11
13
|
|
12
14
|
before(:each) do
|
@@ -25,7 +27,8 @@ describe Rnotifier::Config do
|
|
25
27
|
it 'has default config values' do
|
26
28
|
Rnotifier::Config.tap do |c|
|
27
29
|
expect(c.current_env).to eq @environments
|
28
|
-
expect(c.
|
30
|
+
expect(c.exception_path).to eq @exception_path
|
31
|
+
expect(c.event_path).to eq @event_path
|
29
32
|
expect(c.api_key).to eq @api_key
|
30
33
|
end
|
31
34
|
end
|
@@ -53,7 +56,7 @@ describe Rnotifier::Config do
|
|
53
56
|
Rnotifier.load_config("#{Dir.pwd}/spec/fixtures/rnotifier.yaml")
|
54
57
|
|
55
58
|
expect(Rnotifier::Config.api_key).to eq @api_key
|
56
|
-
expect(Rnotifier::Config.environments).to eq ['production', 'staging']
|
59
|
+
expect(Rnotifier::Config.environments).to eq ['production', 'staging', 'test']
|
57
60
|
expect(Rnotifier::Config.valid?).to be_true
|
58
61
|
end
|
59
62
|
|
data/spec/event_data_spec.rb
CHANGED
@@ -19,13 +19,29 @@ describe Rnotifier::EventData do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
it '
|
23
|
-
|
24
|
-
|
22
|
+
it 'is initialize event_data object with tags' do
|
23
|
+
[:event, :alert].each do |e|
|
24
|
+
e_data = Rnotifier::EventData.new(@name, e, @data, [:create, :update])
|
25
25
|
|
26
|
+
expect(e_data.data[:name]).to eq @name
|
27
|
+
expect(e_data.data[:data]).to eq @data
|
28
|
+
expect(e_data.data[:type]).to eq e
|
29
|
+
expect(e_data.data[:tags]).to eq [:create, :update]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sends event data to server' do
|
34
|
+
stubs = stub_faraday_request({:path => Rnotifier::Config.event_path})
|
26
35
|
Rnotifier::EventData.new(@name, @data).notify
|
27
36
|
|
28
37
|
expect { stubs.verify_stubbed_calls }.to_not raise_error
|
29
38
|
end
|
30
39
|
|
40
|
+
it 'sends event data with tags to server' do
|
41
|
+
stubs = stub_faraday_request({:path => Rnotifier::Config.event_path})
|
42
|
+
Rnotifier.event(@name, @data, {:tags => [:new]})
|
43
|
+
|
44
|
+
expect { stubs.verify_stubbed_calls }.to_not raise_error
|
45
|
+
end
|
46
|
+
|
31
47
|
end
|
data/spec/fixtures/fake_app.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
apikey: API-KEY
|
2
|
-
environments: production,staging
|
2
|
+
environments: production,staging,test
|
data/spec/spec_helper.rb
CHANGED
@@ -34,7 +34,7 @@ end
|
|
34
34
|
def stub_faraday_request(opts = {})
|
35
35
|
opts[:status] ||= 200
|
36
36
|
opts[:message] ||= 'ok'
|
37
|
-
opts[:path] ||= '/' + [ Rnotifier::Config::DEFAULT[:api_version], Rnotifier::Config::DEFAULT[:
|
37
|
+
opts[:path] ||= '/' + [ Rnotifier::Config::DEFAULT[:api_version], Rnotifier::Config::DEFAULT[:exception_path]].join('/')
|
38
38
|
|
39
39
|
stubs = Faraday::Adapter::Test::Stubs.new
|
40
40
|
conn = Faraday.new do |builder|
|
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.2
|
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-07-
|
11
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|