rorvswild 1.4.4 → 1.4.5

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: 171608a472bba02aca22c38a5ef435ed30f7de99
4
- data.tar.gz: e3e0b6d5583d165c411cd9dfc437b5916a61f798
3
+ metadata.gz: 2a9839d60fe1491b15c28ac0470d2efc320a5bda
4
+ data.tar.gz: 3ec7cf369a9241604a54769fc7fa17c12fd8bbd2
5
5
  SHA512:
6
- metadata.gz: 66c87f4cd4eab22ece86273ec9ec1c8e0666410bb9312d0ed1e93ff87f339e61e6a261dacfb4056feb40a45b0ee1bc26d0ace366c41bc16b7f05df858d508a50
7
- data.tar.gz: c636eda87ef43cf16a3f9e45e6d07f52c06506cd3040889cdac0ed1f360e9afebe614acd880f6b3593ba487bf5b858928344502f89aafdc191fc8fddb4af75be
6
+ metadata.gz: ad3e2443dbb3c308cadba11a3da2faf091f0af3e32cb77ffbf36518ea748450e3891e54afce0cf9b8651ce609ac57945fb78831321a4f1c8b4eb7b59fd08d31c
7
+ data.tar.gz: 90a17b8993c535aadd22a9cd95ef3a457e301ebdcb47ab4325a3168efc16196236ad49d60766816f7c234719d8f1a6dc244d05e89494a40b648b7af18ec0feb8
@@ -2,8 +2,6 @@ require "logger"
2
2
 
3
3
  module RorVsWild
4
4
  class Agent
5
- include RorVsWild::Location
6
-
7
5
  def self.default_config
8
6
  {
9
7
  api_url: "https://www.rorvswild.com/api/v1",
@@ -22,18 +20,15 @@ module RorVsWild
22
20
  end
23
21
  end
24
22
 
25
- attr_reader :config, :app_root, :app_root_regex, :client, :queue
23
+ attr_reader :config, :locator, :client, :queue
26
24
 
27
25
  def initialize(config)
28
26
  @config = self.class.default_config.merge(config)
29
27
  @client = Client.new(@config)
30
28
  @queue = config[:queue] || Queue.new(client)
29
+ @locator = RorVsWild::Locator.new(defined?(Rails) ? Rails.root.to_s : ENV["PWD"])
31
30
 
32
- @app_root = config[:app_root]
33
- @app_root ||= Rails.root.to_s if defined?(Rails)
34
- @app_root_regex = app_root ? /\A#{app_root}/ : nil
35
-
36
- RorVsWild.logger.info("Start RorVsWild #{RorVsWild::VERSION} from #{app_root}")
31
+ RorVsWild.logger.info("Start RorVsWild #{RorVsWild::VERSION}")
37
32
  setup_plugins
38
33
  cleanup_data
39
34
  end
@@ -170,10 +165,10 @@ module RorVsWild
170
165
  end
171
166
 
172
167
  def exception_to_hash(exception, extra_details = nil)
173
- file, line = extract_most_relevant_file_and_line_from_exception(exception)
168
+ file, line = locator.find_most_relevant_file_and_line_from_exception(exception)
174
169
  {
175
170
  line: line.to_i,
176
- file: relative_path(file),
171
+ file: locator.relative_path(file),
177
172
  message: exception.message,
178
173
  backtrace: exception.backtrace || ["No backtrace"],
179
174
  exception: exception.class.to_s,
@@ -0,0 +1,67 @@
1
+ module RorVsWild
2
+ class Locator
3
+ attr_reader :current_path
4
+
5
+ def initialize(current_path = ENV["PWD"])
6
+ @current_path = current_path
7
+ end
8
+
9
+ def find_most_relevant_file_and_line(locations)
10
+ location = find_most_relevant_location(locations)
11
+ [relative_path(location.path), location.lineno]
12
+ end
13
+
14
+ def find_most_relevant_location(locations)
15
+ locations.find { |l| relevant_path?(l.path) } || locations.find { |l| !irrelevant_path?(l.path) } || locations.first
16
+ end
17
+
18
+ def find_most_relevant_file_and_line_from_exception(exception)
19
+ # Exception#backtrace_locations is faster but exists since 2.1.0.
20
+ # Sometime Exception#backtrace_locations returns nil for an unknow reason. So we fallback to the old way.
21
+ if exception.respond_to?(:backtrace_locations) && locations = exception.backtrace_locations
22
+ find_most_relevant_file_and_line(locations)
23
+ elsif (backtrace = exception.backtrace) && backtrace.size > 0
24
+ find_most_relevant_file_and_line_from_array_of_strings(backtrace)
25
+ else
26
+ ["No backtrace".freeze, 1]
27
+ end
28
+ end
29
+
30
+ def find_most_relevant_file_and_line_from_array_of_strings(stack)
31
+ location = stack.find { |str| relevant_path?(str) }
32
+ location ||= stack.find { |str| !irrelevant_path?(str) }
33
+ relative_path(location || stack.first).split(":".freeze)
34
+ end
35
+
36
+ def relative_path(path)
37
+ path.index(current_path) == 0 ? path.sub(current_path, "".freeze) : path
38
+ end
39
+
40
+ def relevant_path?(path)
41
+ path.index(current_path) == 0 && !irrelevant_path?(path)
42
+ end
43
+
44
+ def irrelevant_path?(path)
45
+ irrelevant_paths.any? { |irrelevant_path| path.index(irrelevant_path) }
46
+ end
47
+
48
+ def irrelevant_paths
49
+ @irrelevant_paths ||= initialize_irrelevant_paths
50
+ end
51
+
52
+ private
53
+
54
+ def initialize_irrelevant_paths
55
+ array = ["RUBYLIB", "GEM_HOME", "GEM_PATH", "BUNDLER_ORIG_PATH", "BUNDLER_ORIG_GEM_PATH"].flat_map do |name|
56
+ ENV[name].split(":".freeze) if ENV[name]
57
+ end
58
+ array += [heroku_ruby_lib_path] if File.exists?(heroku_ruby_lib_path)
59
+ array += Gem.path
60
+ array.compact.uniq
61
+ end
62
+
63
+ def heroku_ruby_lib_path
64
+ "/app/vendor/ruby-#{RUBY_VERSION}/lib"
65
+ end
66
+ end
67
+ end
@@ -24,6 +24,7 @@ module RorVsWild
24
24
  RorVsWild::Section.start do |section|
25
25
  method_name = controller.method_for_action(controller.action_name)
26
26
  section.file, section.line = controller.method(method_name).source_location
27
+ section.file = RorVsWild.agent.locator.relative_path(section.file)
27
28
  section.command = "#{controller.class}##{method_name}"
28
29
  section.kind = "code".freeze
29
30
  end
@@ -16,7 +16,7 @@ module RorVsWild
16
16
  def finish(name, id, payload)
17
17
  RorVsWild::Section.stop do |section|
18
18
  section.kind = "view".freeze
19
- section.command = RorVsWild.agent.relative_path(payload[:identifier])
19
+ section.command = RorVsWild.agent.locator.relative_path(payload[:identifier])
20
20
  section.file = section.command
21
21
  section.line = 1
22
22
  end
@@ -31,8 +31,8 @@ module RorVsWild
31
31
  @total_runtime = 0
32
32
  @children_runtime = 0
33
33
  @started_at = RorVsWild.clock_milliseconds
34
- location = RorVsWild.agent.find_most_relevant_location(caller_locations)
35
- @file = RorVsWild.agent.relative_path(location.path)
34
+ location = RorVsWild.agent.locator.find_most_relevant_location(caller_locations)
35
+ @file = RorVsWild.agent.locator.relative_path(location.path)
36
36
  @line = location.lineno
37
37
  @appendable_command = false
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.4.4".freeze
2
+ VERSION = "1.4.5".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "rorvswild/version"
2
- require "rorvswild/location"
2
+ require "rorvswild/locator"
3
3
  require "rorvswild/section"
4
4
  require "rorvswild/client"
5
5
  require "rorvswild/plugins"
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: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2019-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Performances and quality insights for rails developers.
14
14
  email:
@@ -36,7 +36,7 @@ files:
36
36
  - lib/rorvswild/local/queue.rb
37
37
  - lib/rorvswild/local/stylesheet/local.css
38
38
  - lib/rorvswild/local/stylesheet/vendor/prism.css
39
- - lib/rorvswild/location.rb
39
+ - lib/rorvswild/locator.rb
40
40
  - lib/rorvswild/plugin/action_controller.rb
41
41
  - lib/rorvswild/plugin/action_mailer.rb
42
42
  - lib/rorvswild/plugin/action_view.rb
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.5.1
77
+ rubygems_version: 2.5.2
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Ruby on Rails app monitoring
@@ -1,51 +0,0 @@
1
- module RorVsWild
2
- module Location
3
- def extract_most_relevant_file_and_line(locations)
4
- location = find_most_relevant_location(locations)
5
- [relative_path(location.path), location.lineno]
6
- end
7
-
8
- def find_most_relevant_location(locations)
9
- result = locations.find { |l| l.path.index(app_root) == 0 && !(l.path =~ gem_home_regex) } if app_root
10
- result || locations.find { |l| !(l.path =~ gem_home_regex) } || locations.first
11
- end
12
-
13
- def extract_most_relevant_file_and_line_from_exception(exception)
14
- # Exception#backtrace_locations is faster but exists since 2.1.0.
15
- # Sometime Exception#backtrace_locations returns nil for an unknow reason. So we fallback to the old way.
16
- if exception.respond_to?(:backtrace_locations) && locations = exception.backtrace_locations
17
- extract_most_relevant_file_and_line(locations)
18
- elsif (backtrace = exception.backtrace) && backtrace.size > 0
19
- extract_most_relevant_file_and_line_from_array_of_strings(backtrace)
20
- else
21
- ["No backtrace".freeze, 1]
22
- end
23
- end
24
-
25
- def extract_most_relevant_file_and_line_from_array_of_strings(stack)
26
- location = stack.find { |str| str =~ app_root_regex && !(str =~ gem_home_regex) } if app_root_regex
27
- location ||= stack.find { |str| !(str =~ gem_home_regex) } if gem_home_regex
28
- relative_path(location || stack.first).split(":".freeze)
29
- end
30
-
31
- def gem_home_regex
32
- @gem_home_regex ||= gem_home ? /\A#{gem_home}/.freeze : /\/gems\//.freeze
33
- end
34
-
35
- def gem_home
36
- @gem_home ||= guess_gem_home
37
- end
38
-
39
- def guess_gem_home
40
- if ENV["GEM_HOME"] && !ENV["GEM_HOME"].empty?
41
- ENV["GEM_HOME"]
42
- elsif ENV["GEM_PATH"] && !(first_gem_path = ENV["GEM_PATH"].split(":").first)
43
- first_gem_path if first_gem_path && !first_gem_path.empty?
44
- end
45
- end
46
-
47
- def relative_path(path)
48
- app_root_regex ? path.sub(app_root_regex, "".freeze) : path
49
- end
50
- end
51
- end