rorvswild 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cacert.pem +3988 -0
- data/lib/rorvswild/version.rb +1 -1
- data/lib/rorvswild.rb +18 -6
- data/test/ror_vs_wild_test.rb +15 -0
- metadata +3 -2
data/lib/rorvswild/version.rb
CHANGED
data/lib/rorvswild.rb
CHANGED
@@ -56,14 +56,16 @@ module RorVsWild
|
|
56
56
|
{
|
57
57
|
api_url: "https://www.rorvswild.com/api",
|
58
58
|
explain_sql_threshold: 500,
|
59
|
+
ignored_exceptions: [],
|
59
60
|
}
|
60
61
|
end
|
61
62
|
|
62
|
-
attr_reader :api_url, :api_key, :app_id, :explain_sql_threshold, :app_root, :app_root_regex
|
63
|
+
attr_reader :api_url, :api_key, :app_id, :explain_sql_threshold, :app_root, :app_root_regex, :ignored_exceptions
|
63
64
|
|
64
65
|
def initialize(config)
|
65
66
|
config = self.class.default_config.merge(config)
|
66
67
|
@explain_sql_threshold = config[:explain_sql_threshold]
|
68
|
+
@ignored_exceptions = config[:ignored_exceptions]
|
67
69
|
@app_root = config[:app_root]
|
68
70
|
@api_url = config[:api_url]
|
69
71
|
@api_key = config[:api_key]
|
@@ -74,7 +76,9 @@ module RorVsWild
|
|
74
76
|
if defined?(Rails)
|
75
77
|
@logger ||= Rails.logger
|
76
78
|
@app_root ||= Rails.root.to_s
|
77
|
-
|
79
|
+
config = Rails.application.config
|
80
|
+
@parameter_filter = ActionDispatch::Http::ParameterFilter.new(config.filter_parameters)
|
81
|
+
@ignored_exceptions = %w[ActionController::RoutingError] + config.action_dispatch.rescue_responses.map { |(key,value)| key }
|
78
82
|
end
|
79
83
|
|
80
84
|
@logger ||= Logger.new(STDERR)
|
@@ -88,6 +92,7 @@ module RorVsWild
|
|
88
92
|
client = self
|
89
93
|
if defined?(ActiveSupport::Notifications)
|
90
94
|
ActiveSupport::Notifications.subscribe("sql.active_record", &method(:after_sql_query))
|
95
|
+
ActiveSupport::Notifications.subscribe("render_partial.action_view", &method(:after_view_rendering))
|
91
96
|
ActiveSupport::Notifications.subscribe("render_template.action_view", &method(:after_view_rendering))
|
92
97
|
ActiveSupport::Notifications.subscribe("process_action.action_controller", &method(:after_http_request))
|
93
98
|
ActiveSupport::Notifications.subscribe("start_processing.action_controller", &method(:before_http_request))
|
@@ -135,7 +140,7 @@ module RorVsWild
|
|
135
140
|
end
|
136
141
|
|
137
142
|
def after_exception(exception, controller)
|
138
|
-
if !
|
143
|
+
if !ignored_exceptions.include?(exception.class.to_s)
|
139
144
|
file, line = exception.backtrace.first.split(":")
|
140
145
|
request[:error] = exception_to_hash(exception).merge(
|
141
146
|
session: controller.session.to_hash,
|
@@ -312,17 +317,24 @@ module RorVsWild
|
|
312
317
|
}
|
313
318
|
end
|
314
319
|
|
320
|
+
HTTPS = "https".freeze
|
321
|
+
CERTIFICATE_AUTHORITIES_PATH = File.expand_path("../../cacert.pem", __FILE__)
|
322
|
+
|
315
323
|
def post(path, data)
|
316
324
|
uri = URI(api_url + path)
|
317
325
|
http = Net::HTTP.new(uri.host, uri.port)
|
318
|
-
|
319
|
-
|
326
|
+
|
327
|
+
if uri.scheme == HTTPS
|
328
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
329
|
+
http.ca_file = CERTIFICATE_AUTHORITIES_PATH
|
330
|
+
http.use_ssl = true
|
331
|
+
end
|
320
332
|
|
321
333
|
post = Net::HTTP::Post.new(uri.path)
|
322
334
|
post.content_type = "application/json".freeze
|
323
335
|
post.basic_auth(app_id, api_key)
|
324
336
|
post.body = data.to_json
|
325
|
-
|
337
|
+
http.request(post)
|
326
338
|
end
|
327
339
|
|
328
340
|
def filter_sensitive_data(hash)
|
data/test/ror_vs_wild_test.rb
CHANGED
@@ -87,6 +87,21 @@ class RorVsWildTest < MiniTest::Unit::TestCase
|
|
87
87
|
assert_equal([{file: "file", line: 123, sql: "SELECT 2", runtime: 21, max_runtime: 11, times: 2, plan: nil,}], client.send(:queries))
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_after_exception
|
91
|
+
exception, controller = nil, stub(session: {}, request: stub(env: ENV))
|
92
|
+
begin; 1/0; rescue => exception; end
|
93
|
+
assert_raises(ZeroDivisionError) { client.after_exception(exception, controller) }
|
94
|
+
assert_equal("ZeroDivisionError", client.send(:request)[:error][:exception])
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_after_exception_when_ignored
|
98
|
+
client = initialize_client(ignored_exceptions: %w[ZeroDivisionError])
|
99
|
+
exception, controller = nil, stub(session: {}, request: stub(env: ENV))
|
100
|
+
begin; raise 1/0; rescue => exception; end
|
101
|
+
assert_raises(ZeroDivisionError) { client.after_exception(exception, controller) }
|
102
|
+
refute(client.send(:request)[:error])
|
103
|
+
end
|
104
|
+
|
90
105
|
private
|
91
106
|
|
92
107
|
def client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rorvswild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Bernard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.md
|
39
39
|
- Rakefile
|
40
|
+
- cacert.pem
|
40
41
|
- lib/rorvswild.rb
|
41
42
|
- lib/rorvswild/version.rb
|
42
43
|
- rorvswild.gemspec
|