errplane 0.2.7 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -49,7 +49,25 @@ This gem also supports notifications from failed Resque jobs. Just add the follo
49
49
  Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Errplane]
50
50
  Resque::Failure.backend = Resque::Failure::Multiple
51
51
 
52
- Assuming this is running from within a normal Rails projects, the values provided in `config/initializers/errplane.rb` will make sure that the Resque backend is set up correctly.
52
+ Assuming this is running from within a normal Rails project, the values provided in `config/initializers/errplane.rb` will make sure that the Resque backend is set up correctly.
53
+
54
+ Customizing How Exceptions Get Grouped and Sending Additional Data
55
+ ------------------------------------------------------------------
56
+
57
+ The Errplane API will automatically attempt to group exceptions and threshold alerts based on a SHA hash of the exception class name and the first line of the backtrace. This works for some cases, but may be too noisy for failures that occur in different spots in your application that mean the same thing. This gem includes functionality to define a hash yourself to modify how exception groupings are made. That can be done by modifying `config/initializers/resque.rb`:
58
+
59
+ require 'digest/sha1'
60
+
61
+ Errplane.configure do |config|
62
+ config.define_custom_exception_data do |black_box|
63
+ if black_box.exception.class == ZeroDivisionError
64
+ black_box.hash = Digest::SHA1.hexdigest("ZeroDivisionError")
65
+ black_box.custom_data[:extra_info] = "maths"
66
+ end
67
+ end
68
+ end
69
+
70
+ That example will ensure that any divide by zero errors in your application will be grouped together, while all other exceptions will be grouped by the normal logic. The custom_exception_data block gets yielded an [Errplane::BlackBox](https://github.com/errplane/gem/blob/master/lib/errplane/black_box.rb) object. Through that object you can access exception information, request information, and custom data. You can also add custom data that can be viewed later in Errplane. This is useful if you want to capture additional context that we haven't already thought of including. When setting `custom_data.hash` it should always be some sort of digest like SHA1 used in the above example.
53
71
 
54
72
  Rails Remote Logger
55
73
  -------------------
data/errplane.gemspec CHANGED
@@ -23,12 +23,14 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'activesupport', ['>= 2.3.14']
24
24
  s.add_dependency 'actionpack', ['>= 2.3.14']
25
25
  s.add_dependency 'json', ['>= 0']
26
+ s.add_dependency 'rails', ['>= 3.0']
26
27
 
27
28
  s.add_development_dependency 'bundler', ['>= 1.0.0']
28
29
  s.add_development_dependency 'rake', ['>= 0']
29
30
  s.add_development_dependency 'sqlite3', ['>= 0']
30
31
  s.add_development_dependency 'tzinfo', ['>= 0']
31
32
  s.add_development_dependency 'rspec', ['>= 0']
33
+ s.add_development_dependency 'rspec-rails', ['>= 0']
32
34
  s.add_development_dependency 'rr', ['>= 0']
33
35
  s.add_development_dependency 'capybara', ['>= 1.0']
34
36
  s.add_development_dependency 'database_cleaner', ['>= 0']
@@ -1,5 +1,6 @@
1
1
  module Errplane
2
2
  class BlackBox
3
+ attr_accessor :hash
3
4
  attr_reader :exception
4
5
  attr_reader :params
5
6
  attr_reader :session_data
@@ -19,7 +20,7 @@ module Errplane
19
20
  end
20
21
 
21
22
  def to_json
22
- {
23
+ paylaod = {
23
24
  :time => Time.now.to_i,
24
25
  :application_name => Errplane.configuration.application_name,
25
26
  :application_root => Errplane.configuration.application_root,
@@ -32,9 +33,15 @@ module Errplane
32
33
  :language_version => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
33
34
  :environment_variables => ENV.to_hash,
34
35
  :reporter => reporter,
35
- :request_data => request_data,
36
36
  :custom_data => @custom_data
37
- }.to_json
37
+ }
38
+
39
+ Errplane.configuration.add_custom_exception_data(self)
40
+
41
+ paylaod[:request_data] = request_data if @controller || @action || !params.empty?
42
+ paylaod[:hash] = hash if hash
43
+
44
+ paylaod.to_json
38
45
  end
39
46
 
40
47
  def reporter
@@ -65,6 +65,14 @@ module Errplane
65
65
  end
66
66
  end
67
67
 
68
+ def define_custom_exception_data(&block)
69
+ @custom_exception_data_handler = block
70
+ end
71
+
72
+ def add_custom_exception_data(black_box)
73
+ @custom_exception_data_handler.call(black_box) if @custom_exception_data_handler
74
+ end
75
+
68
76
  private
69
77
  def initialize_http_connection
70
78
  Net::HTTP.new(@app_host, "80")
@@ -1,3 +1,3 @@
1
1
  module Errplane
2
- VERSION = "0.2.7"
2
+ VERSION = "0.3.7"
3
3
  end
data/lib/errplane.rb CHANGED
@@ -61,7 +61,25 @@ module Errplane
61
61
  configuration.ignore_current_environment? || configuration.ignored_exceptions.include?(e.class.to_s)
62
62
  end
63
63
 
64
+ def rescue(&block)
65
+ block.call
66
+ rescue StandardError => e
67
+ if configuration.ignore_current_environment?
68
+ raise(e)
69
+ else
70
+ transmit_unless_ignorable(e, {})
71
+ end
72
+ end
73
+
74
+ def rescue_and_reraise(&block)
75
+ block.call
76
+ rescue StandardError => e
77
+ transmit_unless_ignorable(e, {})
78
+ raise(e)
79
+ end
80
+
64
81
  private
82
+
65
83
  def assemble_black_box_for(e, opts = {})
66
84
  opts ||= {}
67
85
  configuration.logger.info("OPTS: #{opts}")
@@ -30,5 +30,21 @@ describe Errplane::BlackBox do
30
30
  json["time"].should_not be_nil
31
31
  json["backtrace"].should_not be_nil
32
32
  end
33
+
34
+ it "should include a custom hash if defined in the errplane config" do
35
+ Errplane.configure do |config|
36
+ config.define_custom_exception_data do |black_box|
37
+ if black_box.exception.class == ZeroDivisionError
38
+ black_box.hash = "some_hash"
39
+ black_box.custom_data[:extra_info] = "blah"
40
+ end
41
+ end
42
+ end
43
+
44
+ black_box = Errplane::BlackBox.new(exception: @exception)
45
+ json = JSON.parse(black_box.to_json)
46
+ json["hash"].should == "some_hash"
47
+ json["custom_data"]["extra_info"].should == "blah"
48
+ end
33
49
  end
34
50
  end
@@ -23,4 +23,47 @@ describe Errplane do
23
23
  Errplane.ignorable_exception?(exception).should be_false
24
24
  end
25
25
  end
26
+
27
+ describe 'rescue' do
28
+
29
+ it "should transmit an exception when passed" do
30
+ Errplane.configure do |config|
31
+ config.ignored_environments = %w{development}
32
+ end
33
+
34
+ stub_request(:post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012").to_return(status: 200)
35
+ Errplane.rescue do
36
+ raise ArgumentError.new('wrong')
37
+ end
38
+ assert_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
39
+ end
40
+
41
+ it "should also raise the exception when in an ignored environment" do
42
+ Errplane.configure do |config|
43
+ config.ignored_environments = %w{development test}
44
+ end
45
+ expect {
46
+ Errplane.rescue do
47
+ raise ArgumentError.new('wrong')
48
+ end
49
+ }.to raise_error(ArgumentError)
50
+ end
51
+ end
52
+
53
+ describe "rescue_and_reraise" do
54
+ before do
55
+ Errplane.configure do |config|
56
+ config.ignored_environments = %w{development}
57
+ end
58
+ end
59
+
60
+ it "should transmit an exception when passed" do
61
+ stub_request(:post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012").to_return(status: 200)
62
+ expect {
63
+ Errplane.rescue_and_reraise { raise ArgumentError.new('wrong') }
64
+ }.to raise_error(ArgumentError)
65
+ assert_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
66
+ end
67
+ end
68
+
26
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errplane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70311534139560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 2.3.14
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 2.3.14
24
+ version_requirements: *70311534139560
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: actionpack
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70311534139040 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: 2.3.14
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 2.3.14
35
+ version_requirements: *70311534139040
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: json
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70311534138560 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,21 @@ dependencies:
53
43
  version: '0'
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
46
+ version_requirements: *70311534138560
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: &70311534138080 !ruby/object:Gem::Requirement
57
50
  none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70311534138080
62
58
  - !ruby/object:Gem::Dependency
63
59
  name: bundler
64
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70311534137600 !ruby/object:Gem::Requirement
65
61
  none: false
66
62
  requirements:
67
63
  - - ! '>='
@@ -69,15 +65,10 @@ dependencies:
69
65
  version: 1.0.0
70
66
  type: :development
71
67
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: 1.0.0
68
+ version_requirements: *70311534137600
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70311534137120 !ruby/object:Gem::Requirement
81
72
  none: false
82
73
  requirements:
83
74
  - - ! '>='
@@ -85,15 +76,10 @@ dependencies:
85
76
  version: '0'
86
77
  type: :development
87
78
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
79
+ version_requirements: *70311534137120
94
80
  - !ruby/object:Gem::Dependency
95
81
  name: sqlite3
96
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &70311534136640 !ruby/object:Gem::Requirement
97
83
  none: false
98
84
  requirements:
99
85
  - - ! '>='
@@ -101,15 +87,10 @@ dependencies:
101
87
  version: '0'
102
88
  type: :development
103
89
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
90
+ version_requirements: *70311534136640
110
91
  - !ruby/object:Gem::Dependency
111
92
  name: tzinfo
112
- requirement: !ruby/object:Gem::Requirement
93
+ requirement: &70311534136160 !ruby/object:Gem::Requirement
113
94
  none: false
114
95
  requirements:
115
96
  - - ! '>='
@@ -117,15 +98,10 @@ dependencies:
117
98
  version: '0'
118
99
  type: :development
119
100
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
101
+ version_requirements: *70311534136160
126
102
  - !ruby/object:Gem::Dependency
127
103
  name: rspec
128
- requirement: !ruby/object:Gem::Requirement
104
+ requirement: &70311534135680 !ruby/object:Gem::Requirement
129
105
  none: false
130
106
  requirements:
131
107
  - - ! '>='
@@ -133,15 +109,21 @@ dependencies:
133
109
  version: '0'
134
110
  type: :development
135
111
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
112
+ version_requirements: *70311534135680
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec-rails
115
+ requirement: &70311534135200 !ruby/object:Gem::Requirement
137
116
  none: false
138
117
  requirements:
139
118
  - - ! '>='
140
119
  - !ruby/object:Gem::Version
141
120
  version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70311534135200
142
124
  - !ruby/object:Gem::Dependency
143
125
  name: rr
144
- requirement: !ruby/object:Gem::Requirement
126
+ requirement: &70311534134720 !ruby/object:Gem::Requirement
145
127
  none: false
146
128
  requirements:
147
129
  - - ! '>='
@@ -149,15 +131,10 @@ dependencies:
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
134
+ version_requirements: *70311534134720
158
135
  - !ruby/object:Gem::Dependency
159
136
  name: capybara
160
- requirement: !ruby/object:Gem::Requirement
137
+ requirement: &70311534134240 !ruby/object:Gem::Requirement
161
138
  none: false
162
139
  requirements:
163
140
  - - ! '>='
@@ -165,15 +142,10 @@ dependencies:
165
142
  version: '1.0'
166
143
  type: :development
167
144
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '1.0'
145
+ version_requirements: *70311534134240
174
146
  - !ruby/object:Gem::Dependency
175
147
  name: database_cleaner
176
- requirement: !ruby/object:Gem::Requirement
148
+ requirement: &70311534133760 !ruby/object:Gem::Requirement
177
149
  none: false
178
150
  requirements:
179
151
  - - ! '>='
@@ -181,15 +153,10 @@ dependencies:
181
153
  version: '0'
182
154
  type: :development
183
155
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ! '>='
188
- - !ruby/object:Gem::Version
189
- version: '0'
156
+ version_requirements: *70311534133760
190
157
  - !ruby/object:Gem::Dependency
191
158
  name: rdoc
192
- requirement: !ruby/object:Gem::Requirement
159
+ requirement: &70311533885740 !ruby/object:Gem::Requirement
193
160
  none: false
194
161
  requirements:
195
162
  - - ! '>='
@@ -197,15 +164,10 @@ dependencies:
197
164
  version: '0'
198
165
  type: :development
199
166
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: '0'
167
+ version_requirements: *70311533885740
206
168
  - !ruby/object:Gem::Dependency
207
169
  name: webmock
208
- requirement: !ruby/object:Gem::Requirement
170
+ requirement: &70311533884500 !ruby/object:Gem::Requirement
209
171
  none: false
210
172
  requirements:
211
173
  - - ! '>='
@@ -213,12 +175,7 @@ dependencies:
213
175
  version: '0'
214
176
  type: :development
215
177
  prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- none: false
218
- requirements:
219
- - - ! '>='
220
- - !ruby/object:Gem::Version
221
- version: '0'
178
+ version_requirements: *70311533884500
222
179
  description: This gem provides exception reporting with Errplane for Rails 3.x applications.
223
180
  email:
224
181
  - todd@errplane.com
@@ -227,7 +184,6 @@ extensions: []
227
184
  extra_rdoc_files: []
228
185
  files:
229
186
  - .gitignore
230
- - .rvmrc
231
187
  - Gemfile
232
188
  - README.md
233
189
  - Rakefile
@@ -299,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
255
  version: '0'
300
256
  requirements: []
301
257
  rubyforge_project: errplane
302
- rubygems_version: 1.8.24
258
+ rubygems_version: 1.8.17
303
259
  signing_key:
304
260
  specification_version: 3
305
261
  summary: Rails exception reporting for Errplane.
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3-p194@errplane_rails --create