exception_notification-td 0.0.1.pre2 → 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 +4 -4
- data/README.md +23 -4
- data/Rakefile +10 -0
- data/exception_notification-td.gemspec +3 -0
- data/lib/exception_notification/td/version.rb +1 -1
- data/lib/exception_notifier/td_notifier.rb +7 -1
- data/test/.config.rb +5 -0
- data/test/lib/exception_notifier/test_td_notifier.rb +154 -0
- data/wercker.yml +16 -0
- metadata +52 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f6ce048d50ff328fa1db9553c6d4ec117a04a46
|
4
|
+
data.tar.gz: d88849b31e8506ff0b8b1f41b1187992351ea003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21166728cfa441d4be39da1120d667e4e2025affdb943ec5a0722c38c1695fdcace934283f443fd211a98d2b41a1a7677d05b106fdef4e15dff7fe31453bba19
|
7
|
+
data.tar.gz: 5d9b2e1df003130d61b8353ab17d2e1cbd89c3f989cb42a991baf6df219ed45141bd205c071fe3c762102286ce85f5af222f17b1297126ff2ad1ed5707ead5ad
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# exception_notification-td
|
2
2
|
|
3
|
-
|
3
|
+
[](https://app.wercker.com/project/bykey/7d390b46fd0fcea4e4aabc10f1a1b240)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,11 +20,30 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
In Rails, first set up normal [td config](https://github.com/treasure-data/td-logger-ruby#configuration) and then:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# in config/environments/#{env}.rb
|
27
|
+
config.middleware.use ExceptionNotification::Rack,
|
28
|
+
td: {
|
29
|
+
table_name: "#{Rails.env}_exceptions",
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
In some other rack apps, you need to set more options:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
use ExceptionNotification::Rack,
|
37
|
+
td: {
|
38
|
+
table_name: "#{env}_exceptions",
|
39
|
+
database: "yourdb",
|
40
|
+
apikey: "deadbeaf12345678"
|
41
|
+
}
|
42
|
+
```
|
24
43
|
|
25
44
|
## Contributing
|
26
45
|
|
27
|
-
1. Fork it ( https://github.com/
|
46
|
+
1. Fork it ( https://github.com/udzura/exception_notification-td/fork )
|
28
47
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
48
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
49
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,2 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
2
3
|
|
4
|
+
desc 'Run test_unit based test'
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
# To run test for only one file (or file path pattern)
|
7
|
+
# $ bundle exec rake test TEST=test/test_specified_path.rb
|
8
|
+
t.libs.concat ["test"]
|
9
|
+
t.test_files = Dir["test/**/test_*.rb"]
|
10
|
+
t.verbose = true
|
11
|
+
t.ruby_opts = ["-r .config"]
|
12
|
+
end
|
@@ -23,6 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "pry"
|
26
27
|
spec.add_development_dependency "test-unit", ">= 3"
|
27
28
|
spec.add_development_dependency "test-unit-rr"
|
29
|
+
spec.add_development_dependency "test-unit-power_assert"
|
30
|
+
spec.add_development_dependency "rack"
|
28
31
|
end
|
@@ -19,6 +19,7 @@ module ExceptionNotifier
|
|
19
19
|
TreasureData::Logger.open(@database, options)
|
20
20
|
end
|
21
21
|
end
|
22
|
+
attr_reader :table_name, :backtrace_limit, :custom_param_proc, :database
|
22
23
|
|
23
24
|
def call(exception, options = {})
|
24
25
|
TD.event.post(@table_name, exception_to_td_data(exception, options))
|
@@ -39,12 +40,17 @@ module ExceptionNotifier
|
|
39
40
|
|
40
41
|
def exception_to_td_data(exception, options)
|
41
42
|
backtrace = exception.backtrace ? exception.backtrace[0, @backtrace_limit] : []
|
43
|
+
environment = if defined?(Rails)
|
44
|
+
Rails.env
|
45
|
+
else
|
46
|
+
ENV['RACK_ENV'] || 'development'
|
47
|
+
end
|
42
48
|
params = {
|
43
49
|
class: exception.class.to_s,
|
44
50
|
message: exception.message,
|
45
51
|
backtrace: backtrace,
|
46
52
|
hostname: (Socket.gethostname rescue nil),
|
47
|
-
environment:
|
53
|
+
environment: environment,
|
48
54
|
}
|
49
55
|
if request_klass && options[:env]
|
50
56
|
request = request_klass.new(options[:env])
|
data/test/.config.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
class TestTdNotifier < Test::Unit::TestCase
|
2
|
+
def setup
|
3
|
+
end
|
4
|
+
|
5
|
+
def teardown
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_normal_setup
|
9
|
+
@options = {
|
10
|
+
table_name: 'sample_table',
|
11
|
+
database: 'sample',
|
12
|
+
backtrace_limit: 100,
|
13
|
+
custom_param_proc: proc {|i| i[:foo] = "bar"; i },
|
14
|
+
apikey: 'deadbeaf19842015'
|
15
|
+
}
|
16
|
+
|
17
|
+
assert_equal notifier.table_name, 'sample_table'
|
18
|
+
assert_equal notifier.database, 'sample'
|
19
|
+
assert_equal notifier.backtrace_limit, 100
|
20
|
+
assert_equal notifier.custom_param_proc[{}], {foo: "bar"}
|
21
|
+
|
22
|
+
apikey = TreasureData::Logger.logger.instance_eval{ @client }.apikey
|
23
|
+
assert_equal apikey, "deadbeaf19842015"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_required_options
|
27
|
+
@options = {}
|
28
|
+
assert_raise_message /Please set table_name/ do
|
29
|
+
ExceptionNotifier::TdNotifier.new(@options)
|
30
|
+
end
|
31
|
+
|
32
|
+
@options[:table_name] = "ganbaruzoi"
|
33
|
+
assert_raise_message /Please set database/ do
|
34
|
+
ExceptionNotifier::TdNotifier.new(@options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_post_message
|
39
|
+
@options = {
|
40
|
+
table_name: 'sample_table',
|
41
|
+
database: 'sample',
|
42
|
+
test_mode: true,
|
43
|
+
apikey: 'deadbeaf19842015'
|
44
|
+
}
|
45
|
+
|
46
|
+
# Fill in backtrace
|
47
|
+
begin
|
48
|
+
@l = __LINE__; raise StandardError, "sample error"
|
49
|
+
rescue => e
|
50
|
+
notifier_with_test_mode.call(e, {})
|
51
|
+
end
|
52
|
+
|
53
|
+
posted = TD.logger.queue[0]
|
54
|
+
assert_equal posted[:class], "StandardError"
|
55
|
+
assert_equal posted[:message], "sample error"
|
56
|
+
assert_match %r|#{Regexp.quote __FILE__}:#{@l}|, posted[:backtrace][0]
|
57
|
+
assert_not_nil posted[:hostname]
|
58
|
+
assert_not_nil posted[:environment]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_request_log_via_rack_env
|
62
|
+
require 'rack/request'
|
63
|
+
@options = {
|
64
|
+
table_name: 'sample_table',
|
65
|
+
database: 'sample',
|
66
|
+
test_mode: true,
|
67
|
+
apikey: 'deadbeaf19842015'
|
68
|
+
}
|
69
|
+
@env = {
|
70
|
+
"HTTP_HOST" => "example.udzura.jp:80",
|
71
|
+
"rack.url_scheme" => 'http',
|
72
|
+
"PATH_INFO" => "/hello.html",
|
73
|
+
"REQUEST_METHOD" => "GET",
|
74
|
+
"HTTP_COOKIE" => "foo=bar;buz=1234;",
|
75
|
+
"HTTP_REFERER" => "http://example.com",
|
76
|
+
}
|
77
|
+
|
78
|
+
notifier_with_test_mode.call(StandardError.new("sample error"), {env: @env})
|
79
|
+
posted = TD.logger.queue[0]
|
80
|
+
|
81
|
+
assert_equal posted[:request_url], "http://example.udzura.jp/hello.html"
|
82
|
+
assert_equal posted[:method], "GET"
|
83
|
+
assert_equal posted[:cookies], {"foo"=>"bar", "buz"=>"1234"}
|
84
|
+
assert_equal posted[:referer], "http://example.com"
|
85
|
+
# TODO: add request body assertion
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_custom_param_proc
|
89
|
+
@options = {
|
90
|
+
table_name: 'sample_table',
|
91
|
+
database: 'sample',
|
92
|
+
test_mode: true,
|
93
|
+
apikey: 'deadbeaf19842015',
|
94
|
+
custom_param_proc: proc {|info|
|
95
|
+
info[:hello] = "world"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
notifier_with_test_mode.call(StandardError.new("sample error"), {env: @env})
|
100
|
+
posted = TD.logger.queue[0]
|
101
|
+
|
102
|
+
assert_equal posted[:hello], "world"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_backtrace_limit
|
106
|
+
@options = {
|
107
|
+
table_name: 'sample_table',
|
108
|
+
database: 'sample',
|
109
|
+
test_mode: true,
|
110
|
+
apikey: 'deadbeaf19842015'
|
111
|
+
}
|
112
|
+
|
113
|
+
# Fill in backtrace
|
114
|
+
begin
|
115
|
+
raise StandardError, "sample error"
|
116
|
+
rescue => e
|
117
|
+
notifier_with_test_mode.call(e, {})
|
118
|
+
end
|
119
|
+
|
120
|
+
posted = TD.logger.queue[0]
|
121
|
+
assert_equal posted[:backtrace].size, 10
|
122
|
+
|
123
|
+
@notifier = nil
|
124
|
+
@options = {
|
125
|
+
table_name: 'sample_table',
|
126
|
+
database: 'sample',
|
127
|
+
test_mode: true,
|
128
|
+
apikey: 'deadbeaf19842015',
|
129
|
+
backtrace_limit: 5
|
130
|
+
}
|
131
|
+
begin
|
132
|
+
raise StandardError, "sample error 2"
|
133
|
+
rescue => e
|
134
|
+
notifier_with_test_mode.call(e, {})
|
135
|
+
end
|
136
|
+
|
137
|
+
posted = TD.logger.queue[0]
|
138
|
+
assert_equal posted[:backtrace].size, 5
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def notifier
|
144
|
+
@notifier ||= ExceptionNotifier::TdNotifier.new(@options)
|
145
|
+
end
|
146
|
+
|
147
|
+
def notifier_with_test_mode
|
148
|
+
@notifier ||= begin
|
149
|
+
n = ExceptionNotifier::TdNotifier.new(@options)
|
150
|
+
TreasureData::Logger.open_test
|
151
|
+
n
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
data/wercker.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
box: wercker/rvm
|
2
|
+
build:
|
3
|
+
steps:
|
4
|
+
- rvm-use:
|
5
|
+
version: 2.1.5
|
6
|
+
- bundle-install
|
7
|
+
- script:
|
8
|
+
name: test-unit
|
9
|
+
code: bundle exec rake test
|
10
|
+
|
11
|
+
- rvm-use:
|
12
|
+
version: 2.0.0-p598
|
13
|
+
- bundle-install
|
14
|
+
- script:
|
15
|
+
name: test-unit
|
16
|
+
code: bundle exec rake test
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification-td
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio KONDO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: td-logger
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: test-unit
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,34 @@ dependencies:
|
|
94
108
|
- - '>='
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: test-unit-power_assert
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
description: Send exception info to TreasureData
|
98
140
|
email:
|
99
141
|
- udzura@udzura.jp
|
@@ -111,6 +153,9 @@ files:
|
|
111
153
|
- lib/exception_notification/td.rb
|
112
154
|
- lib/exception_notification/td/version.rb
|
113
155
|
- lib/exception_notifier/td_notifier.rb
|
156
|
+
- test/.config.rb
|
157
|
+
- test/lib/exception_notifier/test_td_notifier.rb
|
158
|
+
- wercker.yml
|
114
159
|
homepage: https://github.com/udzura/exception_notification-td
|
115
160
|
licenses:
|
116
161
|
- MIT
|
@@ -126,13 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
171
|
version: '0'
|
127
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
173
|
requirements:
|
129
|
-
- - '
|
174
|
+
- - '>='
|
130
175
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
176
|
+
version: '0'
|
132
177
|
requirements: []
|
133
178
|
rubyforge_project:
|
134
179
|
rubygems_version: 2.0.14
|
135
180
|
signing_key:
|
136
181
|
specification_version: 4
|
137
182
|
summary: Send exception info to TreasureData
|
138
|
-
test_files:
|
183
|
+
test_files:
|
184
|
+
- test/.config.rb
|
185
|
+
- test/lib/exception_notifier/test_td_notifier.rb
|