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,60 +0,0 @@
1
- # Web Server bound to localhost that listens for remote agent reports. Forwards
2
- # onto the router
3
- module ScoutApm
4
- module Remote
5
- class Server
6
- attr_reader :router
7
- attr_reader :bind
8
- attr_reader :port
9
- attr_reader :logger
10
-
11
- def initialize(bind, port, router, logger)
12
- @router = router
13
- @logger = logger
14
- @bind = bind
15
- @port = port
16
- @server = nil
17
- end
18
-
19
- def start
20
- require 'webrick'
21
-
22
- @server = WEBrick::HTTPServer.new(
23
- :BindAddress => bind,
24
- :Port => port,
25
- :AccessLog => [],
26
- :Logger => @logger
27
- )
28
-
29
- @server.mount_proc '/' do |request, response|
30
- router.handle(request.body)
31
-
32
- # arbitrary response, client doesn't expect anything in particular
33
- response.body = 'Ok'
34
- end
35
-
36
- @thread = Thread.new do
37
- begin
38
- logger.debug("Remote: Starting Server on #{bind}:#{port}")
39
-
40
- @server.start
41
-
42
- logger.debug("Remote: Server returned after #start call, thread exiting")
43
- rescue => e
44
- logger.debug("Remote: Server Exception, #{e},\n#{e.backtrace.join("\n\t")}")
45
- end
46
- end
47
- end
48
-
49
- def running?
50
- @thread.alive?
51
- @server && @server.status == :Running
52
- end
53
-
54
- def stop
55
- @server.stop
56
- @thread.kill
57
- end
58
- end
59
- end
60
- end
@@ -1,143 +0,0 @@
1
- # Methods related to sending metrics to scoutapp.com.
2
- module ScoutApm
3
- class Reporting
4
- attr_reader :context
5
-
6
- def initialize(context)
7
- @context = context
8
- end
9
-
10
- def logger
11
- context.logger
12
- end
13
-
14
- def reporter
15
- @reporter ||= ScoutApm::Reporter.new(context, :checkin)
16
- end
17
-
18
- # The data moves through a treadmill of reporting, coordinating several Rails processes by using an external file.
19
- # * During the minute it is being recorded by the instruments, it gets
20
- # recorded into the ram of each process (in the Store class).
21
- # * The minute after, each process writes its own metrics to a shared LayawayFile
22
- # * The minute after that, the first process to wake up pushes the combined
23
- # data to the server, and wipes it. Next processes don't have anything to do.
24
- #
25
- # At any given point, there is data in each of those steps, moving its way through the process
26
- def process_metrics
27
- # Do any per-minute work necessary for the store
28
- context.store.tick!
29
-
30
- # Write the previous minute's data to the shared-across-process layaway file.
31
- context.store.write_to_layaway(context.layaway)
32
-
33
- # Attempt to send 2 minutes ago's data up to the server. This
34
- # only acctually occurs if this process is the first to wake up this
35
- # minute.
36
- report_to_server
37
- end
38
-
39
- # In a running app, one process will get the period ready for delivery, the others will see 0.
40
- def report_to_server
41
- period_to_report = ScoutApm::StoreReportingPeriodTimestamp.minutes_ago(2)
42
-
43
- logger.debug("Attempting to claim #{period_to_report.to_s}")
44
-
45
- did_write = context.layaway.with_claim(period_to_report) do |rps|
46
- logger.debug("Succeeded claiming #{period_to_report.to_s}")
47
-
48
- begin
49
- merged = rps.inject { |memo, rp| memo.merge(rp) }
50
- logger.debug("Merged #{rps.length} reporting periods, delivering")
51
- metadata = metadata(merged)
52
- deliver_period(merged,metadata)
53
- context.extensions.run_periodic_callbacks(merged, metadata)
54
- true
55
- rescue => e
56
- logger.debug("Error merging reporting periods #{e.message}")
57
- logger.debug("Error merging reporting periods #{e.backtrace}")
58
- false
59
- end
60
-
61
- end
62
-
63
- if !did_write
64
- logger.debug("Failed to obtain claim for #{period_to_report.to_s}")
65
- end
66
- end
67
-
68
- def metadata(reporting_period)
69
- {
70
- :app_root => context.environment.root.to_s,
71
- :unique_id => ScoutApm::Utils::UniqueId.simple,
72
- :agent_version => ScoutApm::VERSION,
73
- :agent_time => reporting_period.timestamp.to_s,
74
- :agent_pid => Process.pid,
75
- :platform => "ruby",
76
- }
77
- end
78
-
79
- def deliver_period(reporting_period,metadata)
80
- metrics = reporting_period.metrics_payload
81
- slow_transactions = reporting_period.slow_transactions_payload
82
- jobs = reporting_period.jobs
83
- slow_jobs = reporting_period.slow_jobs_payload
84
- histograms = reporting_period.histograms
85
- db_query_metrics = reporting_period.db_query_metrics_payload
86
- traces = (slow_transactions.map(&:span_trace) + slow_jobs.map(&:span_trace)).compact
87
-
88
- log_deliver(metrics, slow_transactions, metadata, slow_jobs, histograms)
89
-
90
- payload = ScoutApm::Serializers::PayloadSerializer.serialize(metadata, metrics, slow_transactions, jobs, slow_jobs, histograms, db_query_metrics, traces)
91
- logger.debug("Sending payload w/ Headers: #{headers.inspect}")
92
-
93
- reporter.report(payload, headers)
94
- rescue => e
95
- logger.warn "Error on checkin"
96
- logger.info e.message
97
- logger.debug e.backtrace
98
- end
99
-
100
- def log_deliver(metrics, slow_transactions, metadata, jobs_traces, histograms)
101
- total_request_count = metrics.
102
- select { |meta,stats| meta.metric_name =~ /\AController/ }.
103
- inject(0) {|sum, (_, stat)| sum + stat.call_count }
104
-
105
- memory = metrics.
106
- find {|meta,stats| meta.metric_name =~ /\AMemory/ }
107
- process_log_str = if memory
108
- "Recorded from #{memory.last.call_count} processes"
109
- else
110
- "Recorded across (unknown) processes"
111
- end
112
-
113
- time_clause = "[#{Time.parse(metadata[:agent_time]).strftime("%H:%M")}]"
114
- metrics_clause = "#{metrics.length} Metrics for #{total_request_count} requests"
115
- slow_trans_clause = "#{slow_transactions.length} Slow Transaction Traces"
116
- job_clause = "#{jobs_traces.length} Job Traces"
117
- histogram_clause = "#{histograms.length} Histograms"
118
-
119
- logger.info "#{time_clause} Delivering #{metrics_clause} and #{slow_trans_clause} and #{job_clause}, #{process_log_str}."
120
- logger.debug("\n\nMetrics: #{metrics.pretty_inspect}\nSlowTrans: #{slow_transactions.pretty_inspect}\nMetadata: #{metadata.inspect.pretty_inspect}\n\n")
121
- end
122
-
123
- # TODO: Move this into PayloadSerializer?
124
- # XXX: Remove non-json report format entirely
125
- def headers
126
- if ScoutApm::Agent.instance.context.config.value("report_format") == 'json'
127
- headers = {'Content-Type' => 'application/json'}
128
- else
129
- headers = {}
130
- end
131
- end
132
-
133
- # Before reporting, lookup metric_id for each MetricMeta. This speeds up
134
- # reporting on the server-side.
135
- def add_metric_ids(metrics)
136
- metrics.each do |meta,stats|
137
- if metric_id = metric_lookup[meta]
138
- meta.metric_id = metric_id
139
- end
140
- end
141
- end
142
- end
143
- end
@@ -1,15 +0,0 @@
1
- module ScoutApm
2
- module Serializers
3
- class DbQuerySerializerToJson
4
- attr_reader :db_query_metrics
5
-
6
- def initialize(db_query_metrics)
7
- @db_query_metrics = db_query_metrics
8
- end
9
-
10
- def as_json
11
- db_query_metrics.map{|metric| metric.as_json }
12
- end
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
-
2
- module ScoutApm
3
- module Serializers
4
- class HistogramsSerializerToJson
5
- attr_reader :histograms
6
-
7
- def initialize(histograms)
8
- @histograms = histograms
9
- end
10
-
11
- def as_json
12
- histograms.map do |histo|
13
- {
14
- "name" => histo.name,
15
- "histogram" => histo.histogram.as_json,
16
- }
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- # Provide a synchronous approach to recording TrackedRequests
2
- # Doesn't attempt to background the work, or do it elsewhere. It happens
3
- # inline, in the caller thread right when record! is called
4
-
5
- module ScoutApm
6
- class SynchronousRecorder
7
- attr_reader :context
8
-
9
- def initialize(context)
10
- @context = context
11
- end
12
-
13
- def logger
14
- context.logger
15
- end
16
-
17
- def start
18
- # nothing to do
19
- self
20
- end
21
-
22
- def stop
23
- # nothing to do
24
- end
25
-
26
- def record!(request)
27
- request.record!
28
- end
29
- end
30
- end
@@ -1,75 +0,0 @@
1
- module ScoutApm
2
- module Tasks
3
- class Doctor
4
- def self.run!
5
- new.run!
6
- end
7
-
8
- def initialize()
9
- end
10
-
11
- def run!
12
- puts "Scout Doctor"
13
- puts "============"
14
- puts
15
- puts "Detected App Server: #{agent_context.environment.app_server_integration.name}"
16
- # puts "Detected Background Job: #{agent_context.environment.background_job_integration.name}"
17
- puts
18
- puts "Instruments:"
19
- puts "----------------------------------------"
20
- puts installed_instruments
21
- puts
22
- puts
23
- puts "Configuration Settings:"
24
- puts "-------------|------------------------------|-------"
25
- puts " From | Key | Value "
26
- puts "-------------|------------------------------|-------"
27
- puts configuration_settings
28
- puts
29
- puts
30
- puts "Misc:"
31
- puts "---------------"
32
- puts "Layaway Files stored at: #{agent_context.layaway.directory}"
33
- puts "Logs stored at: #{log_details}"
34
-
35
- end
36
-
37
- def agent_context
38
- ScoutApm::Agent.instance.context
39
- end
40
-
41
- def installed_instruments
42
- ScoutApm::Agent.
43
- instance.
44
- instrument_manager.
45
- installed_instruments.
46
- map{|instance| "#{instance.installed? ? "Installed " : "Not Installed"} - #{instance.class.to_s}"}.
47
- join("\n")
48
- end
49
-
50
- def configuration_settings
51
- all_settings = agent_context.config.all_settings
52
-
53
- longest_key = all_settings.
54
- map{|setting| setting[:key] }.
55
- inject(0) { |len, key| key.length > len ? key.length : len }
56
-
57
- format_string = "%12s | %-#{longest_key}s | %s"
58
-
59
- all_settings.
60
- map{|setting| sprintf format_string, setting[:source], setting[:key], setting[:value]}.
61
- join("\n")
62
- end
63
-
64
- def log_details
65
- if agent_context.logger.log_destination == STDOUT
66
- "STDOUT"
67
- elsif agent_context.logger.log_destination == STDERR
68
- "STDERR"
69
- else
70
- "#{agent_context.logger.log_file_path}"
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,22 +0,0 @@
1
- module ScoutApm
2
- module Tasks
3
- class Support
4
- def self.run!
5
- puts "Support Task"
6
- new.run!
7
- end
8
-
9
- def initialize
10
- @doctor = ScoutApm::Tasks::Doctor.new
11
- end
12
-
13
- def run!
14
- instruments = @doctor.installed_instruments
15
- config = @doctor.configuration_settings
16
- collect_logs
17
-
18
- post_data
19
- end
20
- end
21
- end
22
- end
@@ -1,13 +0,0 @@
1
- module ScoutApm
2
- module Transaction
3
- # Ignores the current request
4
- def self.ignore!
5
- ::ScoutApm::RequestManager.lookup.ignore_request!
6
- end
7
-
8
- # Renames the last Controller or Job layer
9
- def self.rename(name)
10
- ::ScoutApm::RequestManager.lookup.name_override = name
11
- end
12
- end
13
- end
@@ -1,51 +0,0 @@
1
- module ScoutApm
2
- class TransactionTimeConsumed
3
- # Private Accessor:
4
- # A hash of Endpoint Name to an time consumed record
5
- attr_reader :endpoints
6
- private :endpoints
7
-
8
- # Private Accessor:
9
- # The total time spent across all endpoints
10
- attr_reader :total_duration
11
- private :total_duration
12
-
13
- def initialize
14
- @total_duration = 0.0
15
- @endpoints = Hash.new { |h, k| h[k] = TotalTimeRecord.new }
16
- end
17
-
18
- def add(item, duration)
19
- @total_duration += duration.to_f
20
- @endpoints[item].add(duration.to_f)
21
- end
22
-
23
- def percent_of_total(item)
24
- if total_duration == 0.0
25
- 0
26
- else
27
- @endpoints[item].total_duration / total_duration
28
- end
29
- end
30
-
31
- def total_time_for(item)
32
- @endpoints[item].total_duration
33
- end
34
-
35
- def call_count_for(item)
36
- @endpoints[item].count
37
- end
38
-
39
- # Time is in seconds
40
- TotalTimeRecord = Struct.new(:total_duration, :count) do
41
- def initialize
42
- super(0, 0)
43
- end
44
-
45
- def add(duration)
46
- self.total_duration += duration.to_f
47
- self.count += 1
48
- end
49
- end
50
- end
51
- end
@@ -1,24 +0,0 @@
1
- module ScoutApm
2
- module Utils
3
- # A simple wrapper around Ruby's built-in gzip support.
4
- class GzipHelper
5
- DEFAULT_GZIP_LEVEL = 5
6
-
7
- attr_reader :level
8
-
9
- def initialize(level = DEFAULT_GZIP_LEVEL)
10
- @level = level
11
- end
12
-
13
- def deflate(str)
14
- strio = StringIO.new
15
-
16
- gz = Zlib::GzipWriter.new(strio, level)
17
- gz.write str
18
- gz.close
19
-
20
- strio.string
21
- end
22
- end
23
- end
24
- end
@@ -1,90 +0,0 @@
1
- module ScoutApm
2
- module Utils
3
- class Error < StandardError; end
4
-
5
- class InstanceVar
6
- attr_reader :name
7
- attr_reader :obj
8
-
9
- def initialize(name, obj, parent)
10
- @name = name
11
- @obj = obj
12
- @parent = parent
13
- end
14
-
15
- def to_s
16
- "#{@name} - #{obj.class}"
17
- end
18
-
19
- def history
20
- (@parent.nil? ? [] : @parent.history) + [to_s]
21
- end
22
- end
23
-
24
- class MarshalLogging
25
- def initialize(base_obj)
26
- @base_obj = base_obj
27
- end
28
-
29
- def dive
30
- to_investigate = [InstanceVar.new('Root', @base_obj, nil)]
31
- max_to_check = 10000
32
- checked = 0
33
-
34
- while (var = to_investigate.shift)
35
- checked += 1
36
- if checked > max_to_check
37
- return "Limiting Checks (max = #{max_to_check})"
38
- end
39
-
40
- obj = var.obj
41
-
42
- if offending_hash?(obj)
43
- return "Found undumpable object: #{var.history}"
44
- end
45
-
46
- if !dumps?(obj)
47
- if obj.is_a? Hash
48
- keys = obj.keys
49
- keys.each do |key|
50
- to_investigate.push(
51
- InstanceVar.new(key.to_s, obj[key], var)
52
- )
53
- end
54
- elsif obj.is_a? Array
55
- obj.each_with_index do |value, idx|
56
- to_investigate.push(
57
- InstanceVar.new("Index #{idx}", value, var)
58
- )
59
- end
60
- else
61
- symbols = obj.instance_variables
62
- if !symbols.any?
63
- return "Found undumpable object: #{var.history}"
64
- end
65
-
66
- symbols.each do |sym|
67
- to_investigate.push(
68
- InstanceVar.new(sym, obj.instance_variable_get(sym), var)
69
- )
70
- end
71
- end
72
- end
73
- end
74
-
75
- true
76
- end
77
-
78
- def dumps?(obj)
79
- Marshal.dump(obj)
80
- true
81
- rescue TypeError
82
- false
83
- end
84
-
85
- def offending_hash?(obj)
86
- obj.is_a?(Hash) && !obj.default_proc.nil?
87
- end
88
- end
89
- end
90
- end
@@ -1,14 +0,0 @@
1
- module ScoutApm
2
- module Utils
3
- class Numbers
4
-
5
- # Round a float to a certain number of decimal places
6
- def self.round(number, decimals)
7
- factor = 10 ** decimals
8
-
9
- (number * factor).round / factor.to_f
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- # Module for helping to deal with Source Code Management settings
2
- module ScoutApm
3
- module Utils
4
- class Scm
5
- # Takes an *already relative* path +path+
6
- # Returns a relative path, prepending the configured +scm_subdirectory+ environment string
7
- def self.relative_scm_path(path, scm_subdirectory = ScoutApm::Agent.instance.context.environment.scm_subdirectory)
8
- @@scm_subdirectory ||= scm_subdirectory.sub(/^\//, '')
9
- @@scm_subdirectoy_blank ||= @@scm_subdirectory.empty?
10
- @@scm_subdirectoy_blank ? path : File.join(@@scm_subdirectory, path)
11
- end
12
- end
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- namespace :scout do
2
- desc "Prints out details of the detected environment"
3
- task :doctor => :environment do
4
- ScoutApm::Tasks::Doctor.run!
5
- end
6
-
7
- desc "Collect logs, settings and environment to help debug issues"
8
- task :support => :environment do
9
- ScoutApm::Tasks::Support.run!
10
- end
11
- end
data/test/tmp/README.md DELETED
@@ -1,17 +0,0 @@
1
- # Temporary Data
2
-
3
- Use this directory for temporary test files.
4
-
5
- ## Usage
6
-
7
- The `DATA_FILE_DIR` constant points at this directory:
8
-
9
- ```ruby
10
- class MyTest < Minitest::Test
11
- def database_path
12
- File.expand_path('test.sqlite3', DATA_FILE_DIR)
13
- end
14
-
15
- # ... tests
16
- end
17
- ```
@@ -1,15 +0,0 @@
1
- require "test_helper"
2
-
3
- require "scout_apm/agent_context"
4
-
5
- class AgentContextTest < Minitest::Test
6
- def test_has_error_service_ignored_exceptions
7
- context = ScoutApm::AgentContext.new
8
- assert ScoutApm::ErrorService::IgnoredExceptions, context.ignored_exceptions.class
9
- end
10
-
11
- def test_has_error_buffer
12
- context = ScoutApm::AgentContext.new
13
- assert ScoutApm::ErrorService::ErrorBuffer, context.error_buffer.class
14
- end
15
- end
@@ -1,31 +0,0 @@
1
-
2
- class Assignments
3
- def test_op_asgn
4
- foo.bar += ::ScoutApm::AutoInstrument("User.size",["ROOT/test/unit/auto_instrument/assignments.rb:4:in `test_op_asgn'"]){User.size}
5
- foo.bar -= ::ScoutApm::AutoInstrument("User.size",["ROOT/test/unit/auto_instrument/assignments.rb:5:in `test_op_asgn'"]){User.size}
6
- end
7
-
8
- def nested_assignment
9
- @email ||= if (email = ::ScoutApm::AutoInstrument("session[\"email\"]",["ROOT/test/unit/auto_instrument/assignments.rb:9:in `nested_assignment'"]){session["email"]}).present?
10
- ::ScoutApm::AutoInstrument("User.where(email: email).first",["ROOT/test/unit/auto_instrument/assignments.rb:10:in `nested_assignment'"]){User.where(email: email).first}
11
- else
12
- nil
13
- end
14
- end
15
-
16
- def paginate_collection(coll)
17
- page = (::ScoutApm::AutoInstrument("params[:page].present?",["ROOT/test/unit/auto_instrument/assignments.rb:17:in `paginate_collection'"]){params[:page].present?} ? ::ScoutApm::AutoInstrument("params[:page].to_i",["ROOT/test/unit/auto_instrument/assignments.rb:17:in `paginate_collection'"]){params[:page].to_i} : 1)
18
- per_page = (::ScoutApm::AutoInstrument("params[:per_page].present?",["ROOT/test/unit/auto_instrument/assignments.rb:18:in `paginate_collection'"]){params[:per_page].present?} ? ::ScoutApm::AutoInstrument("params[:per_page].to_i",["ROOT/test/unit/auto_instrument/assignments.rb:18:in `paginate_collection'"]){params[:per_page].to_i} : 20)
19
- pagination, self.collection = ::ScoutApm::AutoInstrument("pagy(...",["ROOT/test/unit/auto_instrument/assignments.rb:19:in `paginate_collection'"]){pagy(
20
- coll,
21
- items: per_page,
22
- page: page
23
- )}
24
- ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:24:in `paginate_collection'"]){headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s}
25
- ::ScoutApm::AutoInstrument("headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:25:in `paginate_collection'"]){headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s}
26
- ::ScoutApm::AutoInstrument("headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:26:in `paginate_collection'"]){headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s}
27
- ::ScoutApm::AutoInstrument("headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:27:in `paginate_collection'"]){headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s}
28
- ::ScoutApm::AutoInstrument("headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s",["ROOT/test/unit/auto_instrument/assignments.rb:28:in `paginate_collection'"]){headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s}
29
- ::ScoutApm::AutoInstrument("collection",["ROOT/test/unit/auto_instrument/assignments.rb:29:in `paginate_collection'"]){collection}
30
- end
31
- end