rorvswild 0.2.1 → 0.2.2
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/lib/rorvswild/version.rb +1 -1
- data/lib/rorvswild.rb +31 -24
- data/test/ror_vs_wild_test.rb +7 -15
- 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: defe2d991680e75ff224dcdf201db4410853b1c4
|
4
|
+
data.tar.gz: 6af12c56716629ac4b2a4abed82493639d49ba52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2815352f7222b25537f8a075527cb0a11a8a108029f9a19c91459156784b286519a20321c3a51cc0b9f3e2ecf59da637f8c57d504ab97fbe4da5f58e0c30db9
|
7
|
+
data.tar.gz: 26d522bbce03f923a85ce76f04e54d8476124b90a9d2e205ca85431a5a746a9ad0f369989f0544139093e6c5775cd1060f9aa92c264f5c12a85168ef4c96ddd5
|
data/lib/rorvswild/version.rb
CHANGED
data/lib/rorvswild.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require "rorvswild/version"
|
2
|
+
require "json/ext"
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
2
5
|
|
3
6
|
module RorVsWild
|
4
7
|
def self.new(*args)
|
@@ -59,11 +62,13 @@ module RorVsWild
|
|
59
62
|
|
60
63
|
def setup_callbacks
|
61
64
|
client = self
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
if defined?(Rails)
|
66
|
+
ActiveSupport::Notifications.subscribe("sql.active_record", &method(:after_sql_query))
|
67
|
+
ActiveSupport::Notifications.subscribe("render_template.action_view", &method(:after_view_rendering))
|
68
|
+
ActiveSupport::Notifications.subscribe("process_action.action_controller", &method(:after_http_request))
|
69
|
+
ActiveSupport::Notifications.subscribe("start_processing.action_controller", &method(:before_http_request))
|
70
|
+
ActionController::Base.rescue_from(StandardError) { |exception| client.after_exception(exception, self) }
|
71
|
+
end
|
67
72
|
|
68
73
|
Resque::Job.send(:extend, ResquePlugin) if defined?(Resque::Job)
|
69
74
|
Delayed::Worker.lifecycle.around(:invoke_job, &method(:around_delayed_job)) if defined?(Delayed::Worker)
|
@@ -87,7 +92,7 @@ module RorVsWild
|
|
87
92
|
def after_sql_query(name, start, finish, id, payload)
|
88
93
|
return if !queries || payload[:name] == "EXPLAIN".freeze
|
89
94
|
runtime, sql, plan = compute_duration(start, finish), nil, nil
|
90
|
-
file, line, method =
|
95
|
+
file, line, method = extract_most_relevant_location(caller)
|
91
96
|
# I can't figure out the exact location which triggered the query, so at least the SQL is logged.
|
92
97
|
sql, file, line, method = payload[:sql], "Unknow", 0, "Unknow" if !file
|
93
98
|
sql = payload[:sql] if runtime >= log_sql_threshold
|
@@ -218,7 +223,7 @@ module RorVsWild
|
|
218
223
|
SELECT_REGEX = /\Aselect/i.freeze
|
219
224
|
|
220
225
|
def explain(sql, binds)
|
221
|
-
ActiveRecord::Base.connection.explain(sql, binds) if
|
226
|
+
ActiveRecord::Base.connection.explain(sql, binds) if sql =~ SELECT_REGEX
|
222
227
|
end
|
223
228
|
|
224
229
|
def post_request
|
@@ -240,14 +245,11 @@ module RorVsWild
|
|
240
245
|
post("/errors".freeze, error: hash)
|
241
246
|
end
|
242
247
|
|
243
|
-
|
244
|
-
if location = stack.find { |str| str.include?(Rails.root.to_s) }
|
245
|
-
split_file_location(location.sub(Rails.root.to_s, "".freeze))
|
246
|
-
end
|
247
|
-
end
|
248
|
+
GEM_HOME_REGEX = ENV["GEM_HOME"] ? /\A#{ENV["GEM_HOME"]}/.freeze : nil
|
248
249
|
|
249
|
-
def
|
250
|
-
|
250
|
+
def extract_most_relevant_location(stack)
|
251
|
+
location = stack.find { |str| !(str =~ GEM_HOME_REGEX) } if GEM_HOME_REGEX
|
252
|
+
split_file_location(relative_path(location || stack.first))
|
251
253
|
end
|
252
254
|
|
253
255
|
def split_file_location(location)
|
@@ -268,11 +270,11 @@ module RorVsWild
|
|
268
270
|
end
|
269
271
|
|
270
272
|
def relative_path(path)
|
271
|
-
path.sub(Rails.root.to_s, "".freeze)
|
273
|
+
defined?(Rails) ? path.sub(Rails.root.to_s, "".freeze) : path
|
272
274
|
end
|
273
275
|
|
274
276
|
def exception_to_hash(exception, extra_details = nil)
|
275
|
-
file, line, method =
|
277
|
+
file, line, method = extract_most_relevant_location(exception.backtrace)
|
276
278
|
{
|
277
279
|
method: method,
|
278
280
|
line: line.to_i,
|
@@ -296,21 +298,26 @@ module RorVsWild
|
|
296
298
|
end
|
297
299
|
|
298
300
|
def filter_sensitive_data(hash)
|
299
|
-
|
300
|
-
|
301
|
+
if defined?(Rails)
|
302
|
+
@sensitive_filter ||= ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
|
303
|
+
@sensitive_filter.filter(hash)
|
304
|
+
else
|
305
|
+
hash
|
306
|
+
end
|
301
307
|
end
|
302
308
|
|
303
309
|
def filter_environment_variables(hash)
|
304
310
|
hash.clone.keep_if { |key,value| key == key.upcase }
|
305
311
|
end
|
306
312
|
|
307
|
-
def logger
|
308
|
-
Rails.logger
|
309
|
-
end
|
310
|
-
|
311
313
|
def log_error(exception)
|
312
|
-
|
313
|
-
|
314
|
+
if defined?(Rails)
|
315
|
+
Rails.logger.error("[RorVsWild] " + exception.inspect)
|
316
|
+
Rails.logger.error("[RorVsWild] " + exception.backtrace.join("\n[RorVsWild] "))
|
317
|
+
else
|
318
|
+
$stderr.puts("[RorVsWild] " + exception.inspect)
|
319
|
+
$stderr.puts("[RorVsWild] " + exception.backtrace.join("\n[RorVsWild] "))
|
320
|
+
end
|
314
321
|
end
|
315
322
|
end
|
316
323
|
|
data/test/ror_vs_wild_test.rb
CHANGED
@@ -45,7 +45,7 @@ class RorVsWildTest < MiniTest::Unit::TestCase
|
|
45
45
|
assert_equal(ZeroDivisionError, exception.class)
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def test_catch_error_with_extra_details
|
49
49
|
client.expects(:post_error)
|
50
50
|
exception = RorVsWild.catch_error(foo: "bar") { 1 / 0 }
|
51
51
|
assert_equal(ZeroDivisionError, exception.class)
|
@@ -56,22 +56,14 @@ class RorVsWildTest < MiniTest::Unit::TestCase
|
|
56
56
|
assert_equal(2, RorVsWild.catch_error { 1 + 1 })
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
callstack = ["/
|
61
|
-
assert_equal(%w[/app/models/user.rb 2 method2], client.send(:
|
62
|
-
|
59
|
+
def test_extract_most_relevant_location
|
60
|
+
callstack = ["#{ENV["GEM_HOME"]}/lib/sql.rb:1:in `method1'", "/app/models/user.rb:2:in `method2'"]
|
61
|
+
assert_equal(%w[/app/models/user.rb 2 method2], client.send(:extract_most_relevant_location, callstack))
|
62
|
+
assert_equal(["#{ENV["GEM_HOME"]}/lib/sql.rb", "1", "method1"], client.send(:extract_most_relevant_location, ["#{ENV["GEM_HOME"]}/lib/sql.rb:1:in `method1'"]))
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
|
67
|
-
assert_equal(%w[/app/models/user.rb 2 method2], client.send(:extract_error_location, callstack))
|
68
|
-
|
69
|
-
callstack = ["/ruby/gems/lib/sql.rb:1:in `method1'", "/foo/bar.rb:2:in `method2'"]
|
70
|
-
assert_equal(%w[/ruby/gems/lib/sql.rb 1 method1], client.send(:extract_error_location, callstack))
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_extract_error_location_when_there_is_no_method_name
|
74
|
-
assert_equal(["/foo/bar.rb", "123", nil], client.send(:extract_error_location, ["/foo/bar.rb:123"]))
|
65
|
+
def test_extract_most_relevant_location_when_there_is_no_method_name
|
66
|
+
assert_equal(["/foo/bar.rb", "123", nil], client.send(:extract_most_relevant_location, ["/foo/bar.rb:123"]))
|
75
67
|
end
|
76
68
|
|
77
69
|
private
|
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.2.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|