rorvswild 1.5.7 → 1.5.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 185e306b95a9f95fe78161e62e5e8e03d43ce8f892ad2350882ba44e07ba7d9e
4
- data.tar.gz: 8b5e2bba0d15a48f1bde89cd804bd56535e957069b6b1acd59ccec96ec4d2857
3
+ metadata.gz: 48093e6f93439e8216bd5b0c631b6b56386281d9792f728312d227634834ee11
4
+ data.tar.gz: 9d7cc84527fc054d47e17ed8f8c736c119660f59d7f077a24b420588875e0685
5
5
  SHA512:
6
- metadata.gz: 15ae6b40fcf59aa4eabe7db0b0068239b49cd4311d2a03014484110fc51c5574ee00b068549298c720aef4bbe2f9280c480b026887589b999a0f41792b89d116
7
- data.tar.gz: bd616d7f191bf7296a4d537e4e9edd81bc4d791e46ecd237da8370c5d3031c697eb43545c429ff2040e8a9e41df2cce68ff1e9a077e2ac1a4a65fa4eb4f05453
6
+ metadata.gz: 55d90ef1666a3e5696cfbf998a13446d8dc2cddeccf05d56d5dcc6aa3855e5bd5443eb0dccd0b2d54e6af00b1e5babce359fabd2899a4a624a0fcb9f5ab1a5c4
7
+ data.tar.gz: 909982650664ed49fed2103c7e031ae761ccea22eb5fd39bb82b85e2e3996fd7ec28b891b2151d41ebeadae6f2076ff3c14d895e0a552c006e444e6178d77754
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/rorvswild.svg)](https://badge.fury.io/rb/rorvswild)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/2c4805cf658d7af794fe/maintainability)](https://codeclimate.com/github/BaseSecrete/rorvswild/maintainability)
6
6
 
7
- <img align="right" src="/images/rorvswild_logo.jpg">
7
+ <img align="right" src="./images/rorvswild_logo.jpg">
8
8
 
9
9
  *RoRvsWild* is a ruby gem to monitor performances and exceptions in Ruby on Rails applications.
10
10
 
@@ -21,7 +21,7 @@ It can also be used in your production and staging environments with an account
21
21
  * Run `bundle install` in you terminal
22
22
  * Restart your local server and you’ll see a small button in the bottom left corner of your page.
23
23
 
24
- ![RoRvsWild Local Button](/images/rorvswild_local_button.jpg)
24
+ ![RoRvsWild Local Button](./images/rorvswild_local_button.jpg)
25
25
 
26
26
  This is all what you need to do to monitor your local environment requests.
27
27
 
@@ -47,15 +47,30 @@ RorVsWild.start(api_key: API_KEY)
47
47
 
48
48
  You can create unlimited apps on *rorvswild.com*. If you want to monitor your staging environment, create a new app and edit your rorvswild.yml to add the API key.
49
49
 
50
+ In case there is no data in the dashboard, you can run in a rails console : `RorVsWild.check`.
51
+
50
52
  ## Development mode: *RoRvsWild Local*
51
53
 
52
- ![RoRvsWild Local](/images/rorvswild_local.jpg)
54
+ ![RoRvsWild Local](./images/rorvswild_local.jpg)
53
55
 
54
56
  *RorVsWild Local* monitors the performances of requests in development environment.
55
57
  It shows most of the requests performances insights *RoRvsWild.com* displays. **A big difference is everything works locally and no data is sent and recorded on our servers**. You don’t even need an account to use it.
56
58
 
57
59
  *RoRvsWild Local* renders a small button in the bottom left corner of your page showing the runtime of the current request. If you click on it, you get all the profiled sections ordered by impact, which is depending on the sections average runtime and the calls count. As on RoRvsWild.com, the bottleneck is always on the top of the list.
58
60
 
61
+ You may want to hide or change the widget position like in the example below with the `widget` option :
62
+
63
+ ```yaml
64
+ # config/rorvswild.yml
65
+
66
+ development:
67
+ widget: top-right
68
+
69
+ #accepted values : top-left, top-right, bottom-right, bottom-left (default), hidden
70
+ ```
71
+
72
+ You can still access the profiler at http://localhost:3000/rorvswild if you choose to hide the widget.
73
+
59
74
  Be aware that the performances on your development machine may vary from the production server. Obviously because of the different hardware and database size. Also, Rails is reloading all the code in development environment and this takes quite a lot of time.
60
75
  To prevent this behaviour and better match the production, turn on cache_classes in your config/environments/development.rb:
61
76
 
@@ -69,7 +84,7 @@ If you are using `Rack::Deflater` middleware you won't see the small button in t
69
84
 
70
85
  ## Production mode: *RoRvsWild.com*
71
86
 
72
- ![RoRvsWild.com](/images/rorvswild_prod.jpg)
87
+ ![RoRvsWild.com](./images/rorvswild_prod.jpg)
73
88
 
74
89
  *RoRvsWild.com* makes it easy to monitor requests, background jobs and errors in your production and staging environment.
75
90
  It also comes with some extra options listed below.
@@ -1,4 +1,6 @@
1
1
  require "logger"
2
+ require "socket"
3
+ require "etc"
2
4
 
3
5
  module RorVsWild
4
6
  class Agent
@@ -26,9 +28,9 @@ module RorVsWild
26
28
  @config = self.class.default_config.merge(config)
27
29
  @client = Client.new(@config)
28
30
  @queue = config[:queue] || Queue.new(client)
29
- @locator = RorVsWild::Locator.new(defined?(Rails) ? Rails.root.to_s : ENV["PWD"])
31
+ @locator = RorVsWild::Locator.new
30
32
 
31
- RorVsWild.logger.info("Start RorVsWild #{RorVsWild::VERSION}")
33
+ RorVsWild.logger.debug("Start RorVsWild #{RorVsWild::VERSION}")
32
34
  setup_plugins
33
35
  cleanup_data
34
36
  end
@@ -37,7 +39,7 @@ module RorVsWild
37
39
  for name in RorVsWild::Plugin.constants
38
40
  next if config[:ignore_plugins] && config[:ignore_plugins].include?(name.to_s)
39
41
  if (plugin = RorVsWild::Plugin.const_get(name)).respond_to?(:setup)
40
- RorVsWild.logger.info("Setup RorVsWild::Plugin::#{name}")
42
+ RorVsWild.logger.debug("Setup RorVsWild::Plugin::#{name}")
41
43
  plugin.setup
42
44
  end
43
45
  end
@@ -72,7 +74,7 @@ module RorVsWild
72
74
  begin
73
75
  block.call
74
76
  rescue Exception => ex
75
- push_exception(ex, parameters: parameters)
77
+ push_exception(ex, parameters: parameters, job: {name: name})
76
78
  raise
77
79
  ensure
78
80
  current_data[:runtime] = RorVsWild.clock_milliseconds - current_data[:started_at]
@@ -105,6 +107,7 @@ module RorVsWild
105
107
 
106
108
  def push_exception(exception, options = nil)
107
109
  return if ignored_exception?(exception)
110
+ return unless current_data
108
111
  current_data[:error] = exception_to_hash(exception)
109
112
  current_data[:error].merge!(options) if options
110
113
  current_data[:error]
@@ -168,11 +171,26 @@ module RorVsWild
168
171
  backtrace: exception.backtrace || ["No backtrace"],
169
172
  exception: exception.class.to_s,
170
173
  extra_details: extra_details,
174
+ environment: {
175
+ os: os_description,
176
+ user: Etc.getlogin,
177
+ host: Socket.gethostname,
178
+ ruby: RUBY_DESCRIPTION,
179
+ pid: Process.pid,
180
+ cwd: Dir.pwd,
181
+ lib_paths: locator.lib_paths,
182
+ },
171
183
  }
172
184
  end
173
185
 
174
186
  def ignored_exception?(exception)
175
187
  (config[:ignored_exceptions] || config[:ignore_exceptions]).include?(exception.class.to_s)
176
188
  end
189
+
190
+ def os_description
191
+ @os_description ||= `uname -a`
192
+ rescue Exception => ex
193
+ @os_description = RUBY_PLATFORM
194
+ end
177
195
  end
178
196
  end
@@ -21,7 +21,11 @@ module RorVsWild
21
21
  @connection_count = 0
22
22
  @mutex = Mutex.new
23
23
  @config = config
24
- @headers = {"Content-Type" => "application/json", "X-Gem-Version" => RorVsWild::VERSION}
24
+ @headers = {
25
+ "Content-Type" => "application/json",
26
+ "X-RorVsWild-Version" => RorVsWild::VERSION,
27
+ "X-Ruby-Version" => RUBY_VERSION,
28
+ }
25
29
  @headers["X-Rails-Version"] = Rails.version if defined?(Rails)
26
30
  end
27
31
 
@@ -3,9 +3,9 @@ require "rorvswild/local/queue"
3
3
 
4
4
  module RorVsWild
5
5
  module Local
6
- def self.start
6
+ def self.start(config = {})
7
7
  Rails.application.config.middleware.unshift(RorVsWild::Local::Middleware, nil)
8
- RorVsWild.start(queue: RorVsWild::Local::Queue.new)
8
+ RorVsWild.start(config.merge(queue: RorVsWild::Local::Queue.new))
9
9
  end
10
10
  end
11
11
  end
@@ -1,4 +1,4 @@
1
- <div id="RorVsWild.Local">
1
+ <div id="RorVsWild.Local" class="<%= widget_css %>">
2
2
  <div data-barber="RorVsWild.Local">
3
3
  </div>
4
4
  </div>
@@ -26,6 +26,7 @@ module RorVsWild
26
26
 
27
27
  def serve_embed_profiler(env)
28
28
  status, headers, body = app.call(env)
29
+ status = status.to_i
29
30
  if status >= 200 && status < 300 && headers["Content-Type"] && headers["Content-Type"].include?("text/html")
30
31
  if headers["Content-Encoding"]
31
32
  log_incompatible_middleware_warning
@@ -55,9 +56,15 @@ module RorVsWild
55
56
 
56
57
  private
57
58
 
59
+ def widget_css
60
+ config = RorVsWild.agent.config
61
+ config && config[:widget] && "is-#{config[:widget]}"
62
+ end
63
+
58
64
  def inject_into(html)
59
65
  if index = html.index("</body>")
60
- markup = File.read(File.join(LOCAL_FOLDER, "local.html"))
66
+ markup = File.read(File.join(LOCAL_FOLDER, "local.html.erb"))
67
+ markup = ERB.new(markup).result(binding)
61
68
  markup = markup.html_safe if markup.respond_to?(:html_safe)
62
69
  html.insert(index, markup)
63
70
  end
@@ -25,6 +25,30 @@
25
25
  display: inline-block !important;
26
26
  }
27
27
 
28
+ /************* TOGGLER POSITION OPTION(default bottom-left)**********************/
29
+
30
+ .is-top-right .rorvswild-local-toggler {
31
+ bottom: auto !important;
32
+ left: auto !important;
33
+ right: 12px !important;
34
+ top: 12px !important;
35
+ }
36
+
37
+ .is-top-left .rorvswild-local-toggler {
38
+ bottom: auto !important;
39
+ top: 12px !important;
40
+ }
41
+
42
+ .is-bottom-right .rorvswild-local-toggler {
43
+ bottom: 12px !important;
44
+ left: auto !important;
45
+ right: 12px !important;
46
+ }
47
+
48
+ .is-hidden .rorvswild-local-toggler {
49
+ display: none;
50
+ }
51
+
28
52
  /********************************************/
29
53
  /*************** PANEL **********************/
30
54
  /********************************************/
@@ -2,8 +2,8 @@ module RorVsWild
2
2
  class Locator
3
3
  attr_reader :current_path
4
4
 
5
- def initialize(current_path = ENV["PWD"])
6
- @current_path = current_path
5
+ def initialize(current_path = Dir.pwd)
6
+ @current_path = File.join(current_path, "")
7
7
  end
8
8
 
9
9
  def find_most_relevant_file_and_line(locations)
@@ -12,7 +12,7 @@ module RorVsWild
12
12
  end
13
13
 
14
14
  def find_most_relevant_location(locations)
15
- locations.find { |l| relevant_path?(l.path) } || locations.find { |l| !irrelevant_path?(l.path) } || locations.first
15
+ locations.find { |l| relevant_path?(l.path) } || locations.find { |l| !l.path.start_with?(rorvswild_lib_path) } || locations.first
16
16
  end
17
17
 
18
18
  def find_most_relevant_file_and_line_from_exception(exception)
@@ -29,7 +29,7 @@ module RorVsWild
29
29
 
30
30
  def find_most_relevant_file_and_line_from_array_of_strings(stack)
31
31
  location = stack.find { |str| relevant_path?(str) }
32
- location ||= stack.find { |str| !irrelevant_path?(str) }
32
+ location ||= stack.find { |str| !str.start_with?(rorvswild_lib_path) }
33
33
  relative_path(location || stack.first).split(":".freeze)
34
34
  end
35
35
 
@@ -42,26 +42,25 @@ module RorVsWild
42
42
  end
43
43
 
44
44
  def irrelevant_path?(path)
45
- path.start_with?(*irrelevant_paths)
45
+ path.start_with?(*lib_paths)
46
46
  end
47
47
 
48
- def irrelevant_paths
49
- @irrelevant_paths ||= initialize_irrelevant_paths
48
+ def lib_paths
49
+ @lib_paths ||= initialize_lib_paths
50
+ end
51
+
52
+ def rorvswild_lib_path
53
+ @rorvswild_lib_path ||= File.dirname(File.expand_path(__FILE__))
50
54
  end
51
55
 
52
56
  private
53
57
 
54
- def initialize_irrelevant_paths
55
- array = ["RUBYLIB", "GEM_HOME", "GEM_PATH", "BUNDLER_ORIG_GEM_PATH"].flat_map do |name|
58
+ def initialize_lib_paths
59
+ array = [RbConfig::CONFIG["rubylibprefix"]] + Gem.default_path + Gem.path
60
+ array += ["RUBYLIB", "GEM_HOME", "GEM_PATH", "BUNDLER_ORIG_GEM_PATH"].flat_map do |name|
56
61
  ENV[name].split(":".freeze) if ENV[name]
57
62
  end
58
- array += [heroku_ruby_lib_path] if File.exists?(heroku_ruby_lib_path)
59
- array += Gem.path
60
63
  array.compact.uniq
61
64
  end
62
-
63
- def heroku_ruby_lib_path
64
- "/app/vendor/ruby-#{RUBY_VERSION}/lib"
65
- end
66
65
  end
67
66
  end
@@ -23,7 +23,7 @@ module RorVsWild
23
23
  section.file, section.line = controller.method(method_name).source_location
24
24
  section.file = RorVsWild.agent.locator.relative_path(section.file)
25
25
  section.command = "#{controller.class}##{method_name}"
26
- RorVsWild.agent.current_data[:name] = controller_action
26
+ RorVsWild.agent.current_data[:name] = controller_action if RorVsWild.agent.current_data
27
27
  end
28
28
  block.call
29
29
  ensure
@@ -35,7 +35,12 @@ module RorVsWild
35
35
  if hash = RorVsWild.agent.push_exception(exception)
36
36
  hash[:session] = controller.session.to_hash
37
37
  hash[:parameters] = controller.request.filtered_parameters
38
- hash[:environment_variables] = extract_http_headers(controller.request.filtered_env)
38
+ hash[:request] = {
39
+ headers: extract_http_headers(controller.request.filtered_env),
40
+ name: "#{controller.class}##{controller.action_name}",
41
+ method: controller.request.method,
42
+ url: controller.request.url,
43
+ }
39
44
  end
40
45
  raise exception
41
46
  end
@@ -2,7 +2,9 @@ module RorVsWild
2
2
  module Plugin
3
3
  module Resque
4
4
  def self.setup
5
+ return if @installed
5
6
  ::Resque::Job.send(:extend, Resque) if defined?(::Resque::Job)
7
+ @installed = true
6
8
  end
7
9
 
8
10
  def around_perform_rorvswild(*args, &block)
@@ -63,7 +63,7 @@ module RorVsWild
63
63
  end
64
64
 
65
65
  def start_thread
66
- RorVsWild.logger.info("RorVsWild::Queue#start_thread".freeze)
66
+ RorVsWild.logger.debug("RorVsWild::Queue#start_thread".freeze)
67
67
  @thread = Thread.new { flush_indefinetely }
68
68
  end
69
69
 
@@ -10,20 +10,19 @@ module RorVsWild
10
10
  def self.start
11
11
  return if RorVsWild.agent
12
12
 
13
- if (path = Rails.root.join("config/rorvswild.yml")).exist?
14
- if config = RorVsWild::RailsLoader.load_config_file(path)[Rails.env]
15
- RorVsWild.start(config.symbolize_keys)
16
- end
17
- end
18
-
19
- if !RorVsWild.agent && Rails.env.development?
13
+ if (config = load_config) && config[:api_key]
14
+ RorVsWild.start(config)
15
+ elsif Rails.env.development?
20
16
  require "rorvswild/local"
21
- RorVsWild::Local.start
17
+ RorVsWild::Local.start(config || {})
22
18
  end
23
19
  end
24
20
 
25
- def self.load_config_file(path)
26
- YAML.load(ERB.new(path.read).result)
21
+ def self.load_config
22
+ if (path = Rails.root.join("config/rorvswild.yml")).exist?
23
+ hash = YAML.load(ERB.new(path.read).result)[Rails.env]
24
+ hash && hash.deep_symbolize_keys
25
+ end
27
26
  end
28
27
  end
29
28
  end
@@ -66,5 +66,13 @@ module RorVsWild
66
66
  def command=(value)
67
67
  @command = value && value.size > COMMAND_MAX_SIZE ? value[0, COMMAND_MAX_SIZE] + " [TRUNCATED]" : value
68
68
  end
69
+
70
+ def to_h
71
+ {calls: calls, total_runtime: total_runtime, children_runtime: children_runtime, kind: kind, started_at: started_at, file: file, line: line, command: command}
72
+ end
73
+
74
+ def to_json(options = {})
75
+ to_h.to_json(options)
76
+ end
69
77
  end
70
78
  end
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.5.7".freeze
2
+ VERSION = "1.5.12".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-25 00:00:00.000000000 Z
12
+ date: 2021-05-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Performances and errors insights for rails developers.
15
15
  email:
@@ -34,7 +34,7 @@ files:
34
34
  - lib/rorvswild/local/javascript/vendor/barber.js
35
35
  - lib/rorvswild/local/javascript/vendor/mustache.js
36
36
  - lib/rorvswild/local/javascript/vendor/prism.js
37
- - lib/rorvswild/local/local.html
37
+ - lib/rorvswild/local/local.html.erb
38
38
  - lib/rorvswild/local/middleware.rb
39
39
  - lib/rorvswild/local/queue.rb
40
40
  - lib/rorvswild/local/stylesheet/local.css