scout_apm 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6e3fc97dff8ae1961d76b52394b1352d0b9ed37
4
- data.tar.gz: ec255a3987a94f40a009bb152f07cbc00a6763cc
3
+ metadata.gz: 99bbe7dc8f3e03137118c997250a4ddc41f9889c
4
+ data.tar.gz: 3f7305a88ee28e41392d1c30fa182b879d94c95c
5
5
  SHA512:
6
- metadata.gz: 5d5b03e83afd811e9cf3a9569affdac111e98d78e2668c86bd0ed7cdbca9853e667392f4cb4d6e5820ee9bb3d9841799f9098988dc47e05698f4be87e3d02f52
7
- data.tar.gz: 01605ef204077472adec76c6607cecc0d50263faf8ee2b00550d85386b78bda4d2ab5a9edd548b9a2adf97ee2ec8547597e024e0713336bf9ab30d1a75cebc34
6
+ metadata.gz: e4b44b8e106be2167bd52ed3c405e201c098a4b8b5027afab3dc6a0b51e04f259b8378faa94908d063f234ed3d7dc742dbd05b114614ff77b85c5de7cf35f52a
7
+ data.tar.gz: bd9ce3b704d0c25ca02409981784420738d223018d55368d19c810c9b498d3caf708e4f66267445b3f30a56095090f5f1716fd497f27e18970e9190ae28c6b00
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.2.11
2
+
3
+ * Summarizing middleware instrumentation into a single metric for lower overhead.
4
+ * If monitoring isn't enabled:
5
+ * In ScoutApm::Middleware, don't start the agent
6
+ * Don't start background worker
7
+
1
8
  # 1.2.10
2
9
 
3
10
  * Improve exit handler. It wasn't being run during shutdown in some cases.
@@ -202,6 +202,10 @@ module ScoutApm
202
202
  # Creates the worker thread. The worker thread is a loop that runs continuously. It sleeps for +Agent#period+ and when it wakes,
203
203
  # processes data, either saving it to disk or reporting to Scout.
204
204
  def start_background_worker
205
+ if !apm_enabled?
206
+ logger.debug "Not starting background worker as monitoring isn't enabled."
207
+ return false
208
+ end
205
209
  logger.info "Not starting background worker, already started" and return if background_worker_running?
206
210
  logger.info "Initializing worker thread."
207
211
 
@@ -238,7 +242,7 @@ module ScoutApm
238
242
  when :rails then install_instrument(ScoutApm::Instruments::ActionControllerRails2)
239
243
  when :rails3_or_4 then
240
244
  install_instrument(ScoutApm::Instruments::ActionControllerRails3Rails4)
241
- install_instrument(ScoutApm::Instruments::Middleware)
245
+ install_instrument(ScoutApm::Instruments::MiddlewareSummary)
242
246
  install_instrument(ScoutApm::Instruments::RailsRouter)
243
247
  when :sinatra then install_instrument(ScoutApm::Instruments::Sinatra)
244
248
  end
@@ -1,6 +1,16 @@
1
+ # Inserts a new middleware between each actual middleware in the application,
2
+ # so as to trace the time for each one.
3
+ #
4
+ # Currently disabled due to the overhead of this approach (~10-15ms per request
5
+ # in practice). Instead, middleware as a whole are instrumented via the
6
+ # MiddlewareSummary class.
7
+ #
8
+ # There will likely be a configuration flag to turn this on in favor of the
9
+ # summary tracing in a future version of the agent, but this is not yet
10
+ # implemented.
1
11
  module ScoutApm
2
12
  module Instruments
3
- class Middleware
13
+ class MiddlewareDetailed
4
14
  def initalize(logger=ScoutApm::Agent.instance.logger)
5
15
  @logger = logger
6
16
  @installed = false
@@ -0,0 +1,51 @@
1
+ # Inserts a single middleware at the outer edge of the stack (the first
2
+ # middleware called, before passing to the rest of the stack) to trace the
3
+ # total time spent between all middlewares. This instrument does not attempt to
4
+ # allocate time to specific middlewares. (see MiddlewareDetailed)
5
+ #
6
+ module ScoutApm
7
+ module Instruments
8
+ class MiddlewareSummary
9
+ def initalize(logger=ScoutApm::Agent.instance.logger)
10
+ @logger = logger
11
+ @installed = false
12
+ end
13
+
14
+ def installed?
15
+ @installed
16
+ end
17
+
18
+ def install
19
+ @installed = true
20
+
21
+ if defined?(ActionDispatch) && defined?(ActionDispatch::MiddlewareStack)
22
+ ScoutApm::Agent.instance.logger.info("Instrumenting Middleware")
23
+ ActionDispatch::MiddlewareStack.class_eval do
24
+ def build_with_scout_instruments(app = nil, &block)
25
+ mw_stack = build_without_scout_instruments(app) { block.call if block }
26
+ MiddlewareSummaryWrapper.new(mw_stack)
27
+ end
28
+
29
+ alias_method :build_without_scout_instruments, :build
30
+ alias_method :build, :build_with_scout_instruments
31
+ end
32
+ end
33
+ end
34
+
35
+ class MiddlewareSummaryWrapper
36
+ def initialize(app)
37
+ @app = app
38
+ end
39
+
40
+ def call(env)
41
+ req = ScoutApm::RequestManager.lookup
42
+ layer = ScoutApm::Layer.new("Middleware", "Summary")
43
+ req.start_layer(layer)
44
+ @app.call(env)
45
+ ensure
46
+ req.stop_layer
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -159,14 +159,12 @@ module ScoutApm
159
159
  end
160
160
 
161
161
  # Specific Metric
162
- if record_specific_metric?(layer.type)
163
- meta_options.merge!(:desc => layer.desc) if layer.desc
164
- meta = MetricMeta.new(layer.legacy_metric_name, meta_options)
165
- meta.extra.merge!(:backtrace => ScoutApm::SlowTransaction.backtrace_parser(layer.backtrace)) if layer.backtrace
166
- metric_hash[meta] ||= MetricStats.new( meta_options.has_key?(:scope) )
167
- stat = metric_hash[meta]
168
- stat.update!(layer.total_call_time, layer.total_exclusive_time)
169
- end
162
+ meta_options.merge!(:desc => layer.desc) if layer.desc
163
+ meta = MetricMeta.new(layer.legacy_metric_name, meta_options)
164
+ meta.extra.merge!(:backtrace => ScoutApm::SlowTransaction.backtrace_parser(layer.backtrace)) if layer.backtrace
165
+ metric_hash[meta] ||= MetricStats.new( meta_options.has_key?(:scope) )
166
+ stat = metric_hash[meta]
167
+ stat.update!(layer.total_call_time, layer.total_exclusive_time)
170
168
 
171
169
  # Merged Metric (no specifics, just sum up by type)
172
170
  meta = MetricMeta.new("#{layer.type}/all")
@@ -177,13 +175,6 @@ module ScoutApm
177
175
 
178
176
  metric_hash
179
177
  end
180
-
181
- SKIP_SPECIFICS = ["Middleware"]
182
- # For metrics that are known to be of sort duration (Middleware right now), we don't record specifics on each call to eliminate a metric explosion.
183
- # There can be many Middlewares in an app.
184
- def record_specific_metric?(name)
185
- !SKIP_SPECIFICS.include?(name)
186
- end
187
178
  end
188
179
 
189
180
  class LayerDepthFirstWalker
@@ -202,6 +193,13 @@ module ScoutApm
202
193
  end
203
194
 
204
195
  def walk(layer=root_layer, &block)
196
+ # Need to run this for the root layer the first time through.
197
+ if layer == root_layer
198
+ @before_block.call(layer) if @before_block
199
+ yield layer
200
+ @after_block.call(layer) if @after_block
201
+ end
202
+
205
203
  layer.children.each do |child|
206
204
  @before_block.call(child) if @before_block
207
205
  yield child
@@ -5,12 +5,13 @@ module ScoutApm
5
5
  def initialize(app)
6
6
  @app = app
7
7
  @attempts = 0
8
+ @enabled = ScoutApm::Agent.instance.apm_enabled?
8
9
  @started = ScoutApm::Agent.instance.started? && ScoutApm::Agent.instance.background_worker_running?
9
10
  end
10
11
 
11
12
  # If we get a web request in, then we know we're running in some sort of app server
12
13
  def call(env)
13
- if @started || @attempts > MAX_ATTEMPTS
14
+ if !@enabled || @started || @attempts > MAX_ATTEMPTS
14
15
  @app.call(env)
15
16
  else
16
17
  attempt_to_start_agent
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "1.2.10"
2
+ VERSION = "1.2.11"
3
3
  end
4
4
 
data/lib/scout_apm.rb CHANGED
@@ -65,7 +65,8 @@ require 'scout_apm/instruments/delayed_job'
65
65
  require 'scout_apm/instruments/active_record'
66
66
  require 'scout_apm/instruments/action_controller_rails_2'
67
67
  require 'scout_apm/instruments/action_controller_rails_3_rails4'
68
- require 'scout_apm/instruments/middleware'
68
+ require 'scout_apm/instruments/middleware_summary'
69
+ # require 'scout_apm/instruments/middleware_detailed' # Currently disabled functionality, see the file for details.
69
70
  require 'scout_apm/instruments/rails_router'
70
71
  require 'scout_apm/instruments/sinatra'
71
72
  require 'scout_apm/instruments/process/process_cpu'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-20 00:00:00.000000000 Z
12
+ date: 2016-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -92,7 +92,8 @@ files:
92
92
  - lib/scout_apm/instruments/action_controller_rails_3_rails4.rb
93
93
  - lib/scout_apm/instruments/active_record.rb
94
94
  - lib/scout_apm/instruments/delayed_job.rb
95
- - lib/scout_apm/instruments/middleware.rb
95
+ - lib/scout_apm/instruments/middleware_detailed.rb
96
+ - lib/scout_apm/instruments/middleware_summary.rb
96
97
  - lib/scout_apm/instruments/mongoid.rb
97
98
  - lib/scout_apm/instruments/moped.rb
98
99
  - lib/scout_apm/instruments/net_http.rb
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  version: '0'
176
177
  requirements: []
177
178
  rubyforge_project: scout_apm
178
- rubygems_version: 2.2.2
179
+ rubygems_version: 2.4.6
179
180
  signing_key:
180
181
  specification_version: 4
181
182
  summary: Ruby application performance monitoring
@@ -191,3 +192,4 @@ test_files:
191
192
  - test/unit/slow_transaction_set_test.rb
192
193
  - test/unit/sql_sanitizer_test.rb
193
194
  - test/unit/utils/active_record_metric_name_test.rb
195
+ has_rdoc: