roqua-support 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/roqua-support/version.rb +1 -1
- data/lib/roqua/support/errors.rb +78 -32
- data/spec/roqua/support/errors_spec.rb +21 -2
- 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: 283954f3f130b821ad3df69490094c4117afe0d7
|
4
|
+
data.tar.gz: e3e51403c9b74b86754ed04536f2731a47ac4dc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e51b6995e2dd2fe974c7ef00ea4f5d2408950296fb9a90eb28c654f5e1b4dd88fe5f7f961c1767c660218e39f5b35301296c52021252cd1c14275b7874f39b4
|
7
|
+
data.tar.gz: 03cb728c081c0e926db89b5c8814281c904d4f608c82c17db3764c6f160e317aa0995c2297e58a558681bbed3ded85f10554417fb2a21b128aafa4e24fa22201
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/roqua/support/errors.rb
CHANGED
@@ -9,46 +9,92 @@ module Roqua
|
|
9
9
|
@extra_parameters = hash
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.report(exception,
|
12
|
+
def self.report(exception, context = {})
|
13
13
|
return if const_defined?(:Rails) and Rails.env.test?
|
14
|
-
controller =
|
15
|
-
parameters = extra_parameters.merge(extra_params)
|
16
|
-
|
14
|
+
parameters, controller = merge_parameters(context)
|
17
15
|
# Notify Roqua logging
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
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.
|
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-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|