scout_apm 2.6.10 → 3.0.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.rubocop.yml +3 -11
  4. data/CHANGELOG.markdown +4 -362
  5. data/Gemfile +1 -14
  6. data/README.markdown +7 -52
  7. data/Rakefile +1 -0
  8. data/ext/allocations/allocations.c +1 -7
  9. data/ext/allocations/extconf.rb +0 -1
  10. data/ext/rusage/rusage.c +0 -26
  11. data/ext/stacks/extconf.rb +37 -0
  12. data/ext/stacks/scout_atomics.h +86 -0
  13. data/ext/stacks/stacks.c +811 -0
  14. data/lib/scout_apm/agent/logging.rb +69 -0
  15. data/lib/scout_apm/agent/reporting.rb +126 -0
  16. data/lib/scout_apm/agent.rb +259 -138
  17. data/lib/scout_apm/app_server_load.rb +15 -41
  18. data/lib/scout_apm/attribute_arranger.rb +3 -14
  19. data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -70
  20. data/lib/scout_apm/background_job_integrations/sidekiq.rb +24 -31
  21. data/lib/scout_apm/background_worker.rb +12 -23
  22. data/lib/scout_apm/capacity.rb +57 -0
  23. data/lib/scout_apm/config.rb +37 -206
  24. data/lib/scout_apm/context.rb +4 -20
  25. data/lib/scout_apm/deploy_integrations/capistrano_2.cap +12 -0
  26. data/lib/scout_apm/deploy_integrations/capistrano_2.rb +83 -0
  27. data/lib/scout_apm/deploy_integrations/capistrano_3.cap +12 -0
  28. data/lib/scout_apm/deploy_integrations/capistrano_3.rb +88 -0
  29. data/lib/scout_apm/environment.rb +28 -42
  30. data/lib/scout_apm/fake_store.rb +0 -12
  31. data/lib/scout_apm/framework_integrations/rails_2.rb +1 -2
  32. data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +6 -17
  33. data/lib/scout_apm/framework_integrations/sinatra.rb +1 -1
  34. data/lib/scout_apm/histogram.rb +3 -12
  35. data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
  36. data/lib/scout_apm/instant/middleware.rb +54 -202
  37. data/lib/scout_apm/instant_reporting.rb +7 -7
  38. data/lib/scout_apm/instruments/.DS_Store +0 -0
  39. data/lib/scout_apm/instruments/action_controller_rails_2.rb +9 -15
  40. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +76 -124
  41. data/lib/scout_apm/instruments/active_record.rb +29 -324
  42. data/lib/scout_apm/instruments/delayed_job.rb +57 -0
  43. data/lib/scout_apm/instruments/elasticsearch.rb +6 -10
  44. data/lib/scout_apm/instruments/grape.rb +9 -12
  45. data/lib/scout_apm/instruments/http_client.rb +7 -14
  46. data/lib/scout_apm/instruments/influxdb.rb +6 -10
  47. data/lib/scout_apm/instruments/middleware_detailed.rb +11 -15
  48. data/lib/scout_apm/instruments/middleware_summary.rb +5 -11
  49. data/lib/scout_apm/instruments/mongoid.rb +8 -39
  50. data/lib/scout_apm/instruments/moped.rb +6 -11
  51. data/lib/scout_apm/instruments/net_http.rb +9 -27
  52. data/lib/scout_apm/instruments/percentile_sampler.rb +23 -42
  53. data/lib/scout_apm/instruments/process/process_cpu.rb +6 -11
  54. data/lib/scout_apm/instruments/process/process_memory.rb +12 -17
  55. data/lib/scout_apm/instruments/rails_router.rb +6 -12
  56. data/lib/scout_apm/instruments/redis.rb +6 -10
  57. data/lib/scout_apm/instruments/sinatra.rb +4 -5
  58. data/lib/scout_apm/job_record.rb +2 -4
  59. data/lib/scout_apm/layaway.rb +34 -88
  60. data/lib/scout_apm/layaway_file.rb +3 -13
  61. data/lib/scout_apm/layer.rb +60 -25
  62. data/lib/scout_apm/layer_converters/allocation_metric_converter.rb +6 -7
  63. data/lib/scout_apm/layer_converters/converter_base.rb +14 -203
  64. data/lib/scout_apm/layer_converters/depth_first_walker.rb +10 -22
  65. data/lib/scout_apm/layer_converters/error_converter.rb +8 -8
  66. data/lib/scout_apm/layer_converters/job_converter.rb +50 -37
  67. data/lib/scout_apm/layer_converters/metric_converter.rb +19 -18
  68. data/lib/scout_apm/layer_converters/request_queue_time_converter.rb +13 -13
  69. data/lib/scout_apm/layer_converters/slow_job_converter.rb +116 -52
  70. data/lib/scout_apm/layer_converters/slow_request_converter.rb +120 -51
  71. data/lib/scout_apm/metric_meta.rb +5 -0
  72. data/lib/scout_apm/metric_set.rb +1 -9
  73. data/lib/scout_apm/metric_stats.rb +8 -7
  74. data/lib/scout_apm/middleware.rb +9 -7
  75. data/lib/scout_apm/reporter.rb +24 -71
  76. data/lib/scout_apm/request_histograms.rb +0 -12
  77. data/lib/scout_apm/request_manager.rb +7 -5
  78. data/lib/scout_apm/scored_item_set.rb +0 -7
  79. data/lib/scout_apm/serializers/app_server_load_serializer.rb +0 -4
  80. data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
  81. data/lib/scout_apm/serializers/directive_serializer.rb +0 -4
  82. data/lib/scout_apm/serializers/payload_serializer.rb +4 -11
  83. data/lib/scout_apm/serializers/payload_serializer_to_json.rb +16 -35
  84. data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
  85. data/lib/scout_apm/server_integrations/passenger.rb +1 -1
  86. data/lib/scout_apm/server_integrations/puma.rb +2 -5
  87. data/lib/scout_apm/slow_job_policy.rb +13 -25
  88. data/lib/scout_apm/slow_job_record.rb +4 -13
  89. data/lib/scout_apm/slow_request_policy.rb +13 -25
  90. data/lib/scout_apm/slow_transaction.rb +5 -25
  91. data/lib/scout_apm/store.rb +32 -99
  92. data/lib/scout_apm/trace_compactor.rb +312 -0
  93. data/lib/scout_apm/tracer.rb +31 -35
  94. data/lib/scout_apm/tracked_request.rb +95 -262
  95. data/lib/scout_apm/utils/active_record_metric_name.rb +13 -88
  96. data/lib/scout_apm/utils/backtrace_parser.rb +4 -7
  97. data/lib/scout_apm/utils/fake_stacks.rb +87 -0
  98. data/lib/scout_apm/utils/installed_gems.rb +3 -7
  99. data/lib/scout_apm/utils/klass_helper.rb +2 -8
  100. data/lib/scout_apm/utils/null_logger.rb +13 -0
  101. data/lib/scout_apm/utils/sql_sanitizer.rb +5 -16
  102. data/lib/scout_apm/utils/sql_sanitizer_regex.rb +0 -7
  103. data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +0 -6
  104. data/lib/scout_apm/utils/unique_id.rb +0 -27
  105. data/lib/scout_apm/version.rb +2 -1
  106. data/lib/scout_apm.rb +25 -84
  107. data/scout_apm.gemspec +3 -17
  108. data/test/test_helper.rb +3 -57
  109. data/test/unit/agent_test.rb +54 -1
  110. data/test/unit/background_job_integrations/sidekiq_test.rb +3 -0
  111. data/test/unit/config_test.rb +12 -25
  112. data/test/unit/context_test.rb +4 -4
  113. data/test/unit/histogram_test.rb +4 -25
  114. data/test/unit/ignored_uris_test.rb +1 -1
  115. data/test/unit/instruments/active_record_instruments_test.rb +5 -0
  116. data/test/unit/layaway_test.rb +2 -62
  117. data/test/unit/serializers/payload_serializer_test.rb +15 -43
  118. data/test/unit/slow_request_policy_test.rb +6 -15
  119. data/test/unit/sql_sanitizer_test.rb +6 -53
  120. data/test/unit/store_test.rb +4 -73
  121. data/test/unit/utils/active_record_metric_name_test.rb +5 -59
  122. data/test/unit/utils/backtrace_parser_test.rb +1 -6
  123. data/tester.rb +53 -0
  124. metadata +28 -229
  125. data/.travis.yml +0 -26
  126. data/Guardfile +0 -43
  127. data/gems/README.md +0 -28
  128. data/gems/octoshark.gemfile +0 -4
  129. data/gems/rails3.gemfile +0 -5
  130. data/gems/rails4.gemfile +0 -4
  131. data/gems/rails5.gemfile +0 -4
  132. data/gems/rails6.gemfile +0 -4
  133. data/lib/scout_apm/agent/exit_handler.rb +0 -65
  134. data/lib/scout_apm/agent/preconditions.rb +0 -81
  135. data/lib/scout_apm/agent_context.rb +0 -261
  136. data/lib/scout_apm/auto_instrument/instruction_sequence.rb +0 -31
  137. data/lib/scout_apm/auto_instrument/layer.rb +0 -23
  138. data/lib/scout_apm/auto_instrument/parser.rb +0 -27
  139. data/lib/scout_apm/auto_instrument/rails.rb +0 -175
  140. data/lib/scout_apm/auto_instrument.rb +0 -5
  141. data/lib/scout_apm/background_job_integrations/legacy_sneakers.rb +0 -55
  142. data/lib/scout_apm/background_job_integrations/que.rb +0 -134
  143. data/lib/scout_apm/background_job_integrations/resque.rb +0 -88
  144. data/lib/scout_apm/background_job_integrations/shoryuken.rb +0 -124
  145. data/lib/scout_apm/background_job_integrations/sneakers.rb +0 -87
  146. data/lib/scout_apm/background_recorder.rb +0 -48
  147. data/lib/scout_apm/db_query_metric_set.rb +0 -97
  148. data/lib/scout_apm/db_query_metric_stats.rb +0 -102
  149. data/lib/scout_apm/debug.rb +0 -37
  150. data/lib/scout_apm/detailed_trace.rb +0 -217
  151. data/lib/scout_apm/error.rb +0 -27
  152. data/lib/scout_apm/error_service/error_buffer.rb +0 -39
  153. data/lib/scout_apm/error_service/error_record.rb +0 -211
  154. data/lib/scout_apm/error_service/ignored_exceptions.rb +0 -66
  155. data/lib/scout_apm/error_service/middleware.rb +0 -32
  156. data/lib/scout_apm/error_service/notifier.rb +0 -33
  157. data/lib/scout_apm/error_service/payload.rb +0 -47
  158. data/lib/scout_apm/error_service/periodic_work.rb +0 -17
  159. data/lib/scout_apm/error_service/railtie.rb +0 -11
  160. data/lib/scout_apm/error_service/sidekiq.rb +0 -80
  161. data/lib/scout_apm/error_service.rb +0 -32
  162. data/lib/scout_apm/extensions/config.rb +0 -87
  163. data/lib/scout_apm/extensions/transaction_callback_payload.rb +0 -74
  164. data/lib/scout_apm/git_revision.rb +0 -59
  165. data/lib/scout_apm/instrument_manager.rb +0 -88
  166. data/lib/scout_apm/instruments/action_view.rb +0 -141
  167. data/lib/scout_apm/instruments/http.rb +0 -48
  168. data/lib/scout_apm/instruments/memcached.rb +0 -43
  169. data/lib/scout_apm/instruments/resque.rb +0 -39
  170. data/lib/scout_apm/instruments/samplers.rb +0 -11
  171. data/lib/scout_apm/layer_children_set.rb +0 -86
  172. data/lib/scout_apm/layer_converters/database_converter.rb +0 -70
  173. data/lib/scout_apm/layer_converters/find_layer_by_type.rb +0 -38
  174. data/lib/scout_apm/layer_converters/histograms.rb +0 -15
  175. data/lib/scout_apm/layer_converters/trace_converter.rb +0 -184
  176. data/lib/scout_apm/limited_layer.rb +0 -126
  177. data/lib/scout_apm/logger.rb +0 -158
  178. data/lib/scout_apm/periodic_work.rb +0 -47
  179. data/lib/scout_apm/rack.rb +0 -26
  180. data/lib/scout_apm/remote/message.rb +0 -27
  181. data/lib/scout_apm/remote/recorder.rb +0 -57
  182. data/lib/scout_apm/remote/router.rb +0 -49
  183. data/lib/scout_apm/remote/server.rb +0 -60
  184. data/lib/scout_apm/reporting.rb +0 -143
  185. data/lib/scout_apm/serializers/db_query_serializer_to_json.rb +0 -15
  186. data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
  187. data/lib/scout_apm/synchronous_recorder.rb +0 -30
  188. data/lib/scout_apm/tasks/doctor.rb +0 -75
  189. data/lib/scout_apm/tasks/support.rb +0 -22
  190. data/lib/scout_apm/transaction.rb +0 -13
  191. data/lib/scout_apm/transaction_time_consumed.rb +0 -51
  192. data/lib/scout_apm/utils/gzip_helper.rb +0 -24
  193. data/lib/scout_apm/utils/marshal_logging.rb +0 -90
  194. data/lib/scout_apm/utils/numbers.rb +0 -14
  195. data/lib/scout_apm/utils/scm.rb +0 -14
  196. data/lib/tasks/doctor.rake +0 -11
  197. data/test/tmp/README.md +0 -17
  198. data/test/unit/agent_context_test.rb +0 -15
  199. data/test/unit/auto_instrument/assignments-instrumented.rb +0 -31
  200. data/test/unit/auto_instrument/assignments.rb +0 -31
  201. data/test/unit/auto_instrument/controller-ast.txt +0 -57
  202. data/test/unit/auto_instrument/controller-instrumented.rb +0 -49
  203. data/test/unit/auto_instrument/controller.rb +0 -49
  204. data/test/unit/auto_instrument/rescue_from-instrumented.rb +0 -13
  205. data/test/unit/auto_instrument/rescue_from.rb +0 -13
  206. data/test/unit/auto_instrument_test.rb +0 -54
  207. data/test/unit/db_query_metric_set_test.rb +0 -67
  208. data/test/unit/db_query_metric_stats_test.rb +0 -113
  209. data/test/unit/error_service/error_buffer_test.rb +0 -25
  210. data/test/unit/error_service/ignored_exceptions_test.rb +0 -49
  211. data/test/unit/extensions/periodic_callbacks_test.rb +0 -58
  212. data/test/unit/extensions/transaction_callbacks_test.rb +0 -58
  213. data/test/unit/fake_store_test.rb +0 -10
  214. data/test/unit/git_revision_test.rb +0 -15
  215. data/test/unit/instruments/active_record_test.rb +0 -40
  216. data/test/unit/instruments/net_http_test.rb +0 -27
  217. data/test/unit/instruments/percentile_sampler_test.rb +0 -133
  218. data/test/unit/layer_children_set_test.rb +0 -97
  219. data/test/unit/layer_converters/depth_first_walker_test.rb +0 -70
  220. data/test/unit/layer_converters/metric_converter_test.rb +0 -22
  221. data/test/unit/layer_converters/stubs.rb +0 -33
  222. data/test/unit/limited_layer_test.rb +0 -53
  223. data/test/unit/logger_test.rb +0 -69
  224. data/test/unit/remote/test_message.rb +0 -13
  225. data/test/unit/remote/test_router.rb +0 -33
  226. data/test/unit/remote/test_server.rb +0 -15
  227. data/test/unit/request_histograms_test.rb +0 -17
  228. data/test/unit/tracer_test.rb +0 -76
  229. data/test/unit/tracked_request_test.rb +0 -71
  230. data/test/unit/transaction_test.rb +0 -14
  231. data/test/unit/transaction_time_consumed_test.rb +0 -46
  232. data/test/unit/utils/numbers_test.rb +0 -15
  233. data/test/unit/utils/scm.rb +0 -17
@@ -1,59 +0,0 @@
1
- module ScoutApm
2
- class GitRevision
3
- attr_accessor :sha
4
-
5
- attr_reader :context
6
-
7
- def initialize(context)
8
- @context = context
9
- @sha = detect
10
- logger.debug "Detected Git Revision [#{@sha}]"
11
- end
12
-
13
- def logger
14
- context.logger
15
- end
16
-
17
- private
18
-
19
- def detect
20
- detect_from_config ||
21
- detect_from_heroku ||
22
- detect_from_capistrano ||
23
- detect_from_git
24
- end
25
-
26
- def detect_from_heroku
27
- ENV['HEROKU_SLUG_COMMIT']
28
- end
29
-
30
- # Config will locate the value from:
31
- # ENV variable - SCOUT_REVISION_SHA
32
- # YAML setting - revision_sha
33
- def detect_from_config
34
- context.config.value('revision_sha')
35
- end
36
-
37
- def detect_from_capistrano
38
- version = File.read(File.join(app_root, 'REVISION')).strip
39
- # Capistrano 3.0 - 3.1.x
40
- version || File.open(File.join(app_root, '..', 'revisions.log')).to_a.last.strip.sub(/.*as release ([0-9]+).*/, '\1')
41
- rescue
42
- logger.debug "Unable to detect Git Revision from Capistrano: #{$!.message}"
43
- nil
44
- end
45
-
46
- def detect_from_git
47
- if File.directory?(".git")
48
- `git rev-parse --short HEAD`.strip
49
- end
50
- rescue
51
- logger.debug "Unable to detect Git Revision from Git: #{$!.message}"
52
- nil
53
- end
54
-
55
- def app_root
56
- context.environment.root
57
- end
58
- end
59
- end
@@ -1,88 +0,0 @@
1
- module ScoutApm
2
- class InstrumentManager
3
- attr_reader :context
4
-
5
- attr_reader :installed_instruments
6
-
7
- def initialize(context)
8
- @context = context
9
- @installed_instruments = []
10
- end
11
-
12
- # Loads the instrumention logic.
13
- def install!
14
- case framework
15
- when :rails then
16
- install_instrument(ScoutApm::Instruments::ActionControllerRails2)
17
- when :rails3_or_4 then
18
- install_instrument(ScoutApm::Instruments::ActionControllerRails3Rails4)
19
- install_instrument(ScoutApm::Instruments::RailsRouter)
20
-
21
- if config.value("detailed_middleware")
22
- install_instrument(ScoutApm::Instruments::MiddlewareDetailed)
23
- else
24
- install_instrument(ScoutApm::Instruments::MiddlewareSummary)
25
- end
26
- end
27
-
28
- install_instrument(ScoutApm::Instruments::ActionView)
29
- install_instrument(ScoutApm::Instruments::ActiveRecord)
30
- install_instrument(ScoutApm::Instruments::Moped)
31
- install_instrument(ScoutApm::Instruments::Mongoid)
32
- install_instrument(ScoutApm::Instruments::NetHttp)
33
- install_instrument(ScoutApm::Instruments::HttpClient)
34
- install_instrument(ScoutApm::Instruments::Memcached)
35
- install_instrument(ScoutApm::Instruments::Redis)
36
- install_instrument(ScoutApm::Instruments::InfluxDB)
37
- install_instrument(ScoutApm::Instruments::Elasticsearch)
38
- install_instrument(ScoutApm::Instruments::Grape)
39
- rescue
40
- logger.warn "Exception loading instruments:"
41
- logger.warn $!.message
42
- logger.warn $!.backtrace
43
- end
44
-
45
- # Allows users to skip individual instruments via the config file
46
- def skip_instrument?(instrument_klass)
47
- instrument_short_name = instrument_klass.name.split("::").last
48
- (config.value("disabled_instruments") || []).include?(instrument_short_name)
49
- end
50
-
51
- private
52
-
53
- def install_instrument(instrument_klass)
54
- return if already_installed?(instrument_klass)
55
-
56
- if skip_instrument?(instrument_klass)
57
- logger.info "Skipping Disabled Instrument: #{instrument_klass} - To re-enable, change `disabled_instruments` key in scout_apm.yml"
58
- return
59
- end
60
-
61
- instance = instrument_klass.new(context)
62
- @installed_instruments << instance
63
- instance.install
64
- end
65
-
66
- def already_installed?(instrument_klass)
67
- @installed_instruments.any? do |already_installed_instrument|
68
- instrument_klass === already_installed_instrument
69
- end
70
- end
71
-
72
- ###################
73
- # Lookup Helpers #
74
- ###################
75
-
76
- def logger
77
- context.logger
78
- end
79
-
80
- def config
81
- context.config
82
- end
83
-
84
- def framework
85
- context.environment.framework
86
- end
87
- end
88
- end
@@ -1,141 +0,0 @@
1
- # Note, this instrument has the same logic in both Tracer and Module Prepend
2
- # versions. If you update, be sure you update in both spots.
3
- #
4
- # The prepend version was added for Rails 6 support - ActiveRecord prepends on
5
- # top of PartialRenderer#collection_with_template, which can (and does) cause
6
- # infinite loops with our alias_method approach.
7
- #
8
- # Even though Rails 6 forced us to use a prepend version, it is now used for
9
- # all Rubies that support it.
10
- module ScoutApm
11
- module Instruments
12
- class ActionView
13
- attr_reader :context
14
-
15
- def initialize(context)
16
- @context = context
17
- @installed = false
18
- end
19
-
20
- def logger
21
- context.logger
22
- end
23
-
24
- def installed?
25
- @installed
26
- end
27
-
28
- def prependable?
29
- context.environment.supports_module_prepend?
30
- end
31
-
32
- def install
33
- return unless defined?(::ActionView) && defined?(::ActionView::PartialRenderer)
34
-
35
- if prependable?
36
- install_using_prepend
37
- else
38
- install_using_tracer
39
- end
40
- @installed = true
41
- end
42
-
43
- def install_using_tracer
44
- logger.info "Instrumenting ActionView::PartialRenderer"
45
- ::ActionView::PartialRenderer.class_eval do
46
- include ScoutApm::Tracer
47
-
48
- instrument_method :render_partial,
49
- :type => "View",
50
- :name => '#{@template.virtual_path rescue "Unknown Partial"}/Rendering',
51
- :scope => true
52
-
53
- instrument_method :collection_with_template,
54
- :type => "View",
55
- :name => '#{@template.virtual_path rescue "Unknown Collection"}/Rendering',
56
- :scope => true
57
- end
58
-
59
- logger.info "Instrumenting ActionView::TemplateRenderer"
60
- ::ActionView::TemplateRenderer.class_eval do
61
- include ScoutApm::Tracer
62
- instrument_method :render_template,
63
- :type => "View",
64
- :name => '#{args[0].virtual_path rescue "Unknown"}/Rendering',
65
- :scope => true
66
- end
67
- end
68
-
69
- def install_using_prepend
70
- logger.info "Instrumenting ActionView::PartialRenderer"
71
- ::ActionView::PartialRenderer.prepend(ActionViewPartialRendererInstruments)
72
-
73
- logger.info "Instrumenting ActionView::TemplateRenderer"
74
- ::ActionView::TemplateRenderer.prepend(ActionViewTemplateRendererInstruments)
75
- end
76
-
77
- module ActionViewPartialRendererInstruments
78
- # In Rails 6, the signature changed to pass the view & template args directly, as opposed to through the instance var
79
- # New signature is: def render_partial(view, template)
80
- def render_partial(*args)
81
- req = ScoutApm::RequestManager.lookup
82
-
83
- maybe_template = args[1]
84
-
85
- template_name = @template.virtual_path rescue nil # Works on Rails 3.2 -> end of Rails 5 series
86
- template_name ||= maybe_template.virtual_path rescue nil # Works on Rails 6 -> 6.0.3
87
- template_name ||= "Unknown Partial"
88
-
89
- layer_name = template_name + "/Rendering"
90
- layer = ScoutApm::Layer.new("View", layer_name)
91
- layer.subscopable!
92
-
93
- begin
94
- req.start_layer(layer)
95
- super(*args)
96
- ensure
97
- req.stop_layer
98
- end
99
- end
100
-
101
- def collection_with_template(*args)
102
- req = ScoutApm::RequestManager.lookup
103
-
104
- template_name = @template.virtual_path rescue "Unknown Collection"
105
- template_name ||= "Unknown Collection"
106
- layer_name = template_name + "/Rendering"
107
-
108
- layer = ScoutApm::Layer.new("View", layer_name)
109
- layer.subscopable!
110
-
111
- begin
112
- req.start_layer(layer)
113
- super(*args)
114
- ensure
115
- req.stop_layer
116
- end
117
- end
118
- end
119
-
120
- module ActionViewTemplateRendererInstruments
121
- def render_template(*args)
122
- req = ScoutApm::RequestManager.lookup
123
-
124
- template_name = args[0].virtual_path rescue "Unknown"
125
- template_name ||= "Unknown"
126
- layer_name = template_name + "/Rendering"
127
-
128
- layer = ScoutApm::Layer.new("View", layer_name)
129
- layer.subscopable!
130
-
131
- begin
132
- req.start_layer(layer)
133
- super(*args)
134
- ensure
135
- req.stop_layer
136
- end
137
- end
138
- end
139
- end
140
- end
141
- end
@@ -1,48 +0,0 @@
1
- module ScoutApm
2
- module Instruments
3
- class HTTP
4
- attr_reader :context
5
-
6
- def initialize(context)
7
- @context = context
8
- @installed = false
9
- end
10
-
11
- def logger
12
- context.logger
13
- end
14
-
15
- def installed?
16
- @installed
17
- end
18
-
19
- def install
20
- if defined?(::HTTP) && defined?(::HTTP::Client)
21
- @installed = true
22
-
23
- logger.info "Instrumenting HTTP::Client"
24
-
25
- ::HTTP::Client.class_eval do
26
- include ScoutApm::Tracer
27
-
28
- def request_with_scout_instruments(verb, uri, opts = {})
29
- self.class.instrument("HTTP", verb, :ignore_children => true, :desc => request_scout_description(verb, uri)) do
30
- request_without_scout_instruments(verb, uri, opts)
31
- end
32
- end
33
-
34
- def request_scout_description(verb, uri)
35
- max_length = ScoutApm::Agent.instance.context.config.value('instrument_http_url_length')
36
- (String(uri).split('?').first)[0..(max_length - 1)]
37
- rescue
38
- ""
39
- end
40
-
41
- alias request_without_scout_instruments request
42
- alias request request_with_scout_instruments
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,43 +0,0 @@
1
- module ScoutApm
2
- module Instruments
3
- class Memcached
4
- attr_reader :context
5
-
6
- def initialize(context)
7
- @context = context
8
- @installed = false
9
- end
10
-
11
- def logger
12
- context.logger
13
- end
14
-
15
- def installed?
16
- @installed
17
- end
18
-
19
- def install
20
- if defined?(::Dalli) && defined?(::Dalli::Client)
21
- @installed = true
22
-
23
- logger.info "Instrumenting Memcached"
24
-
25
- ::Dalli::Client.class_eval do
26
- include ScoutApm::Tracer
27
-
28
- def perform_with_scout_instruments(*args, &block)
29
- command = args.first rescue "Unknown"
30
-
31
- self.class.instrument("Memcached", command) do
32
- perform_without_scout_instruments(*args, &block)
33
- end
34
- end
35
-
36
- alias_method :perform_without_scout_instruments, :perform
37
- alias_method :perform, :perform_with_scout_instruments
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,39 +0,0 @@
1
- module ScoutApm
2
- module Instruments
3
- module Resque
4
- def around_perform_with_scout_instruments(*args)
5
- job_name = self.to_s
6
- queue = find_queue
7
-
8
- if job_name == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
9
- job_name = args.first["job_class"] rescue job_name
10
- queue = args.first["queue_name"] rescue queue_name
11
- end
12
-
13
- req = ScoutApm::RequestManager.lookup
14
-
15
- begin
16
- req.start_layer(ScoutApm::Layer.new('Queue', queue))
17
- started_queue = true
18
- req.start_layer(ScoutApm::Layer.new('Job', job_name))
19
- started_job = true
20
-
21
- yield
22
- rescue => e
23
- req.error!
24
- raise
25
- ensure
26
- req.stop_layer if started_job
27
- req.stop_layer if started_queue
28
- end
29
- end
30
-
31
- def find_queue
32
- return @queue if @queue
33
- return queue if self.respond_to?(:queue)
34
- return "unknown"
35
- end
36
- end
37
- end
38
- end
39
-
@@ -1,11 +0,0 @@
1
- module ScoutApm
2
- module Instruments
3
- class Samplers
4
- DEFAULT_SAMPLERS = [
5
- ScoutApm::Instruments::Process::ProcessCpu,
6
- ScoutApm::Instruments::Process::ProcessMemory,
7
- ScoutApm::Instruments::PercentileSampler,
8
- ]
9
- end
10
- end
11
- end
@@ -1,86 +0,0 @@
1
- module ScoutApm
2
- # A set of children records for any given Layer. This implements some
3
- # rate-limiting logic.
4
- #
5
- # We store the first `unique_cutoff` count of each layer type. So if cutoff
6
- # is 1000, we'd store 1000 HTTP layers, and 1000 ActiveRecord calls, and 1000
7
- # of each other layer type. After that, make a LimitedLayer object and store
8
- # only aggregate counts and times of future layers of that type. (So the
9
- # 1001st an onward of ActiveRecord would get only aggregate times, and
10
- # counts, without any detail about the SQL called)
11
- #
12
- # When the set of children is small, keep them unique
13
- # When the set of children gets large enough, stop keeping details
14
- #
15
- # The next optimization, which is not yet implemented:
16
- # when the set of children gets larger, attempt to merge them without data loss
17
- class LayerChildrenSet
18
- include Enumerable
19
-
20
- # By default, how many unique children of a type do we store before
21
- # flipping over to storing only aggregate info.
22
- DEFAULT_UNIQUE_CUTOFF = 2000
23
- attr_reader :unique_cutoff
24
-
25
- # The Set of children objects
26
- attr_reader :children
27
- private :children
28
-
29
- def initialize(unique_cutoff = DEFAULT_UNIQUE_CUTOFF)
30
- @children = Hash.new
31
- @limited_layers = nil # populated when needed
32
- @unique_cutoff = unique_cutoff
33
- end
34
-
35
- def child_set(metric_type)
36
- children[metric_type] = Set.new if !children.has_key?(metric_type)
37
- children[metric_type]
38
- end
39
-
40
- # Add a new layer into this set
41
- # Only add completed layers - otherwise this will collect up incorrect info
42
- # into the created LimitedLayer, since it will "freeze" any current data for
43
- # total_call_time and similar methods.
44
- def <<(child)
45
- metric_type = child.type
46
- set = child_set(metric_type)
47
-
48
- if set.size >= unique_cutoff
49
- # find or create limited_layer
50
- @limited_layers ||= Hash.new
51
- layer = if @limited_layers.has_key?(metric_type)
52
- @limited_layers[metric_type]
53
- else
54
- @limited_layers[metric_type] = LimitedLayer.new(metric_type)
55
- end
56
-
57
- layer.absorb(child)
58
- else
59
- # we have space just add it
60
- set << child
61
- end
62
- end
63
-
64
- def each
65
- children.each do |_type, set|
66
- set.each do |child_layer|
67
- yield child_layer
68
- end
69
- end
70
-
71
- if @limited_layers
72
- @limited_layers.each do |_type, limited_layer|
73
- yield limited_layer
74
- end
75
- end
76
- end
77
-
78
- def length
79
- @children.length
80
- end
81
-
82
- def size
83
- @children.size
84
- end
85
- end
86
- end
@@ -1,70 +0,0 @@
1
- module ScoutApm
2
- module LayerConverters
3
- class DatabaseConverter < ConverterBase
4
- def initialize(*)
5
- super
6
- @db_query_metric_set = DbQueryMetricSet.new(context)
7
- end
8
-
9
- def register_hooks(walker)
10
- super
11
-
12
- return unless scope_layer
13
-
14
- walker.on do |layer|
15
- next if skip_layer?(layer)
16
- stat = DbQueryMetricStats.new(
17
- model_name(layer),
18
- operation_name(layer),
19
- scope_layer.legacy_metric_name, # controller_scope
20
- 1, # count, this is a single query, so 1
21
- layer.total_call_time,
22
- records_returned(layer)
23
- )
24
- @db_query_metric_set << stat
25
- end
26
- end
27
-
28
- def record!
29
- # Everything in the metric set here is from a single transaction, which
30
- # we want to keep track of. (One web call did a User#find 10 times, but
31
- # only due to 1 http request)
32
- @db_query_metric_set.increment_transaction_count!
33
- @store.track_db_query_metrics!(@db_query_metric_set)
34
-
35
- nil # not returning anything in the layer results ... not used
36
- end
37
-
38
- def skip_layer?(layer)
39
- layer.type != 'ActiveRecord' ||
40
- layer.limited? ||
41
- super
42
- end
43
-
44
- private
45
-
46
-
47
- # If we can't name the model, default to:
48
- DEFAULT_MODEL = "SQL"
49
-
50
- # If we can't name the operation, default to:
51
- DEFAULT_OPERATION = "other"
52
-
53
- def model_name(layer)
54
- layer.name.to_s.split("/").first || DEFAULT_MODEL
55
- end
56
-
57
- def operation_name(layer)
58
- layer.name.to_s.split("/")[1] || DEFAULT_OPERATION
59
- end
60
-
61
- def records_returned(layer)
62
- if layer.annotations
63
- layer.annotations.fetch(:record_count, 0)
64
- else
65
- 0
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,38 +0,0 @@
1
- # Scope is determined by the first Controller we hit. Most of the time
2
- # there will only be 1 anyway. But if you have a controller that calls
3
- # another controller method, we may pick that up:
4
- # def update
5
- # show
6
- # render :update
7
- # end
8
- module ScoutApm
9
- module LayerConverters
10
- class FindLayerByType
11
- def initialize(request)
12
- @request = request
13
- end
14
-
15
- def scope
16
- @scope ||= call(["Controller", "Job"])
17
- end
18
-
19
- def controller
20
- @controller ||= call(["Controller"])
21
- end
22
-
23
- def job
24
- @job ||= call(["Job"])
25
- end
26
-
27
- def queue
28
- @queue ||= call(["Queue"])
29
- end
30
-
31
- def call(layer_types)
32
- walker = DepthFirstWalker.new(@request.root_layer)
33
- walker.on {|l| return l if layer_types.include?(l.type) }
34
- walker.walk
35
- end
36
- end
37
- end
38
- end
@@ -1,15 +0,0 @@
1
- module ScoutApm
2
- module LayerConverters
3
- class Histograms < ConverterBase
4
- # Updates immediate and long-term histograms for both job and web requests
5
- def record!
6
- if request.unique_name != :unknown
7
- context.request_histograms.add(request.unique_name, root_layer.total_call_time)
8
- context.request_histograms_by_time[@store.current_timestamp].
9
- add(request.unique_name, root_layer.total_call_time)
10
- end
11
- nil # not returning anything in the layer results ... not used
12
- end
13
- end
14
- end
15
- end