rails_performance 1.0.4 → 1.0.5

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: da39e641dcac93526efb39f08e39cff972b5c09c04956b48bf1a30a6988fc24f
4
- data.tar.gz: b7b0615aab822ec3742cc43ee74f45b63f1141cb79c246e4bc58c1d1b30b01f0
3
+ metadata.gz: 437c85fdb48db55caa5da3b41a7b0344d05e27094637cca6f3e8f28f8a15d284
4
+ data.tar.gz: c4bf8df35605e2cef8de589be79cde872d1a5d5210883140855eb0cf877562d7
5
5
  SHA512:
6
- metadata.gz: 9ed2ae6cbd21422811df03088d04c036129ccf1bd527cf18964d6c1ff7c3781f7d5ab251041900a264ee89d7f0598b154f8426921f4cd3a5628a18b477580e6c
7
- data.tar.gz: 55c864e62678514bf2b9c03cd648dfb8faa454d42061e8f454572c2d0083f367105540e0533c5b9efcd587e08dadabedc583fce842269aaa6b3659f26eb72d56
6
+ metadata.gz: e54cd14676bde4b86de76a1cc73b482f51dfa9cd7529a658b70bec638e7f0d7eae1af22d60d00e959fbfbd4f3912cce2f6a5c545e8358c949bd0ba0c844e633e
7
+ data.tar.gz: 7c459ccf377434021fc0d2a4348e95e49ea9ef4e741cc7d768e8f9185121bf7fe36c0cd0b6475aa03fd208cb518f764467880542eb38d994baa8484810e5074f
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Tests](https://github.com/igorkasyanchuk/rails_performance/actions/workflows/ruby.yml/badge.svg)](https://github.com/igorkasyanchuk/rails_performance/actions/workflows/ruby.yml)
4
4
  [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
5
5
  [![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)
6
+ [![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/igorkasyanchuk/rails_performance)
6
7
 
7
8
  A self-hosted tool to monitor the performance of your Ruby on Rails application.
8
9
 
@@ -70,6 +71,15 @@ RailsPerformance.setup do |config|
70
71
  # for example when you have `current_user`
71
72
  # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }
72
73
 
74
+ # store custom data for the request
75
+ # config.custom_data_proc = proc do |env|
76
+ # request = Rack::Request.new(env)
77
+ # {
78
+ # email: request.env['warden'].user&.email, # if you are using Devise for example
79
+ # user_agent: request.env['HTTP_USER_AGENT']
80
+ # }
81
+ # end
82
+
73
83
  # config home button link
74
84
  config.home_link = '/'
75
85
 
@@ -20,4 +20,4 @@
20
20
  </tr>
21
21
  <% end %>
22
22
  </tbody>
23
- </table>
23
+ </table>
@@ -35,7 +35,7 @@
35
35
  <div class="navbar-item">
36
36
  <div class="buttons">
37
37
  <%#= link_to 'Export to CSV', '#', target: '_blank', class: "button is-primary" %>
38
- <%= link_to RailsPerformance.home_link, target: '_blank', class: "button is-light home_icon" do %>
38
+ <%= link_to RailsPerformance.home_link, class: "button is-light home_icon" do %>
39
39
  <%= icon('home') %>
40
40
  <% end %>
41
41
  </div>
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  RailsPerformance::Engine.routes.draw do
2
+ devise_for :users
3
+
2
4
  get '/' => 'rails_performance#index', as: :rails_performance
3
5
 
4
6
  get '/requests' => 'rails_performance#requests', as: :rails_performance_requests
@@ -22,4 +24,4 @@ Rails.application.routes.draw do
22
24
  # already added
23
25
  # this code exist here because engine not includes routing automatically
24
26
  end
25
- end
27
+ end
@@ -21,6 +21,15 @@ RailsPerformance.setup do |config|
21
21
  # You can ignore endpoints with Rails standard notation controller#action
22
22
  # config.ignored_endpoints = ['HomeController#contact']
23
23
 
24
+ # store custom data for the request
25
+ # config.custom_data_proc = proc do |env|
26
+ # request = Rack::Request.new(env)
27
+ # {
28
+ # email: request.env['warden'].user&.email, # if you are using Devise for example
29
+ # user_agent: request.env['HTTP_USER_AGENT']
30
+ # }
31
+ # end
32
+
24
33
  # config home button link
25
34
  config.home_link = '/'
26
35
  end if defined?(RailsPerformance)
@@ -2,7 +2,7 @@ module RailsPerformance
2
2
  module Models
3
3
  class RequestRecord < BaseRecord
4
4
  attr_accessor :controller, :action, :format, :status, :datetime, :datetimei, :method, :path, :request_id, :json
5
- attr_accessor :view_runtime, :db_runtime, :duration, :http_referer
5
+ attr_accessor :view_runtime, :db_runtime, :duration, :http_referer, :custom_data
6
6
  attr_accessor :exception, :exception_object
7
7
 
8
8
  def RequestRecord.find_by(request_id:)
@@ -25,7 +25,7 @@ module RailsPerformance
25
25
  # path|/|
26
26
  # request_id|454545454545454545|
27
27
  # END|1.0.0
28
- # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
28
+ # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"custom_data":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
29
29
  # value = JSON
30
30
  def RequestRecord.from_db(key, value)
31
31
  items = key.split("|")
@@ -44,26 +44,27 @@ module RailsPerformance
44
44
  )
45
45
  end
46
46
 
47
- def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, exception: nil, exception_object: nil, json: '{}')
48
- @controller = controller
49
- @action = action
50
- @format = format
51
- @status = status
52
- @datetime = datetime
53
- @datetimei = datetimei.to_i
54
- @method = method
55
- @path = path
56
- @request_id = request_id
47
+ def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, custom_data: nil, exception: nil, exception_object: nil, json: '{}')
48
+ @controller = controller
49
+ @action = action
50
+ @format = format
51
+ @status = status
52
+ @datetime = datetime
53
+ @datetimei = datetimei.to_i
54
+ @method = method
55
+ @path = path
56
+ @request_id = request_id
57
57
 
58
58
  @view_runtime = view_runtime
59
59
  @db_runtime = db_runtime
60
60
  @duration = duration
61
61
  @http_referer = http_referer
62
+ @custom_data = custom_data
62
63
 
63
64
  @exception = Array.wrap(exception).compact.join(" ")
64
65
  @exception_object = exception_object
65
66
 
66
- @json = json
67
+ @json = json
67
68
  end
68
69
 
69
70
  def controller_action
@@ -74,6 +75,7 @@ module RailsPerformance
74
75
  "#{controller}##{action}|#{format}"
75
76
  end
76
77
 
78
+ # show on UI in the right panel
77
79
  def record_hash
78
80
  {
79
81
  controller: self.controller,
@@ -89,8 +91,14 @@ module RailsPerformance
89
91
  db_runtime: self.value['db_runtime'],
90
92
  view_runtime: self.value['view_runtime'],
91
93
  exception: self.value['exception'],
92
- backtrace: self.value['backtrace']
93
- }
94
+ backtrace: self.value['backtrace'],
95
+ http_referer: self.value['http_referer']
96
+ }.tap do |h|
97
+ custom_data = JSON.parse(self.value['custom_data']) rescue nil
98
+ if custom_data.is_a?(Hash)
99
+ h.merge!(custom_data)
100
+ end
101
+ end
94
102
  end
95
103
 
96
104
  def save
@@ -100,6 +108,7 @@ module RailsPerformance
100
108
  db_runtime: db_runtime,
101
109
  duration: duration,
102
110
  http_referer: http_referer,
111
+ custom_data: custom_data.to_json
103
112
  }
104
113
  value[:exception] = exception if exception.present?
105
114
  value[:backtrace] = exception_object.backtrace.take(3) if exception_object
@@ -108,4 +117,4 @@ module RailsPerformance
108
117
 
109
118
  end
110
119
  end
111
- end
120
+ end
@@ -53,6 +53,13 @@ module RailsPerformance
53
53
  # capture referer from where this page was opened
54
54
  record.http_referer = env["HTTP_REFERER"] if record.status == 404
55
55
 
56
+ # we can add custom data, for example Http User-Agent
57
+ # or even devise current_user
58
+ if RailsPerformance.custom_data_proc
59
+ # just to be sure it won't break format how we store in redis
60
+ record.custom_data = RailsPerformance.custom_data_proc.call(env)
61
+ end
62
+
56
63
  # store for section "recent requests"
57
64
  # store request information (regular rails request)
58
65
  record.save
@@ -66,4 +73,4 @@ module RailsPerformance
66
73
 
67
74
  end
68
75
  end
69
- end
76
+ end
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  SCHEMA = '1.0.1'
4
4
  end
@@ -77,12 +77,16 @@ module RailsPerformance
77
77
  mattr_accessor :skipable_rake_tasks
78
78
  @@skipable_rake_tasks = []
79
79
 
80
+ # add custom payload to the request
81
+ mattr_accessor :custom_data_proc
82
+ @@custom_data_proc = []
83
+
80
84
  def RailsPerformance.setup
81
85
  yield(self)
82
86
  end
83
87
 
84
88
  def RailsPerformance.log(message)
85
- return
89
+ return unless RailsPerformance.debug
86
90
 
87
91
  if ::Rails.logger
88
92
  # puts(message)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-23 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sprockets-rails
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: 3rd party dependency-free solution how to monitor performance of your
196
210
  Rails applications.
197
211
  email:
@@ -301,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
315
  - !ruby/object:Gem::Version
302
316
  version: '0'
303
317
  requirements: []
304
- rubygems_version: 3.2.3
318
+ rubygems_version: 3.3.7
305
319
  signing_key:
306
320
  specification_version: 4
307
321
  summary: Simple Rails Performance tracker. Alternative to the NewRelic, Datadog or