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
@@ -5,33 +5,17 @@
5
5
  # For misc context, use @Context#add@.
6
6
  module ScoutApm
7
7
  class Context
8
- attr_reader :context
9
-
10
- def initialize(context)
11
- @context = context
8
+ def initialize
12
9
  @extra = {}
13
10
  @user = {}
14
11
  end
15
12
 
16
- def logger
17
- context.logger
18
- end
19
-
20
13
  # Generates a hash representation of the Context.
21
14
  # Example: {:monthly_spend => 100, :user => {:ip => '127.0.0.1'}}
22
15
  def to_hash
23
16
  @extra.merge({:user => @user})
24
17
  end
25
18
 
26
- def to_flat_hash
27
- h = to_hash
28
- user = h.delete(:user)
29
- if user
30
- user.each { |k,v| h["user_#{k}"] = v}
31
- end
32
- h
33
- end
34
-
35
19
  def self.current
36
20
  RequestManager.lookup.context
37
21
  end
@@ -94,7 +78,7 @@ module ScoutApm
94
78
  if value.nil?
95
79
  false # don't log this ... easy to happen
96
80
  elsif !valid_type?([String, Symbol, Numeric, Time, Date, TrueClass, FalseClass],value)
97
- logger.info "The value for [#{key_value.keys.first}] is not a valid type [#{value.class}]."
81
+ ScoutApm::Agent.instance.logger.info "The value for [#{key_value.keys.first}] is not a valid type [#{value.class}]."
98
82
  false
99
83
  else
100
84
  true
@@ -108,12 +92,12 @@ module ScoutApm
108
92
  false # don't log this ... easy to happen
109
93
  # ensure a string or a symbol
110
94
  elsif !valid_type?([String, Symbol],key)
111
- logger.info "The key [#{key}] is not a valid type [#{key.class}]."
95
+ ScoutApm::Agent.instance.logger.info "The key [#{key}] is not a valid type [#{key.class}]."
112
96
  return false
113
97
  end
114
98
  # only alphanumeric, dash, and underscore allowed.
115
99
  if key.to_s.match(/[^\w-]/)
116
- logger.info "They key name [#{key}] is not valid."
100
+ ScoutApm::Agent.instance.logger.info "They key name [#{key}] is not valid."
117
101
  return false
118
102
  end
119
103
  true
@@ -0,0 +1,12 @@
1
+ namespace :scout_apm do
2
+ namespace :deploy do
3
+ task :starting do
4
+ # Warn if missing scout apm deploy creds?
5
+ end
6
+ task :finished do
7
+ ScoutApm::Agent.instance.deploy_integration.report
8
+ end
9
+ end
10
+ end
11
+
12
+ after 'deploy:finished', 'scout_apm:deploy:finished'
@@ -0,0 +1,83 @@
1
+ require 'scout_apm'
2
+
3
+ module ScoutApm
4
+ module DeployIntegrations
5
+ class Capistrano2
6
+ attr_reader :logger
7
+
8
+ def initialize(logger)
9
+ @logger = logger
10
+ @cap = defined?(Capistrano::Configuration) ? ObjectSpace.each_object(Capistrano::Configuration).map.first : nil rescue nil
11
+ end
12
+
13
+ def name
14
+ :capistrano_2
15
+ end
16
+
17
+ def version
18
+ present? ? Capistrano::VERSION : nil
19
+ end
20
+
21
+ def present?
22
+ if !@cap.nil? && @cap.is_a?(Capistrano::Configuration)
23
+ require 'capistrano/version'
24
+ defined?(Capistrano::VERSION) && Gem::Dependency.new('', '~> 2.0').match?('', Capistrano::VERSION.to_s)
25
+ else
26
+ return false
27
+ end
28
+ return true
29
+ rescue
30
+ return false
31
+ end
32
+
33
+ def install
34
+ logger.debug "Initializing Capistrano2 Deploy Integration."
35
+ @cap.load File.expand_path("../capistrano_2.cap", __FILE__)
36
+ end
37
+
38
+ def root
39
+ '.'
40
+ end
41
+
42
+ def env
43
+ @cap.fetch(:stage)
44
+ end
45
+
46
+ def found?
47
+ true
48
+ end
49
+
50
+ def report
51
+ if reporter.can_report?
52
+ data = deploy_data
53
+ logger.debug "Sending deploy hook data: #{data}"
54
+ payload = ScoutApm::Serializers::DeploySerializer.serialize(data)
55
+ reporter.report(payload, ScoutApm::Serializers::DeploySerializer::HTTP_HEADERS)
56
+ else
57
+ logger.warn "Unable to post deploy hook data"
58
+ end
59
+ end
60
+
61
+ def reporter
62
+ @reporter ||= ScoutApm::Reporter.new(:deploy_hook, ScoutApm::Agent.instance.config, @logger)
63
+ end
64
+
65
+ def deploy_data
66
+ {:revision => current_revision, :branch => branch, :deployed_by => deployed_by}
67
+ end
68
+
69
+ def branch
70
+ @cap.fetch(:branch)
71
+ end
72
+
73
+ def current_revision
74
+ @cap.fetch(:current_revision) || `git rev-list --max-count=1 --abbrev-commit --abbrev=12 #{branch}`.chomp
75
+ end
76
+
77
+ def deployed_by
78
+ ScoutApm::Agent.instance.config.value('deployed_by')
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,12 @@
1
+ namespace :scout_apm do
2
+ namespace :deploy do
3
+ task :starting do
4
+ # Warn if missing scout apm deploy creds?
5
+ end
6
+ task :finished do
7
+ ScoutApm::Agent.instance.deploy_integration.report
8
+ end
9
+ end
10
+ end
11
+
12
+ after 'deploy:finished', 'scout_apm:deploy:finished'
@@ -0,0 +1,88 @@
1
+ require 'scout_apm'
2
+
3
+ module ScoutApm
4
+ module DeployIntegrations
5
+ class Capistrano3
6
+ attr_reader :logger
7
+
8
+ def initialize(logger)
9
+ @logger = logger
10
+ @cap = Rake.application rescue nil
11
+ end
12
+
13
+ def name
14
+ :capistrano_3
15
+ end
16
+
17
+ def version
18
+ present? ? Capistrano::VERSION : nil
19
+ end
20
+
21
+ def present?
22
+ if !@cap.nil? && @cap.is_a?(Capistrano::Application)
23
+ require 'capistrano/version'
24
+ defined?(Capistrano::VERSION) && Gem::Dependency.new('', '~> 3.0').match?('', Capistrano::VERSION.to_s)
25
+ else
26
+ return false
27
+ end
28
+ rescue
29
+ return false
30
+ end
31
+
32
+ def install
33
+ logger.debug "Initializing Capistrano3 Deploy Integration."
34
+ load File.expand_path("../capistrano_3.cap", __FILE__)
35
+ end
36
+
37
+ def root
38
+ '.'
39
+ end
40
+
41
+ def env
42
+ @cap.fetch(:stage).to_s
43
+ end
44
+
45
+ def found?
46
+ true
47
+ end
48
+
49
+ def report
50
+ if reporter.can_report?
51
+ data = deploy_data
52
+ logger.debug "Sending deploy hook data: #{data}"
53
+ payload = ScoutApm::Serializers::DeploySerializer.serialize(data)
54
+ reporter.report(payload, ScoutApm::Serializers::DeploySerializer::HTTP_HEADERS)
55
+ else
56
+ logger.warn "Unable to post deploy hook data"
57
+ end
58
+ end
59
+
60
+ def reporter
61
+ config = if env == ''
62
+ ScoutApm::Agent.instance.config
63
+ else
64
+ ScoutApm::Config.with_file(nil, {:file => { :environment => env }}) # instantiate our own config, with an overridden environment for the deploy-to app name instead of deploy-from app name)
65
+ end
66
+
67
+ @reporter ||= ScoutApm::Reporter.new(:deploy_hook, config, @logger)
68
+ end
69
+
70
+ def deploy_data
71
+ {:revision => current_revision, :branch => branch, :deployed_by => deployed_by}
72
+ end
73
+
74
+ def branch
75
+ @cap.fetch(:branch)
76
+ end
77
+
78
+ def current_revision
79
+ @cap.fetch(:current_revision) || `git rev-list --max-count=1 --abbrev-commit --abbrev=12 #{branch}`.chomp
80
+ end
81
+
82
+ def deployed_by
83
+ ScoutApm::Agent.instance.config.value('deployed_by')
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -24,12 +24,8 @@ module ScoutApm
24
24
  ]
25
25
 
26
26
  BACKGROUND_JOB_INTEGRATIONS = [
27
- ScoutApm::BackgroundJobIntegrations::Resque.new,
28
27
  ScoutApm::BackgroundJobIntegrations::Sidekiq.new,
29
- ScoutApm::BackgroundJobIntegrations::Shoryuken.new,
30
- ScoutApm::BackgroundJobIntegrations::Sneakers.new,
31
- ScoutApm::BackgroundJobIntegrations::DelayedJob.new,
32
- ScoutApm::BackgroundJobIntegrations::Que.new,
28
+ # ScoutApm::BackgroundJobIntegrations::DelayedJob.new
33
29
  ]
34
30
 
35
31
  FRAMEWORK_INTEGRATIONS = [
@@ -45,8 +41,13 @@ module ScoutApm
45
41
  ScoutApm::PlatformIntegrations::Server.new,
46
42
  ]
47
43
 
44
+ DEPLOY_INTEGRATIONS = [
45
+ ScoutApm::DeployIntegrations::Capistrano3.new(STDOUT_LOGGER),
46
+ # ScoutApm::DeployIntegrations::Capistrano2.new(STDOUT_LOGGER),
47
+ ]
48
+
48
49
  def env
49
- @env ||= framework_integration.env
50
+ @env ||= deploy_integration? ? deploy_integration.env : framework_integration.env
50
51
  end
51
52
 
52
53
  def framework
@@ -62,9 +63,7 @@ module ScoutApm
62
63
  end
63
64
 
64
65
  def application_name
65
- Agent.instance.context.config.value("name") ||
66
- framework_integration.application_name ||
67
- "App"
66
+ Agent.instance.config.value("name") || framework_integration.application_name
68
67
  end
69
68
 
70
69
  def database_engine
@@ -88,20 +87,12 @@ module ScoutApm
88
87
  end
89
88
  end
90
89
 
91
- def scm_subdirectory
92
- @scm_subdirectory ||= if Agent.instance.context.config.value('scm_subdirectory').empty?
93
- ''
94
- else
95
- Agent.instance.context.config.value('scm_subdirectory').sub(/^\//, '') # Trim any leading slash
96
- end
97
- end
98
-
99
90
  def root
100
- @root ||= framework_root
91
+ @root ||= deploy_integration? ? deploy_integration.root : framework_root
101
92
  end
102
93
 
103
94
  def framework_root
104
- if override_root = Agent.instance.context.config.value("application_root")
95
+ if override_root = Agent.instance.config.value("application_root")
105
96
  return override_root
106
97
  end
107
98
  if framework == :rails
@@ -116,11 +107,7 @@ module ScoutApm
116
107
  end
117
108
 
118
109
  def hostname
119
- @hostname ||= Agent.instance.context.config.value("hostname") || platform_integration.hostname
120
- end
121
-
122
- def git_revision
123
- @git_revision ||= ScoutApm::GitRevision.new(Agent.instance.context)
110
+ @hostname ||= Agent.instance.config.value("hostname") || platform_integration.hostname
124
111
  end
125
112
 
126
113
  # Returns the whole integration object
@@ -144,17 +131,24 @@ module ScoutApm
144
131
  app_server_integration.forking? || (background_job_integration && background_job_integration.forking?)
145
132
  end
146
133
 
147
- def background_job_integrations
148
- if Agent.instance.context.config.value("enable_background_jobs")
149
- @background_job_integrations ||= BACKGROUND_JOB_INTEGRATIONS.select {|integration| integration.present?}
134
+ def background_job_integration
135
+ if Agent.instance.config.value("enable_background_jobs")
136
+ @background_job_integration ||= BACKGROUND_JOB_INTEGRATIONS.detect {|integration| integration.present?}
150
137
  else
151
- []
138
+ nil
152
139
  end
153
140
  end
154
141
 
155
- # If both stdin & stdout are interactive and the Rails::Console constant is defined
156
- def interactive?
157
- defined?(::Rails::Console) && $stdout.isatty && $stdin.isatty
142
+ def background_job_name
143
+ background_job_integration && background_job_integration.name
144
+ end
145
+
146
+ def deploy_integration
147
+ @deploy_integration ||= DEPLOY_INTEGRATIONS.detect{ |integration| integration.present? }
148
+ end
149
+
150
+ def deploy_integration?
151
+ !@deploy_integration.nil?
158
152
  end
159
153
 
160
154
  ### ruby checks
@@ -168,23 +162,15 @@ module ScoutApm
168
162
  end
169
163
 
170
164
  def ruby_19?
171
- return @ruby_19 if defined?(@ruby_19)
172
- @ruby_19 = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/)
165
+ @ruby_19 ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/)
173
166
  end
174
167
 
175
168
  def ruby_187?
176
- return @ruby_187 if defined?(@ruby_187)
177
- @ruby_187 = defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/)
169
+ @ruby_187 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/)
178
170
  end
179
171
 
180
172
  def ruby_2?
181
- return @ruby_2 if defined?(@ruby_2)
182
- @ruby_2 = defined?(RUBY_VERSION) && RUBY_VERSION.match(/^2/)
183
- end
184
-
185
- # Returns true if this Ruby version supports Module#prepend.
186
- def supports_module_prepend?
187
- ruby_2?
173
+ @ruby_2 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^2/)
188
174
  end
189
175
 
190
176
  # Returns a string representation of the OS (ex: darwin, linux)
@@ -17,15 +17,6 @@ module ScoutApm
17
17
  def track_one!(type, name, value, options={})
18
18
  end
19
19
 
20
- def track_trace!(trace, type)
21
- end
22
-
23
- def track_histograms!(histograms, options={})
24
- end
25
-
26
- def track_db_query_metrics!(db_query_metric_set, options={})
27
- end
28
-
29
20
  def track_slow_transaction!(slow_transaction)
30
21
  end
31
22
 
@@ -40,8 +31,5 @@ module ScoutApm
40
31
 
41
32
  def add_sampler(sampler)
42
33
  end
43
-
44
- def tick!
45
- end
46
34
  end
47
35
  end
@@ -15,8 +15,7 @@ module ScoutApm
15
15
 
16
16
  def present?
17
17
  defined?(::Rails) &&
18
- defined?(::Rails::VERSION) &&
19
- defined?(ActionController) &&
18
+ defined?(ActionController) &&
20
19
  Rails::VERSION::MAJOR < 3
21
20
  end
22
21
 
@@ -15,8 +15,7 @@ module ScoutApm
15
15
 
16
16
  def present?
17
17
  defined?(::Rails) &&
18
- defined?(::Rails::VERSION) &&
19
- defined?(ActionController) &&
18
+ defined?(ActionController) &&
20
19
  Rails::VERSION::MAJOR >= 3
21
20
  end
22
21
 
@@ -48,7 +47,6 @@ module ScoutApm
48
47
  when "sqlite" then :sqlite
49
48
  when "mysql" then :mysql
50
49
  when "mysql2" then :mysql
51
- when "sqlserver" then :sqlserver
52
50
  else default
53
51
  end
54
52
  else
@@ -57,21 +55,12 @@ module ScoutApm
57
55
  end
58
56
  end
59
57
 
60
- # Note, this code intentionally avoids `.respond_to?` because of an
61
- # infinite loop created by the Textacular gem (tested against 3.2.2 of
62
- # that gem), which some customers have installed.
63
- #
64
- # The loop was:
65
- # - Ask for database adapter
66
- # - Do .respond_to? on AR::Base to look for connection_config (which isn't present on some versions of rails)
67
- # - Textacular gem has a monkey-patch that queries the columns of the db
68
- # This obtains a connection, and runs a query.
69
- # - Scout tries to run SQLSanitizer against the query, which needs the database adapter.
70
- # - Goes back to first step.
71
- #
72
- # We avoid this issue by not calling .respond_to? here, and instead using the less optimal `rescue nil` approach
73
58
  def raw_database_adapter
74
- adapter = ActiveRecord::Base.connection_config[:adapter].to_s rescue nil
59
+ adapter = if ActiveRecord::Base.respond_to?(:connection_config)
60
+ ActiveRecord::Base.connection_config[:adapter].to_s
61
+ else
62
+ nil
63
+ end
75
64
 
76
65
  if adapter.nil?
77
66
  adapter = ActiveRecord::Base.configurations[env]["adapter"]
@@ -25,7 +25,7 @@ module ScoutApm
25
25
  "Sinatra"
26
26
  end
27
27
  rescue => e
28
- ScoutApm::Agent.instance.context.logger.debug "Failed getting Sinatra Application Name: #{e.message}\n#{e.backtrace.join("\n\t")}"
28
+ ScoutApm::Agent.instance.logger.debug "Failed getting Sinatra Application Name: #{e.message}\n#{e.backtrace.join("\n\t")}"
29
29
  "Sinatra"
30
30
  end
31
31
 
@@ -90,11 +90,7 @@ module ScoutApm
90
90
  def combine!(other)
91
91
  mutex.synchronize do
92
92
  other.mutex.synchronize do
93
- @bins = (other.bins + @bins).
94
- group_by {|b| b.value }.
95
- map {|val, bs| [val, bs.inject(0) {|sum, b| sum + b.count }] }.
96
- map {|val, sum| HistogramBin.new(val,sum) }.
97
- sort_by { |b| b.value }
93
+ @bins = (other.bins + @bins).sort_by {|b| b.value }
98
94
  @total += other.total
99
95
  trim
100
96
  self
@@ -104,12 +100,7 @@ module ScoutApm
104
100
 
105
101
  def as_json
106
102
  mutex.synchronize do
107
- bins.map{ |b|
108
- [
109
- ScoutApm::Utils::Numbers.round(b.value, 4),
110
- b.count
111
- ]
112
- }
103
+ bins.map{|b| [b.value, b.count]}
113
104
  end
114
105
  end
115
106
 
@@ -171,7 +162,7 @@ module ScoutApm
171
162
  bins.slice!(minDeltaIndex - 1, 2)
172
163
  bins.insert(minDeltaIndex - 1, mergedBin)
173
164
  rescue => e
174
- ScoutApm::Agent.instance.context.logger.info("Error in NumericHistogram#trim_one. #{e.message}, #{e.backtrace}, #{self.inspect}")
165
+ ScoutApm::Agent.instance.logger.info("Error in NumericHistogram#trim_one. #{e.message}, #{e.backtrace}, #{self.inspect}")
175
166
  raise
176
167
  end
177
168
  end
@@ -3,7 +3,7 @@
3
3
  (function(){var open=window.XMLHttpRequest.prototype.open;var send=window.XMLHttpRequest.prototype.send;function openReplacement(method,url,async,user,password){this._url=url;return open.apply(this,arguments);}
4
4
  function sendReplacement(data){if(this.onload){this._onload=this.onload;}
5
5
  this.onload=onLoadReplacement;return send.apply(this,arguments);}
6
- function onLoadReplacement(){if(this._url.startsWith(window.location.protocol+"//"+window.location.host)||!this._url.startsWith("http")){try{var traceText=this.getResponseHeader("X-scoutapminstant");if(traceText){setTimeout(function(){window.scoutInstant("addTrace",traceText)},0);}}catch(e){console.debug("Problem getting X-scoutapminstant header");}}
6
+ function onLoadReplacement(){if(this._url.startsWith(window.location.protocol+"//"+window.location.host)||!this._url.startsWith("http")){try{traceText=this.getResponseHeader("X-scoutapminstant");if(traceText){setTimeout(function(){window.scoutInstant("addTrace",traceText)},0);}}catch(e){console.debug("Problem getting X-scoutapminstant header");}}
7
7
  if(this._onload){return this._onload.apply(this,arguments);}}
8
8
  window.XMLHttpRequest.prototype.open=openReplacement;window.XMLHttpRequest.prototype.send=sendReplacement;})();
9
- </script>
9
+ </script>