roqua-support 0.1.13 → 0.1.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 803305fe155529f0da3dfa1ab3e12ac47b94f111
4
- data.tar.gz: 61f3227e70ac8bf18a145d07e726ef8743ff2d85
3
+ metadata.gz: 283954f3f130b821ad3df69490094c4117afe0d7
4
+ data.tar.gz: e3e51403c9b74b86754ed04536f2731a47ac4dc4
5
5
  SHA512:
6
- metadata.gz: 693863caf7baa5a55fda02d6c75f8fe3b9d5e7fbd144270f704dc1aac1ac881ac6d4ff3ce5ca22a594bf69f19efa491910a071fb2b3153c23f46f742cfeab8c2
7
- data.tar.gz: 2f09d28afd8b73299c5754a739e66001af653000c649616c6ce1a4721410d45ed8d436ac738a745e5d90522a32f99acf58386ba893eb0d39e021f0da7313df77
6
+ metadata.gz: 0e51b6995e2dd2fe974c7ef00ea4f5d2408950296fb9a90eb28c654f5e1b4dd88fe5f7f961c1767c660218e39f5b35301296c52021252cd1c14275b7874f39b4
7
+ data.tar.gz: 03cb728c081c0e926db89b5c8814281c904d4f608c82c17db3764c6f160e317aa0995c2297e58a558681bbed3ded85f10554417fb2a21b128aafa4e24fa22201
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.14 / 2014-11-13
2
+
3
+ * Don't put request data under params
4
+ * Robustify reporting exceptions
5
+
1
6
  ## 0.1.13 / 2014-11-12
2
7
 
3
8
  * Add support for reporting request data to Airbrake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roqua-support (0.1.13)
4
+ roqua-support (0.1.14)
5
5
  activesupport (>= 3.2, < 5.0)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = '0.1.13'
3
+ VERSION = '0.1.14'
4
4
  end
5
5
  end
@@ -9,46 +9,92 @@ module Roqua
9
9
  @extra_parameters = hash
10
10
  end
11
11
 
12
- def self.report(exception, extra_params = {})
12
+ def self.report(exception, context = {})
13
13
  return if const_defined?(:Rails) and Rails.env.test?
14
- controller = extra_params.delete :controller
15
- parameters = extra_parameters.merge(extra_params)
16
-
14
+ parameters, controller = merge_parameters(context)
17
15
  # Notify Roqua logging
18
- if Roqua.respond_to?(:logger)
19
- Roqua.logger.error('roqua.exception',
20
- class_name: exception.class.to_s,
21
- message: exception.message,
22
- backtrace: exception.backtrace,
23
- parameters: parameters)
16
+ log_exception(exception, parameters)
17
+ # Notify Airbrake
18
+ notify_airbrake(exception, controller, parameters)
19
+ # Notify AppSignal
20
+ notify_appsignal(exception, parameters)
21
+ end
22
+
23
+ private
24
+
25
+ def self.merge_parameters(context)
26
+ begin
27
+ if context.is_a?(Hash) && extra_parameters.is_a?(Hash)
28
+ controller = context.delete :controller
29
+ parameters = extra_parameters.merge(context)
30
+ elsif context.is_a?(Hash)
31
+ controller = context.delete :controller
32
+ parameters = context
33
+ elsif extra_parameters.is_a?(Hash)
34
+ parameters = extra_parameters
35
+ end
36
+ [parameters, controller]
37
+ rescue Exception
24
38
  end
39
+ end
25
40
 
26
- # Notify Airbrake
27
- if const_defined?(:Airbrake)
28
- parameters = parameters.merge controller.airbrake_request_data if controller
29
- Airbrake.notify_or_ignore(exception, parameters: parameters)
41
+ def self.log_exception(exception, parameters = {})
42
+ begin
43
+ if Roqua.respond_to?(:logger)
44
+ Roqua.logger.error('roqua.exception',
45
+ class_name: exception.class.to_s,
46
+ message: exception.message,
47
+ backtrace: exception.backtrace,
48
+ parameters: parameters)
49
+ end
50
+ rescue Exception
30
51
  end
52
+ end
31
53
 
32
- # Notify AppSignal
33
- if const_defined?(:Appsignal) and
34
- not Appsignal.is_ignored_exception?(exception)
35
- # TODO: If and when https://github.com/appsignal/appsignal/pull/9 is merged,
36
- # this functionality should be supported directly by Appsignal.send_exception.
37
- # Appsignal.send_exception(exception, parameters: parameters)
38
-
39
- if Appsignal.active?
40
- # Hackety hack around stateful mess of Appsignal gem
41
- if Appsignal::Transaction.current
42
- Appsignal::Transaction.current.set_tags(parameters)
43
- Appsignal::Transaction.current.add_exception(exception)
44
- else
45
- transaction = Appsignal::Transaction.create(SecureRandom.uuid, ENV.to_hash)
46
- transaction.set_tags(parameters)
47
- transaction.add_exception(exception)
48
- transaction.complete!
49
- Appsignal.agent.send_queue
54
+ def self.notify_airbrake(exception, controller, parameters = {})
55
+ begin
56
+ if const_defined?(:Airbrake)
57
+ if controller && controller.respond_to?(:airbrake_request_data)
58
+ request_data = controller.airbrake_request_data
59
+ if request_data.is_a?(Hash)
60
+ request_data[:parameters] ||= {}
61
+ if request_data[:parameters].is_a?(Hash)
62
+ request_data[:parameters] = parameters.merge request_data[:parameters]
63
+ end
64
+ else
65
+ request_data = nil
66
+ end
67
+ end
68
+ request_data ||= {parameters: parameters}
69
+ Airbrake.notify_or_ignore(exception, request_data)
70
+ end
71
+ rescue Exception
72
+ end
73
+ end
74
+
75
+ def self.notify_appsignal(exception, parameters = {})
76
+ begin
77
+ if const_defined?(:Appsignal) and
78
+ not Appsignal.is_ignored_exception?(exception)
79
+ # TODO: If and when https://github.com/appsignal/appsignal/pull/9 is merged,
80
+ # this functionality should be supported directly by Appsignal.send_exception.
81
+ # Appsignal.send_exception(exception, parameters: parameters)
82
+
83
+ if Appsignal.active?
84
+ # Hackety hack around stateful mess of Appsignal gem
85
+ if Appsignal::Transaction.current
86
+ Appsignal::Transaction.current.set_tags(parameters)
87
+ Appsignal::Transaction.current.add_exception(exception)
88
+ else
89
+ transaction = Appsignal::Transaction.create(SecureRandom.uuid, ENV.to_hash)
90
+ transaction.set_tags(parameters)
91
+ transaction.add_exception(exception)
92
+ transaction.complete!
93
+ Appsignal.agent.send_queue
94
+ end
50
95
  end
51
96
  end
97
+ rescue Exception
52
98
  end
53
99
  end
54
100
  end
@@ -37,8 +37,27 @@ describe 'Error reporting' do
37
37
  end
38
38
 
39
39
  it 'adds request data when a controller is passed in' do
40
- controller = double(airbrake_request_data: {request: 'data'})
41
- Airbrake.should_receive(:notify_or_ignore).with(exception, parameters: {request: 'data'})
40
+ controller = double(airbrake_request_data: {request: 'data', parameters: {request: 'param'}})
41
+ expect(Airbrake).to receive(:notify_or_ignore)
42
+ .with(exception, request: 'data', parameters: {request: 'param', some: 'context'})
43
+ Roqua::Support::Errors.report exception, controller: controller, some: 'context'
44
+ end
45
+
46
+ it 'does not fail with extra parameters of incompatible type' do
47
+ Roqua::Support::Errors.extra_parameters = ['extra', 'param']
48
+ expect(Airbrake).to receive(:notify_or_ignore).with(exception, parameters: {})
49
+ Roqua::Support::Errors.report exception
50
+ Roqua::Support::Errors.extra_parameters = {}
51
+ end
52
+
53
+ it 'does not fail with context of incompatible type' do
54
+ expect(Airbrake).to receive(:notify_or_ignore).with(exception, parameters: {})
55
+ Roqua::Support::Errors.report exception, ['controller', 'extra_param']
56
+ end
57
+
58
+ it 'does not fail with request data of incompatible type' do
59
+ controller = double(airbrake_request_data: ['request', 'data'])
60
+ expect(Airbrake).to receive(:notify_or_ignore).with(exception, parameters: {})
42
61
  Roqua::Support::Errors.report exception, controller: controller
43
62
  end
44
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport