nunes 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +15 -7
  3. data/Changelog.md +8 -0
  4. data/Gemfile +1 -1
  5. data/README.md +2 -3
  6. data/Rakefile +10 -0
  7. data/lib/nunes.rb +12 -0
  8. data/lib/nunes/adapter.rb +4 -2
  9. data/lib/nunes/instrumentable.rb +1 -1
  10. data/lib/nunes/subscriber.rb +5 -2
  11. data/lib/nunes/subscribers/action_controller.rb +51 -24
  12. data/lib/nunes/subscribers/action_mailer.rb +2 -2
  13. data/lib/nunes/subscribers/action_view.rb +5 -2
  14. data/lib/nunes/subscribers/active_job.rb +2 -3
  15. data/lib/nunes/subscribers/active_record.rb +4 -1
  16. data/lib/nunes/version.rb +1 -1
  17. data/script/test +10 -13
  18. data/test/controller_instrumentation_test.rb +47 -5
  19. data/test/helper.rb +5 -1
  20. data/test/instrumentable_test.rb +27 -3
  21. data/test/job_instrumentation_test.rb +11 -8
  22. data/test/mailer_instrumentation_test.rb +5 -1
  23. data/test/namespaced_controller_instrumentation_test.rb +7 -7
  24. data/test/namespaced_job_instrumentation_test.rb +33 -0
  25. data/test/namespaced_mailer_instrumentation_test.rb +35 -0
  26. data/test/namespaced_model_instrumentation_test.rb +55 -0
  27. data/test/nunes_test.rb +8 -0
  28. data/test/{rails_app → rails_app_4.2.5}/.gitignore +0 -0
  29. data/test/{rails_app → rails_app_4.2.5}/Rakefile +0 -0
  30. data/test/{rails_app → rails_app_4.2.5}/app/assets/images/rails.png +0 -0
  31. data/test/{rails_app → rails_app_4.2.5}/app/assets/javascripts/application.js +0 -0
  32. data/test/{rails_app → rails_app_4.2.5}/app/assets/stylesheets/application.css +0 -0
  33. data/test/{rails_app → rails_app_4.2.5}/app/controllers/admin/posts_controller.rb +2 -7
  34. data/test/{rails_app → rails_app_4.2.5}/app/controllers/application_controller.rb +0 -0
  35. data/test/{rails_app → rails_app_4.2.5}/app/controllers/posts_controller.rb +1 -7
  36. data/test/{rails_app → rails_app_4.2.5}/app/helpers/application_helper.rb +0 -0
  37. data/test/rails_app_4.2.5/app/jobs/spam/detector_job.rb +11 -0
  38. data/test/{rails_app → rails_app_4.2.5}/app/jobs/spam_detector_job.rb +0 -0
  39. data/test/{rails_app → rails_app_4.2.5}/app/mailers/.gitkeep +0 -0
  40. data/test/rails_app_4.2.5/app/mailers/admin/post_mailer.rb +13 -0
  41. data/test/{rails_app → rails_app_4.2.5}/app/mailers/post_mailer.rb +0 -0
  42. data/test/{rails_app → rails_app_4.2.5}/app/models/.gitkeep +0 -0
  43. data/test/rails_app_4.2.5/app/models/admin/post.rb +5 -0
  44. data/test/{rails_app → rails_app_4.2.5}/app/models/post.rb +0 -0
  45. data/test/{rails_app/app/views → rails_app_4.2.5/app/views/admin}/post_mailer/created.text.erb +0 -0
  46. data/test/{rails_app → rails_app_4.2.5}/app/views/admin/posts/index.html.erb +0 -0
  47. data/test/{rails_app → rails_app_4.2.5}/app/views/layouts/application.html.erb +0 -0
  48. data/test/rails_app_4.2.5/app/views/post_mailer/created.text.erb +1 -0
  49. data/test/{rails_app → rails_app_4.2.5}/app/views/posts/_post.html.erb +0 -0
  50. data/test/{rails_app → rails_app_4.2.5}/app/views/posts/index.html.erb +0 -0
  51. data/test/{rails_app → rails_app_4.2.5}/config.ru +0 -0
  52. data/test/{rails_app → rails_app_4.2.5}/config/application.rb +0 -0
  53. data/test/{rails_app → rails_app_4.2.5}/config/boot.rb +0 -0
  54. data/test/{rails_app → rails_app_4.2.5}/config/database.yml +0 -0
  55. data/test/{rails_app → rails_app_4.2.5}/config/environment.rb +0 -0
  56. data/test/{rails_app → rails_app_4.2.5}/config/environments/development.rb +0 -0
  57. data/test/{rails_app → rails_app_4.2.5}/config/environments/production.rb +0 -0
  58. data/test/{rails_app → rails_app_4.2.5}/config/environments/test.rb +0 -0
  59. data/test/{rails_app → rails_app_4.2.5}/config/initializers/backtrace_silencers.rb +0 -0
  60. data/test/{rails_app → rails_app_4.2.5}/config/initializers/force_test_schema_load.rb +0 -0
  61. data/test/{rails_app → rails_app_4.2.5}/config/initializers/inflections.rb +0 -0
  62. data/test/{rails_app → rails_app_4.2.5}/config/initializers/mime_types.rb +0 -0
  63. data/test/{rails_app → rails_app_4.2.5}/config/initializers/secret_token.rb +0 -0
  64. data/test/{rails_app → rails_app_4.2.5}/config/initializers/session_store.rb +0 -0
  65. data/test/{rails_app → rails_app_4.2.5}/config/initializers/wrap_parameters.rb +0 -0
  66. data/test/{rails_app → rails_app_4.2.5}/config/locales/en.yml +0 -0
  67. data/test/{rails_app → rails_app_4.2.5}/config/routes.rb +0 -0
  68. data/test/{rails_app → rails_app_4.2.5}/config/secrets.yml +0 -0
  69. data/test/{rails_app → rails_app_4.2.5}/db/migrate/20130417154459_create_posts.rb +0 -0
  70. data/test/{rails_app → rails_app_4.2.5}/db/schema.rb +0 -0
  71. data/test/{rails_app → rails_app_4.2.5}/db/seeds.rb +0 -0
  72. data/test/{rails_app → rails_app_4.2.5}/lib/assets/.gitkeep +0 -0
  73. data/test/{rails_app → rails_app_4.2.5}/lib/tasks/.gitkeep +0 -0
  74. data/test/{rails_app → rails_app_4.2.5}/public/404.html +0 -0
  75. data/test/{rails_app → rails_app_4.2.5}/public/422.html +0 -0
  76. data/test/{rails_app → rails_app_4.2.5}/public/500.html +0 -0
  77. data/test/{rails_app → rails_app_4.2.5}/public/favicon.ico +0 -0
  78. data/test/{rails_app → rails_app_4.2.5}/public/index.html +0 -0
  79. data/test/{rails_app → rails_app_4.2.5}/public/robots.txt +0 -0
  80. data/test/{rails_app → rails_app_4.2.5}/script/rails +0 -0
  81. data/test/rails_app_5.0.0/.gitignore +21 -0
  82. data/test/rails_app_5.0.0/Gemfile +48 -0
  83. data/test/rails_app_5.0.0/README.md +24 -0
  84. data/test/rails_app_5.0.0/Rakefile +6 -0
  85. data/test/rails_app_5.0.0/app/assets/config/manifest.js +3 -0
  86. data/test/rails_app_5.0.0/app/assets/images/.keep +0 -0
  87. data/test/rails_app_5.0.0/app/assets/images/rails.png +0 -0
  88. data/test/rails_app_5.0.0/app/assets/javascripts/application.js +13 -0
  89. data/test/rails_app_5.0.0/app/assets/javascripts/cable.js +13 -0
  90. data/test/rails_app_5.0.0/app/assets/javascripts/channels/.keep +0 -0
  91. data/test/rails_app_5.0.0/app/assets/stylesheets/application.css +15 -0
  92. data/test/rails_app_5.0.0/app/channels/application_cable/channel.rb +4 -0
  93. data/test/rails_app_5.0.0/app/channels/application_cable/connection.rb +4 -0
  94. data/test/rails_app_5.0.0/app/controllers/admin/posts_controller.rb +14 -0
  95. data/test/rails_app_5.0.0/app/controllers/application_controller.rb +3 -0
  96. data/test/rails_app_5.0.0/app/controllers/concerns/.keep +0 -0
  97. data/test/rails_app_5.0.0/app/controllers/posts_controller.rb +22 -0
  98. data/test/rails_app_5.0.0/app/helpers/application_helper.rb +2 -0
  99. data/test/rails_app_5.0.0/app/jobs/application_job.rb +2 -0
  100. data/test/rails_app_5.0.0/app/jobs/spam/detector_job.rb +11 -0
  101. data/test/rails_app_5.0.0/app/jobs/spam_detector_job.rb +9 -0
  102. data/test/rails_app_5.0.0/app/mailers/admin/post_mailer.rb +13 -0
  103. data/test/rails_app_5.0.0/app/mailers/application_mailer.rb +4 -0
  104. data/test/rails_app_5.0.0/app/mailers/post_mailer.rb +11 -0
  105. data/test/rails_app_5.0.0/app/models/admin/post.rb +5 -0
  106. data/test/rails_app_5.0.0/app/models/application_record.rb +3 -0
  107. data/test/rails_app_5.0.0/app/models/concerns/.keep +0 -0
  108. data/test/rails_app_5.0.0/app/models/post.rb +2 -0
  109. data/test/rails_app_5.0.0/app/views/admin/post_mailer/created.text.erb +1 -0
  110. data/test/rails_app_5.0.0/app/views/admin/posts/index.html.erb +5 -0
  111. data/test/rails_app_5.0.0/app/views/layouts/application.html.erb +14 -0
  112. data/test/rails_app_5.0.0/app/views/layouts/mailer.html.erb +13 -0
  113. data/test/rails_app_5.0.0/app/views/layouts/mailer.text.erb +1 -0
  114. data/test/rails_app_5.0.0/app/views/post_mailer/created.text.erb +1 -0
  115. data/test/rails_app_5.0.0/app/views/posts/_post.html.erb +1 -0
  116. data/test/rails_app_5.0.0/app/views/posts/index.html.erb +5 -0
  117. data/test/rails_app_5.0.0/bin/bundle +3 -0
  118. data/test/rails_app_5.0.0/bin/rails +9 -0
  119. data/test/rails_app_5.0.0/bin/rake +9 -0
  120. data/test/rails_app_5.0.0/bin/setup +34 -0
  121. data/test/rails_app_5.0.0/bin/spring +15 -0
  122. data/test/rails_app_5.0.0/bin/update +29 -0
  123. data/test/rails_app_5.0.0/config.ru +5 -0
  124. data/test/rails_app_5.0.0/config/application.rb +15 -0
  125. data/test/rails_app_5.0.0/config/boot.rb +3 -0
  126. data/test/rails_app_5.0.0/config/cable.yml +9 -0
  127. data/test/rails_app_5.0.0/config/database.yml +25 -0
  128. data/test/rails_app_5.0.0/config/environment.rb +5 -0
  129. data/test/rails_app_5.0.0/config/environments/development.rb +54 -0
  130. data/test/rails_app_5.0.0/config/environments/production.rb +86 -0
  131. data/test/rails_app_5.0.0/config/environments/test.rb +42 -0
  132. data/test/rails_app_5.0.0/config/initializers/application_controller_renderer.rb +6 -0
  133. data/test/rails_app_5.0.0/config/initializers/assets.rb +11 -0
  134. data/test/rails_app_5.0.0/config/initializers/backtrace_silencers.rb +7 -0
  135. data/test/rails_app_5.0.0/config/initializers/cookies_serializer.rb +5 -0
  136. data/test/rails_app_5.0.0/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/test/rails_app_5.0.0/config/initializers/force_test_schema_load.rb +3 -0
  138. data/test/rails_app_5.0.0/config/initializers/inflections.rb +16 -0
  139. data/test/rails_app_5.0.0/config/initializers/mime_types.rb +4 -0
  140. data/test/rails_app_5.0.0/config/initializers/new_framework_defaults.rb +24 -0
  141. data/test/rails_app_5.0.0/config/initializers/session_store.rb +3 -0
  142. data/test/rails_app_5.0.0/config/initializers/wrap_parameters.rb +14 -0
  143. data/test/rails_app_5.0.0/config/locales/en.yml +23 -0
  144. data/test/rails_app_5.0.0/config/puma.rb +47 -0
  145. data/test/rails_app_5.0.0/config/routes.rb +12 -0
  146. data/test/rails_app_5.0.0/config/secrets.yml +22 -0
  147. data/test/rails_app_5.0.0/config/spring.rb +6 -0
  148. data/test/rails_app_5.0.0/db/migrate/20160812134213_create_posts.rb +9 -0
  149. data/test/rails_app_5.0.0/db/schema.rb +21 -0
  150. data/test/rails_app_5.0.0/db/seeds.rb +7 -0
  151. data/test/rails_app_5.0.0/lib/assets/.keep +0 -0
  152. data/test/rails_app_5.0.0/lib/tasks/.keep +0 -0
  153. data/test/rails_app_5.0.0/log/.keep +0 -0
  154. data/test/rails_app_5.0.0/public/404.html +67 -0
  155. data/test/rails_app_5.0.0/public/422.html +67 -0
  156. data/test/rails_app_5.0.0/public/500.html +66 -0
  157. data/test/rails_app_5.0.0/public/apple-touch-icon-precomposed.png +0 -0
  158. data/test/rails_app_5.0.0/public/apple-touch-icon.png +0 -0
  159. data/test/rails_app_5.0.0/public/favicon.ico +0 -0
  160. data/test/rails_app_5.0.0/public/robots.txt +5 -0
  161. data/test/rails_app_5.0.0/test/controllers/.keep +0 -0
  162. data/test/rails_app_5.0.0/test/fixtures/.keep +0 -0
  163. data/test/rails_app_5.0.0/test/fixtures/files/.keep +0 -0
  164. data/test/rails_app_5.0.0/test/helpers/.keep +0 -0
  165. data/test/rails_app_5.0.0/test/integration/.keep +0 -0
  166. data/test/rails_app_5.0.0/test/mailers/.keep +0 -0
  167. data/test/rails_app_5.0.0/test/models/.keep +0 -0
  168. data/test/rails_app_5.0.0/test/test_helper.rb +10 -0
  169. data/test/rails_app_5.0.0/vendor/assets/javascripts/.keep +0 -0
  170. data/test/rails_app_5.0.0/vendor/assets/stylesheets/.keep +0 -0
  171. data/test/support/adapter_test_helpers.rb +17 -2
  172. metadata +295 -100
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bddc1e5791272becd4a0272db00372b590bb27a6
4
- data.tar.gz: 795aac98c9ba8a5194ad8128a0df8401637a0f6f
3
+ metadata.gz: 519721bdfa50f41504919cb7a153d5be9bf0ccd2
4
+ data.tar.gz: 6b912ad6b4fbafdc54fe19e5bc0de7c986f3ab77
5
5
  SHA512:
6
- metadata.gz: 778bf582c222528abf705cf0710bf36809b13c9fadf52ca2d9c93c9968b7b25df8f88a32df4785279431e4bdb8c5901ef4da88ef8c42e345cb5e2c60596999b7
7
- data.tar.gz: 2938ce75643befd9904221fe48be7a6dc77d88906c7e980d32eb2b2b6466fd385cfca7b41092a20b4f82b68f2e136280dbe0c69f628c7bc4b0ddabd4043a34d4
6
+ metadata.gz: 76cc5998cd987b32faa08bfc2607c56c3e913294ebd26a57a853ce2a31699e3b98901920b95f96b130cf6d148c3b8f879bb0f5b375cb00a659e503113d7cf59a
7
+ data.tar.gz: 48c54dd8a5bdf5a8c1d26e3f9cdb6533bd07e6fb5b0cda62bef195c8d96c5f2a8284aa77ef730e03f1234db78db6932f803837db4d46b41d4e9012640285f8c6
@@ -1,9 +1,17 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.1.0
5
- - 2.2.0
6
- notifications:
7
- email: false
8
- bundler_args: --without guard
9
- script: script/test
3
+ - 2.0.0
4
+ - 2.1.10
5
+ - 2.2.5
6
+ bundler_args: --without guard watch bench
7
+ script: bundle exec rake
8
+ env:
9
+ - RAILS_VERSION=4.2.5
10
+ - RAILS_VERSION=5.0.0
11
+ matrix:
12
+ # don't run rails 5 on ruby versions that can't install rack 2
13
+ exclude:
14
+ - rvm: 2.0.0
15
+ env: RAILS_VERSION=5.0.0
16
+ - rvm: 2.1.10
17
+ env: RAILS_VERSION=5.0.0
@@ -1,3 +1,11 @@
1
+ # 0.5.0
2
+
3
+ * no longer doing underscore on active job class name when instrumenting it (ie: active_job.spam_detector_job.perform changed to active_job.SpamDetectorJob.perform)
4
+ * drop ruby 1.9 support
5
+ * ruby namespaces are now converted to dash instead of dot in metric namespace (https://github.com/jnunemaker/nunes/pull/27)
6
+ * allow disabling view/db runtime, format and exception instrumentation
7
+ * official support for rails 5
8
+
1
9
  # 0.4.0
2
10
 
3
11
  ## Backwards Compatibility Break
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- gem "rails", "~> 4.2.0"
4
+ gem "rails", "~> #{ENV["RAILS_VERSION"] || '4.2.5'}"
5
5
  gem "sqlite3", "~> 1.3.7"
6
6
  gem "minitest", "~> 5.1"
7
7
  gem "rake", "~> 10.0.4"
data/README.md CHANGED
@@ -18,8 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Compatibility
20
20
 
21
- * >= Ruby 1.9
22
- * Rails 4.2.x
21
+ * >= Ruby 2.0
22
+ * Rails 4.2.x, 5.0.x
23
23
 
24
24
  Note: you can use v0.3.1 is for rails 3.2.x support.
25
25
 
@@ -74,7 +74,6 @@ Based on those events, you'll get metrics like this in instrumental and statsd:
74
74
  * `action_controller.format.html`
75
75
  * `action_controller.controller.Admin.PostsController.new.status.403`
76
76
  * `action_controller.controller.Admin.PostsController.index.format.json`
77
- * `action_controller.exception.RuntimeError` - where RuntimeError is the class of any exceptions that occur while processing a controller's action.
78
77
  * `active_support.cache.hit`
79
78
  * `active_support.cache.miss`
80
79
 
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new do |t|
6
+ t.libs = ["lib", "test"]
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task :default => :test
@@ -37,4 +37,16 @@ module Nunes
37
37
 
38
38
  subscribers
39
39
  end
40
+
41
+ # Private: What ruby uses to separate namespaces.
42
+ NAMESPACE_SEPARATOR = "::".freeze
43
+
44
+ # Private: What nunes uses to separate namespaces in the metric.
45
+ METRIC_NAMESPACE_SEPARATOR = "-".freeze
46
+
47
+ # Private: Converts a class to a metric safe name.
48
+ def self.class_to_metric(class_or_class_name)
49
+ return if class_or_class_name.nil?
50
+ class_or_class_name.to_s.gsub(NAMESPACE_SEPARATOR, METRIC_NAMESPACE_SEPARATOR)
51
+ end
40
52
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/class/subclasses'
2
+
1
3
  module Nunes
2
4
  class Adapter
3
5
  # Private: Wraps a given object with the correct adapter/decorator.
@@ -55,10 +57,10 @@ module Nunes
55
57
  ReplaceRegex = /[^a-z0-9\-_]+/i
56
58
 
57
59
  # Private: The default metric namespace separator.
58
- Separator = "."
60
+ Separator = ".".freeze
59
61
 
60
62
  # Private
61
- Nothing = ""
63
+ Nothing = "".freeze
62
64
 
63
65
  # Private: Prepare a metric name before it is sent to the adapter's client.
64
66
  def prepare(metric, replacement = Separator)
@@ -24,7 +24,7 @@ module Nunes
24
24
  if name.nil?
25
25
  raise ArgumentError, "For class methods you must provide the full name of the metric."
26
26
  else
27
- "#{name}.#{method_name}"
27
+ "#{::Nunes.class_to_metric(name)}.#{method_name}"
28
28
  end
29
29
  }
30
30
 
@@ -3,7 +3,10 @@ require "active_support/notifications"
3
3
  module Nunes
4
4
  class Subscriber
5
5
  # Private: The bang character that is the first char of some events.
6
- BANG = '!'
6
+ BANG = "!".freeze
7
+
8
+ # Private: The dot charactor used to determine the method name.
9
+ DOT = ".".freeze
7
10
 
8
11
  # Public: Setup a subscription for the subscriber using the
9
12
  # provided adapter.
@@ -34,7 +37,7 @@ module Nunes
34
37
  # when in production
35
38
  return if name.start_with?(BANG)
36
39
 
37
- method_name = name.split('.').first
40
+ method_name = name.split(DOT).first
38
41
 
39
42
  if respond_to?(method_name)
40
43
  send(method_name, start, ending, transaction_id, payload)
@@ -11,46 +11,73 @@ module Nunes
11
11
  Pattern
12
12
  end
13
13
 
14
- def process_action(start, ending, transaction_id, payload)
15
- controller = payload[:controller]
16
- action = payload[:action]
17
- status = payload[:status]
18
- exception_info = payload[:exception]
14
+ class << self
15
+ attr_accessor :instrument_format
16
+ attr_accessor :instrument_view_runtime
17
+ attr_accessor :instrument_db_runtime
18
+ end
19
19
 
20
- format = payload[:format] || "all"
21
- format = "all" if format == "*/*"
20
+ # Public: Should we instrument the number of requests per format overall and per controller/action.
21
+ self.instrument_format = true
22
22
 
23
- db_runtime = payload[:db_runtime]
24
- db_runtime = db_runtime.round if db_runtime
23
+ # Public: Should we instrument the view runtime overall and per controller/action.
24
+ self.instrument_view_runtime = true
25
25
 
26
- view_runtime = payload[:view_runtime]
27
- view_runtime = view_runtime.round if view_runtime
26
+ # Public: Should we instrument the db runtime overall and per controller/action.
27
+ self.instrument_db_runtime = true
28
28
 
29
+ def process_action(start, ending, transaction_id, payload)
29
30
  runtime = ((ending - start) * 1_000).round
30
-
31
31
  timing "action_controller.runtime.total", runtime
32
- timing "action_controller.runtime.view", view_runtime if view_runtime
33
- timing "action_controller.runtime.db", db_runtime if db_runtime
34
32
 
35
- increment "action_controller.format.#{format}" if format
33
+ status = payload[:status]
36
34
  increment "action_controller.status.#{status}" if status
37
35
 
36
+ controller = ::Nunes.class_to_metric(payload[:controller])
37
+ action = payload[:action]
38
+
38
39
  if controller && action
39
- namespace = "action_controller.controller.#{controller}.#{action}"
40
+ timing "action_controller.controller.#{controller}.#{action}.runtime.total", runtime
41
+ increment "action_controller.controller.#{controller}.#{action}.status.#{status}" if status
42
+ end
40
43
 
41
- timing "#{namespace}.runtime.total", runtime
42
- timing "#{namespace}.runtime.view", view_runtime if view_runtime
43
- timing "#{namespace}.runtime.db", db_runtime if db_runtime
44
+ if self.class.instrument_view_runtime
45
+ view_runtime = payload[:view_runtime]
46
+ view_runtime = view_runtime.round if view_runtime
44
47
 
45
- increment "#{namespace}.format.#{format}" if format
46
- increment "#{namespace}.status.#{status}" if status
48
+ if view_runtime
49
+ timing "action_controller.runtime.view", view_runtime
47
50
 
51
+ if controller && action
52
+ timing "action_controller.controller.#{controller}.#{action}.runtime.view", view_runtime
53
+ end
54
+ end
48
55
  end
49
56
 
50
- if exception_info
51
- exception_class, exception_message = exception_info
57
+ if self.class.instrument_db_runtime
58
+ db_runtime = payload[:db_runtime]
59
+ db_runtime = db_runtime.round if db_runtime
60
+
61
+ if db_runtime
62
+ timing "action_controller.runtime.db", db_runtime
63
+
64
+ if controller && action
65
+ timing "action_controller.controller.#{controller}.#{action}.runtime.db", db_runtime
66
+ end
67
+ end
68
+ end
69
+
70
+ if self.class.instrument_format
71
+ format = payload[:format] || "all"
72
+ format = "all" if format == "*/*"
73
+
74
+ if format
75
+ increment "action_controller.format.#{format}"
52
76
 
53
- increment "action_controller.exception.#{exception_class}"
77
+ if controller && action
78
+ increment "action_controller.controller.#{controller}.#{action}.format.#{format}"
79
+ end
80
+ end
54
81
  end
55
82
  end
56
83
 
@@ -13,7 +13,7 @@ module Nunes
13
13
 
14
14
  def deliver(start, ending, transaction_id, payload)
15
15
  runtime = ((ending - start) * 1_000).round
16
- mailer = payload[:mailer]
16
+ mailer = ::Nunes.class_to_metric(payload[:mailer])
17
17
 
18
18
  if mailer
19
19
  timing "action_mailer.deliver.#{mailer}", runtime
@@ -22,7 +22,7 @@ module Nunes
22
22
 
23
23
  def receive(start, ending, transaction_id, payload)
24
24
  runtime = ((ending - start) * 1_000).round
25
- mailer = payload[:mailer]
25
+ mailer = ::Nunes.class_to_metric(payload[:mailer])
26
26
 
27
27
  if mailer
28
28
  timing "action_mailer.receive.#{mailer}", runtime
@@ -30,14 +30,17 @@ module Nunes
30
30
  end
31
31
 
32
32
  # Private: What to replace file separators with.
33
- FileSeparatorReplacement = "_"
33
+ FileSeparatorReplacement = "_".freeze
34
+
35
+ # Private: An empty string.
36
+ Nothing = "".freeze
34
37
 
35
38
  # Private: Converts an identifier to a metric name. Strips out the rails
36
39
  # root from the full path.
37
40
  #
38
41
  # identifier - The String full path to the template or partial.
39
42
  def identifier_to_metric(kind, identifier)
40
- view_path = identifier.to_s.gsub(::Rails.root.to_s, "")
43
+ view_path = identifier.to_s.gsub(::Rails.root.to_s, Nothing)
41
44
  metric = adapter.prepare(view_path, FileSeparatorReplacement)
42
45
  "action_view.#{kind}.#{metric}"
43
46
  end
@@ -13,16 +13,15 @@ module Nunes
13
13
 
14
14
  def perform(start, ending, transaction_id, payload)
15
15
  runtime = ((ending - start) * 1_000).round
16
- job = payload[:job].class.to_s.underscore
16
+ job = ::Nunes.class_to_metric(payload[:job].class)
17
17
 
18
18
  timing "active_job.#{job}.perform", runtime
19
19
  end
20
20
 
21
21
  def enqueue(start, ending, transaction_id, payload)
22
- job = payload[:job].class.to_s.underscore
22
+ job = ::Nunes.class_to_metric(payload[:job].class)
23
23
  increment "active_job.#{job}.enqueue"
24
24
  end
25
25
  end
26
26
  end
27
27
  end
28
-
@@ -11,11 +11,14 @@ module Nunes
11
11
  Pattern
12
12
  end
13
13
 
14
+ # Private: Used to detect the operation from the sql.
15
+ Space = " ".freeze
16
+
14
17
  def sql(start, ending, transaction_id, payload)
15
18
  runtime = ((ending - start) * 1_000).round
16
19
  name = payload[:name]
17
20
  sql = payload[:sql].to_s.strip
18
- operation = sql.split(' ', 2).first.to_s.downcase
21
+ operation = sql.split(Space, 2).first.to_s.downcase
19
22
 
20
23
  timing "active_record.sql", runtime
21
24
 
@@ -1,3 +1,3 @@
1
1
  module Nunes
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,15 +1,7 @@
1
1
  #!/bin/sh
2
- #/ Usage: test [individual test file]
2
+ #/ Usage: test
3
3
  #/
4
- #/ Bootstrap and run all tests or an individual test.
5
- #/
6
- #/ Examples:
7
- #/
8
- #/ # run all tests
9
- #/ test
10
- #/
11
- #/ # run individual test
12
- #/ test test/controller_instrumentation_test.rb
4
+ #/ Bootstrap and run all tests.
13
5
  #/
14
6
 
15
7
  set -e
@@ -20,6 +12,11 @@ cd $(dirname "$0")/..
20
12
  exit 0
21
13
  }
22
14
 
23
- script/bootstrap && ruby -I lib -I test -r rubygems \
24
- -e 'require "bundler/setup"' \
25
- -e '(ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV).each { |f| load f }' -- "$@"
15
+ export RAILS_VERSION=5.0.0
16
+ script/bootstrap || bundle update
17
+ bundle exec rake
18
+
19
+
20
+ export RAILS_VERSION=4.2.5
21
+ script/bootstrap || bundle update
22
+ bundle exec rake
@@ -23,10 +23,12 @@ class ControllerInstrumentationTest < ActionController::TestCase
23
23
  assert_counter "action_controller.format.html"
24
24
 
25
25
  assert_timer "action_controller.runtime.total"
26
+ assert_timer "action_controller.runtime.db"
26
27
  assert_timer "action_controller.runtime.view"
27
28
 
28
29
  assert_timer "action_controller.controller.PostsController.index.runtime.total"
29
30
  assert_timer "action_controller.controller.PostsController.index.runtime.view"
31
+ assert_timer "action_controller.controller.PostsController.index.runtime.db"
30
32
  end
31
33
 
32
34
  test "send_data" do
@@ -67,8 +69,8 @@ class ControllerInstrumentationTest < ActionController::TestCase
67
69
  assert_timer "action_controller.runtime.total"
68
70
  assert_timer "action_controller.controller.PostsController.some_redirect.runtime.total"
69
71
 
70
- assert_no_timer "action_controller.runtime.view"
71
- assert_no_timer "action_controller.controller.PostsController.some_redirect.runtime.view"
72
+ refute_timer "action_controller.runtime.view"
73
+ refute_timer "action_controller.controller.PostsController.some_redirect.runtime.view"
72
74
  end
73
75
 
74
76
  test "action with exception" do
@@ -76,13 +78,53 @@ class ControllerInstrumentationTest < ActionController::TestCase
76
78
 
77
79
  assert_response :success
78
80
 
79
- assert_counter "action_controller.exception.RuntimeError"
80
81
  assert_counter "action_controller.format.html"
81
82
 
82
83
  assert_timer "action_controller.runtime.total"
83
84
  assert_timer "action_controller.controller.PostsController.some_boom.runtime.total"
84
85
 
85
- assert_no_timer "action_controller.runtime.view"
86
- assert_no_timer "action_controller.controller.PostsController.some_boom.runtime.view"
86
+ refute_timer "action_controller.runtime.view"
87
+ refute_timer "action_controller.controller.PostsController.some_boom.runtime.view"
88
+ end
89
+
90
+ test "with instrument format disabled" do
91
+ begin
92
+ original_format_enabled = Nunes::Subscribers::ActionController.instrument_format
93
+ Nunes::Subscribers::ActionController.instrument_format = false
94
+
95
+ get :index
96
+
97
+ refute_counter "action_controller.format.html"
98
+ ensure
99
+ Nunes::Subscribers::ActionController.instrument_format = original_format_enabled
100
+ end
101
+ end
102
+
103
+ test "with instrument db runtime disabled" do
104
+ begin
105
+ original_format_enabled = Nunes::Subscribers::ActionController.instrument_db_runtime
106
+ Nunes::Subscribers::ActionController.instrument_db_runtime = false
107
+
108
+ get :index
109
+
110
+ refute_timer "action_controller.runtime.db"
111
+ refute_timer "action_controller.controller.PostsController.index.runtime.db"
112
+ ensure
113
+ Nunes::Subscribers::ActionController.instrument_db_runtime = original_format_enabled
114
+ end
115
+ end
116
+
117
+ test "with instrument view runtime disabled" do
118
+ begin
119
+ original_format_enabled = Nunes::Subscribers::ActionController.instrument_view_runtime
120
+ Nunes::Subscribers::ActionController.instrument_view_runtime = false
121
+
122
+ get :index
123
+
124
+ refute_timer "action_controller.runtime.view"
125
+ refute_timer "action_controller.controller.PostsController.index.runtime.view"
126
+ ensure
127
+ Nunes::Subscribers::ActionController.instrument_view_runtime = original_format_enabled
128
+ end
87
129
  end
88
130
  end