scout_apm 3.0.0.pre25 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +49 -0
  3. data/.gitignore +1 -1
  4. data/.rubocop.yml +5 -5
  5. data/.travis.yml +19 -14
  6. data/CHANGELOG.markdown +148 -4
  7. data/Gemfile +1 -7
  8. data/README.markdown +30 -4
  9. data/Rakefile +1 -1
  10. data/ext/allocations/allocations.c +2 -0
  11. data/gems/README.md +28 -0
  12. data/gems/octoshark.gemfile +4 -0
  13. data/gems/rails3.gemfile +5 -0
  14. data/gems/rails4.gemfile +4 -0
  15. data/gems/rails5.gemfile +4 -0
  16. data/gems/rails6.gemfile +4 -0
  17. data/lib/scout_apm.rb +38 -9
  18. data/lib/scout_apm/agent.rb +29 -10
  19. data/lib/scout_apm/agent/exit_handler.rb +0 -1
  20. data/lib/scout_apm/agent_context.rb +22 -3
  21. data/lib/scout_apm/app_server_load.rb +7 -2
  22. data/lib/scout_apm/attribute_arranger.rb +0 -2
  23. data/lib/scout_apm/auto_instrument.rb +5 -0
  24. data/lib/scout_apm/auto_instrument/instruction_sequence.rb +31 -0
  25. data/lib/scout_apm/auto_instrument/layer.rb +23 -0
  26. data/lib/scout_apm/auto_instrument/parser.rb +27 -0
  27. data/lib/scout_apm/auto_instrument/rails.rb +175 -0
  28. data/lib/scout_apm/background_job_integrations/legacy_sneakers.rb +55 -0
  29. data/lib/scout_apm/background_job_integrations/que.rb +134 -0
  30. data/lib/scout_apm/background_job_integrations/resque.rb +6 -2
  31. data/lib/scout_apm/background_job_integrations/shoryuken.rb +124 -0
  32. data/lib/scout_apm/background_job_integrations/sidekiq.rb +5 -19
  33. data/lib/scout_apm/background_job_integrations/sneakers.rb +87 -0
  34. data/lib/scout_apm/config.rb +45 -8
  35. data/lib/scout_apm/detailed_trace.rb +217 -0
  36. data/lib/scout_apm/environment.rb +19 -1
  37. data/lib/scout_apm/error.rb +27 -0
  38. data/lib/scout_apm/error_service.rb +32 -0
  39. data/lib/scout_apm/error_service/error_buffer.rb +39 -0
  40. data/lib/scout_apm/error_service/error_record.rb +211 -0
  41. data/lib/scout_apm/error_service/ignored_exceptions.rb +66 -0
  42. data/lib/scout_apm/error_service/middleware.rb +32 -0
  43. data/lib/scout_apm/error_service/notifier.rb +33 -0
  44. data/lib/scout_apm/error_service/payload.rb +47 -0
  45. data/lib/scout_apm/error_service/periodic_work.rb +17 -0
  46. data/lib/scout_apm/error_service/railtie.rb +11 -0
  47. data/lib/scout_apm/error_service/sidekiq.rb +80 -0
  48. data/lib/scout_apm/extensions/transaction_callback_payload.rb +1 -1
  49. data/lib/scout_apm/fake_store.rb +3 -0
  50. data/lib/scout_apm/framework_integrations/rails_2.rb +2 -1
  51. data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +17 -6
  52. data/lib/scout_apm/git_revision.rb +6 -3
  53. data/lib/scout_apm/instant/middleware.rb +2 -1
  54. data/lib/scout_apm/instrument_manager.rb +8 -7
  55. data/lib/scout_apm/instruments/action_controller_rails_2.rb +3 -1
  56. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +56 -55
  57. data/lib/scout_apm/instruments/action_view.rb +126 -26
  58. data/lib/scout_apm/instruments/active_record.rb +70 -19
  59. data/lib/scout_apm/instruments/http.rb +48 -0
  60. data/lib/scout_apm/instruments/memcached.rb +43 -0
  61. data/lib/scout_apm/instruments/mongoid.rb +9 -4
  62. data/lib/scout_apm/instruments/net_http.rb +8 -1
  63. data/lib/scout_apm/job_record.rb +4 -2
  64. data/lib/scout_apm/layaway_file.rb +4 -0
  65. data/lib/scout_apm/layer.rb +6 -57
  66. data/lib/scout_apm/layer_children_set.rb +15 -6
  67. data/lib/scout_apm/layer_converters/converter_base.rb +15 -30
  68. data/lib/scout_apm/layer_converters/database_converter.rb +2 -15
  69. data/lib/scout_apm/layer_converters/slow_job_converter.rb +12 -2
  70. data/lib/scout_apm/layer_converters/slow_request_converter.rb +14 -4
  71. data/lib/scout_apm/layer_converters/trace_converter.rb +184 -0
  72. data/lib/scout_apm/limited_layer.rb +0 -7
  73. data/lib/scout_apm/metric_stats.rb +0 -8
  74. data/lib/scout_apm/middleware.rb +1 -1
  75. data/lib/scout_apm/periodic_work.rb +19 -0
  76. data/lib/scout_apm/remote/message.rb +4 -0
  77. data/lib/scout_apm/remote/server.rb +13 -1
  78. data/lib/scout_apm/reporter.rb +8 -3
  79. data/lib/scout_apm/reporting.rb +2 -1
  80. data/lib/scout_apm/request_histograms.rb +8 -0
  81. data/lib/scout_apm/serializers/app_server_load_serializer.rb +4 -0
  82. data/lib/scout_apm/serializers/directive_serializer.rb +4 -0
  83. data/lib/scout_apm/serializers/payload_serializer.rb +2 -2
  84. data/lib/scout_apm/serializers/payload_serializer_to_json.rb +30 -15
  85. data/lib/scout_apm/slow_job_record.rb +5 -1
  86. data/lib/scout_apm/slow_policy/age_policy.rb +33 -0
  87. data/lib/scout_apm/slow_policy/percent_policy.rb +22 -0
  88. data/lib/scout_apm/slow_policy/percentile_policy.rb +24 -0
  89. data/lib/scout_apm/slow_policy/policy.rb +21 -0
  90. data/lib/scout_apm/slow_policy/speed_policy.rb +16 -0
  91. data/lib/scout_apm/slow_request_policy.rb +18 -77
  92. data/lib/scout_apm/slow_transaction.rb +3 -1
  93. data/lib/scout_apm/store.rb +12 -8
  94. data/lib/scout_apm/tracked_request.rb +39 -30
  95. data/lib/scout_apm/utils/active_record_metric_name.rb +16 -3
  96. data/lib/scout_apm/utils/backtrace_parser.rb +3 -0
  97. data/lib/scout_apm/utils/marshal_logging.rb +90 -0
  98. data/lib/scout_apm/utils/sql_sanitizer.rb +10 -1
  99. data/lib/scout_apm/utils/sql_sanitizer_regex.rb +8 -1
  100. data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +6 -0
  101. data/lib/scout_apm/utils/unique_id.rb +27 -0
  102. data/lib/scout_apm/version.rb +1 -1
  103. data/scout_apm.gemspec +13 -7
  104. data/test/test_helper.rb +2 -2
  105. data/test/unit/agent_context_test.rb +29 -0
  106. data/test/unit/auto_instrument/assignments-instrumented.rb +31 -0
  107. data/test/unit/auto_instrument/assignments.rb +31 -0
  108. data/test/unit/auto_instrument/controller-ast.txt +57 -0
  109. data/test/unit/auto_instrument/controller-instrumented.rb +49 -0
  110. data/test/unit/auto_instrument/controller.rb +49 -0
  111. data/test/unit/auto_instrument/rescue_from-instrumented.rb +13 -0
  112. data/test/unit/auto_instrument/rescue_from.rb +13 -0
  113. data/test/unit/auto_instrument_test.rb +54 -0
  114. data/test/unit/environment_test.rb +2 -2
  115. data/test/unit/error_service/error_buffer_test.rb +25 -0
  116. data/test/unit/error_service/ignored_exceptions_test.rb +49 -0
  117. data/test/unit/instruments/active_record_test.rb +40 -0
  118. data/test/unit/layer_children_set_test.rb +9 -0
  119. data/test/unit/request_histograms_test.rb +17 -0
  120. data/test/unit/serializers/payload_serializer_test.rb +39 -5
  121. data/test/unit/slow_request_policy_test.rb +41 -13
  122. data/test/unit/sql_sanitizer_test.rb +78 -0
  123. data/test/unit/utils/active_record_metric_name_test.rb +10 -2
  124. metadata +100 -63
  125. data/ext/stacks/extconf.rb +0 -37
  126. data/ext/stacks/scout_atomics.h +0 -86
  127. data/ext/stacks/stacks.c +0 -814
  128. data/lib/scout_apm/slow_job_policy.rb +0 -111
  129. data/lib/scout_apm/trace_compactor.rb +0 -312
  130. data/lib/scout_apm/utils/fake_stacks.rb +0 -88
  131. data/test/unit/instruments/active_record_instruments_test.rb +0 -5
  132. data/test/unit/slow_job_policy_test.rb +0 -6
  133. data/tester.rb +0 -53
@@ -82,10 +82,8 @@ module ScoutApm
82
82
 
83
83
  # Install #log tracing
84
84
  if Utils::KlassHelper.defined?("ActiveRecord::ConnectionAdapters::AbstractAdapter")
85
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
86
- include ::ScoutApm::Instruments::ActiveRecordInstruments
87
- include ::ScoutApm::Tracer
88
- end
85
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecordInstruments)
86
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.include(Tracer)
89
87
  end
90
88
 
91
89
  if Utils::KlassHelper.defined?("ActiveRecord::Base")
@@ -142,7 +140,10 @@ module ScoutApm
142
140
  req = ScoutApm::RequestManager.lookup
143
141
  layer = req.current_layer
144
142
  if layer && layer.type == "ActiveRecord"
145
- layer.annotate_layer(payload)
143
+ layer.annotate_layer({
144
+ :class_name => payload[:class_name],
145
+ :record_count => payload[:record_count]
146
+ })
146
147
  elsif layer
147
148
  logger.debug("Expected layer type: ActiveRecord, got #{layer && layer.type}")
148
149
  else
@@ -165,17 +166,63 @@ module ScoutApm
165
166
  #
166
167
  ################################################################################
167
168
  module ActiveRecordInstruments
168
- def self.included(instrumented_class)
169
+ def self.prepended(instrumented_class)
169
170
  ScoutApm::Agent.instance.context.logger.info "Instrumenting #{instrumented_class.inspect}"
170
- instrumented_class.class_eval do
171
- unless instrumented_class.method_defined?(:log_without_scout_instruments)
172
- alias_method :log_without_scout_instruments, :log
173
- alias_method :log, :log_with_scout_instruments
171
+ end
172
+
173
+ def log(*args, &block)
174
+ # Extract data from the arguments
175
+ sql, name = args
176
+ metric_name = Utils::ActiveRecordMetricName.new(sql, name)
177
+ desc = SqlList.new(sql)
178
+
179
+ # Get current ScoutApm context
180
+ req = ScoutApm::RequestManager.lookup
181
+ current_layer = req.current_layer
182
+
183
+ # If we call #log, we have a real query to run, and we've already
184
+ # gotten through the cache gatekeeper. Since we want to only trace real
185
+ # queries, and not repeated identical queries that just hit cache, we
186
+ # mark layer as ignorable initially in #find_by_sql, then only when we
187
+ # know it's a real database call do we mark it back as usable.
188
+ #
189
+ # This flag is later used in SlowRequestConverter to skip adding ignorable layers
190
+ current_layer.annotate_layer(:ignorable => false) if current_layer
191
+
192
+ # Either: update the current layer and yield, don't start a new one.
193
+ if current_layer && current_layer.type == "ActiveRecord"
194
+ # TODO: Get rid of call .to_s, need to find this without forcing a previous run of the name logic
195
+ if current_layer.name.to_s == Utils::ActiveRecordMetricName::DEFAULT_METRIC
196
+ current_layer.name = metric_name
197
+ end
198
+
199
+ if current_layer.desc.nil?
200
+ current_layer.desc = SqlList.new
201
+ end
202
+ current_layer.desc.merge(desc)
203
+
204
+ super(*args, &block)
205
+
206
+ # OR: Start a new layer, we didn't pick up instrumentation earlier in the stack.
207
+ else
208
+ layer = ScoutApm::Layer.new("ActiveRecord", metric_name)
209
+ layer.desc = desc
210
+ req.start_layer(layer)
211
+ begin
212
+ super(*args, &block)
213
+ ensure
214
+ req.stop_layer
174
215
  end
175
216
  end
176
217
  end
218
+ end
177
219
 
178
- def log_with_scout_instruments(*args, &block)
220
+ module ActiveRecordInstruments
221
+ def self.prepended(instrumented_class)
222
+ ScoutApm::Agent.instance.context.logger.info "Instrumenting #{instrumented_class.inspect}"
223
+ end
224
+
225
+ def log(*args, &block)
179
226
  # Extract data from the arguments
180
227
  sql, name = args
181
228
  metric_name = Utils::ActiveRecordMetricName.new(sql, name)
@@ -206,7 +253,7 @@ module ScoutApm
206
253
  end
207
254
  current_layer.desc.merge(desc)
208
255
 
209
- log_without_scout_instruments(*args, &block)
256
+ super(*args, &block)
210
257
 
211
258
  # OR: Start a new layer, we didn't pick up instrumentation earlier in the stack.
212
259
  else
@@ -214,7 +261,7 @@ module ScoutApm
214
261
  layer.desc = desc
215
262
  req.start_layer(layer)
216
263
  begin
217
- log_without_scout_instruments(*args, &block)
264
+ super(*args, &block)
218
265
  ensure
219
266
  req.stop_layer
220
267
  end
@@ -261,14 +308,18 @@ module ScoutApm
261
308
  end
262
309
  end
263
310
 
264
- def find_by_sql_with_scout_instruments(*args, &block)
311
+ def find_by_sql_with_scout_instruments(*args, **kwargs, &block)
265
312
  req = ScoutApm::RequestManager.lookup
266
313
  layer = ScoutApm::Layer.new("ActiveRecord", Utils::ActiveRecordMetricName::DEFAULT_METRIC)
267
314
  layer.annotate_layer(:ignorable => true)
268
315
  req.start_layer(layer)
269
316
  req.ignore_children!
270
317
  begin
271
- find_by_sql_without_scout_instruments(*args, &block)
318
+ if ScoutApm::Agent.instance.context.environment.supports_kwarg_delegation?
319
+ find_by_sql_without_scout_instruments(*args, **kwargs, &block)
320
+ else
321
+ find_by_sql_without_scout_instruments(*args, &block)
322
+ end
272
323
  ensure
273
324
  req.acknowledge_children!
274
325
  req.stop_layer
@@ -346,7 +397,7 @@ module ScoutApm
346
397
  end
347
398
 
348
399
  module ActiveRecordUpdateInstruments
349
- def save(*args, &block)
400
+ def save(*args, **options, &block)
350
401
  model = self.class.name
351
402
  operation = self.persisted? ? "Update" : "Create"
352
403
 
@@ -356,14 +407,14 @@ module ScoutApm
356
407
  req.start_layer(layer)
357
408
  req.ignore_children!
358
409
  begin
359
- super(*args, &block)
410
+ super(*args, **options, &block)
360
411
  ensure
361
412
  req.acknowledge_children!
362
413
  req.stop_layer
363
414
  end
364
415
  end
365
416
 
366
- def save!(*args, &block)
417
+ def save!(*args, **options, &block)
367
418
  model = self.class.name
368
419
  operation = self.persisted? ? "Update" : "Create"
369
420
 
@@ -372,7 +423,7 @@ module ScoutApm
372
423
  req.start_layer(layer)
373
424
  req.ignore_children!
374
425
  begin
375
- super(*args, &block)
426
+ super(*args, **options, &block)
376
427
  ensure
377
428
  req.acknowledge_children!
378
429
  req.stop_layer
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,43 @@
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
@@ -37,8 +37,8 @@ module ScoutApm
37
37
  ### See moped instrument for Moped driven deploys
38
38
 
39
39
  ### 5.x Mongoid
40
- if (mongoid_v5? || mongoid_v6?) && defined?(::Mongoid::Contextual::Mongo)
41
- logger.info "Instrumenting Mongoid 5.x/6.x"
40
+ if (mongoid_v5? || mongoid_v6? || mongoid_v7?) && defined?(::Mongoid::Contextual::Mongo)
41
+ logger.info "Instrumenting Mongoid 5.x/6.x/7.x"
42
42
  # All the public methods from Mongoid::Contextual::Mongo.
43
43
  # TODO: Geo and MapReduce support (?). They are in other Contextual::* classes
44
44
  methods = [
@@ -54,8 +54,6 @@ module ScoutApm
54
54
  if ::Mongoid::Contextual::Mongo.method_defined?(method)
55
55
  with_scout_instruments = %Q[
56
56
  def #{method}_with_scout_instruments(*args, &block)
57
-
58
-
59
57
  req = ScoutApm::RequestManager.lookup
60
58
  *db, collection = view.collection.namespace.split(".")
61
59
 
@@ -112,6 +110,13 @@ module ScoutApm
112
110
  end
113
111
  end
114
112
 
113
+ def mongoid_v7?
114
+ if defined?(::Mongoid::VERSION)
115
+ ::Mongoid::VERSION =~ /\A7/
116
+ else
117
+ false
118
+ end
119
+ end
115
120
 
116
121
  # Example of what a filter looks like: => {"founded"=>{"$gte"=>"1980-1-1"}, "name"=>{"$in"=>["Tool", "Deftones", "Melvins"]}}
117
122
  # Approach: find every leaf-node, clear it. inspect the whole thing when done.
@@ -25,7 +25,7 @@ module ScoutApm
25
25
  ::Net::HTTP.class_eval do
26
26
  include ScoutApm::Tracer
27
27
 
28
- def request_with_scout_instruments(*args,&block)
28
+ def request_with_scout_instruments(*args, &block)
29
29
  self.class.instrument("HTTP", "request", :ignore_children => true, :desc => request_scout_description(args.first)) do
30
30
  request_without_scout_instruments(*args, &block)
31
31
  end
@@ -35,8 +35,15 @@ module ScoutApm
35
35
  path = req.path
36
36
  path = path.path if path.respond_to?(:path)
37
37
 
38
+ # Protect against a nil address value
39
+ if @address.nil?
40
+ return "No Address Found"
41
+ end
42
+
38
43
  max_length = ScoutApm::Agent.instance.context.config.value('instrument_http_url_length')
39
44
  (@address + path.split('?').first)[0..(max_length - 1)]
45
+ rescue
46
+ ""
40
47
  end
41
48
 
42
49
  alias request_without_scout_instruments request
@@ -32,8 +32,10 @@ module ScoutApm
32
32
 
33
33
  # Modifies self and returns self, after merging in `other`.
34
34
  def combine!(other)
35
- same_job = queue_name == other.queue_name && job_name == other.job_name
36
- raise "Mismatched Merge of Background Job" unless same_job
35
+ if !self.eql?(other)
36
+ ScoutApm::Agent.instance.logger.debug("Mismatched Merge of Background Job: (Queue #{queue_name} == #{other.queue_name}) (Name #{job_name} == #{other.job_name}) (Hash #{hash} == #{other.hash})")
37
+ return self
38
+ end
37
39
 
38
40
  @errors += other.errors
39
41
  @metric_set = metric_set.combine!(other.metric_set)
@@ -30,6 +30,10 @@ module ScoutApm
30
30
 
31
31
  def serialize(data)
32
32
  Marshal.dump(data)
33
+ rescue
34
+ ScoutApm::Agent.instance.logger.info("Failed Marshalling LayawayFile")
35
+ ScoutApm::Agent.instance.logger.info(ScoutApm::Utils::MarshalLogging.new(data).dive) rescue nil
36
+ raise
33
37
  end
34
38
 
35
39
  def deserialize(data)
@@ -36,7 +36,10 @@ module ScoutApm
36
36
 
37
37
  # If this layer took longer than a fixed amount of time, store the
38
38
  # backtrace of where it occurred.
39
- attr_reader :backtrace
39
+ attr_accessor :backtrace
40
+
41
+ # The file name associated with the layer. Only used for autoinstruments overhead logging.
42
+ attr_accessor :file_name
40
43
 
41
44
  # As we go through a part of a request, instrumentation can store additional data
42
45
  # Known Keys:
@@ -46,19 +49,7 @@ module ScoutApm
46
49
  # If no annotations are ever set, this will return nil
47
50
  attr_reader :annotations
48
51
 
49
- # ScoutProf - trace_index is an index into the Stack structure in the C
50
- # code, used to store captured traces.
51
- attr_reader :trace_index
52
-
53
- # ScoutProf - frame_index is an optimization to not capture a few frames
54
- # during scoutprof instrumentation
55
- attr_reader :frame_index
56
-
57
- # Captured backtraces from ScoutProf. This is distinct from the backtrace
58
- # attribute, which gets the ruby backtrace of any given layer. StackProf
59
- # focuses on Controller layers, and requires a native extension and a
60
- # reasonably recent Ruby.
61
- attr_reader :traces
52
+ attr_reader :allocations_start, :allocations_stop
62
53
 
63
54
  BACKTRACE_CALLER_LIMIT = 50 # maximum number of lines to send thru for backtrace analysis
64
55
 
@@ -73,11 +64,6 @@ module ScoutApm
73
64
  @children = nil
74
65
  @annotations = nil
75
66
  @desc = nil
76
-
77
- @traces = ScoutApm::TraceSet.new
78
- @raw_frames = []
79
- @frame_index = ScoutApm::Instruments::Stacks.current_frame_index # For efficiency sake, try to skip the bottom X frames when collecting traces
80
- @trace_index = ScoutApm::Instruments::Stacks.current_trace_index
81
67
  end
82
68
 
83
69
  def limited?
@@ -116,14 +102,6 @@ module ScoutApm
116
102
  @subscopable
117
103
  end
118
104
 
119
- def traced!
120
- @traced = true
121
- end
122
-
123
- def traced?
124
- @traced
125
- end
126
-
127
105
  # This is the old style name. This function is used for now, but should be
128
106
  # removed, and the new type & name split should be enforced through the
129
107
  # app.
@@ -138,42 +116,13 @@ module ScoutApm
138
116
  # In Ruby 2.0+, we can pass the range directly to the caller to reduce the memory footprint.
139
117
  def caller_array
140
118
  # omits the first several callers which are in the ScoutAPM stack.
141
- if ScoutApm::Agent.instance.context.environment.ruby_2?
119
+ if ScoutApm::Agent.instance.context.environment.ruby_2? || ScoutApm::Agent.instance.context.environment.ruby_3?
142
120
  caller(3...BACKTRACE_CALLER_LIMIT)
143
121
  else
144
122
  caller[3...BACKTRACE_CALLER_LIMIT]
145
123
  end
146
124
  end
147
125
 
148
- # Set the name of the file that this action is coming from.
149
- # TraceSet uses this to more accurately filter backtraces
150
- def set_root_class(klass_name)
151
- @traces.set_root_class(klass_name)
152
- end
153
-
154
- def start_sampling
155
- if ScoutApm::Agent.instance.context.config.value('profile') && traced?
156
- ScoutApm::Instruments::Stacks.update_indexes(frame_index, trace_index)
157
- ScoutApm::Instruments::Stacks.start_sampling
158
- else
159
- ScoutApm::Instruments::Stacks.stop_sampling(false)
160
- end
161
- end
162
-
163
- def record_traces!
164
- if ScoutApm::Agent.instance.context.config.value('profile')
165
- ScoutApm::Instruments::Stacks.stop_sampling(false)
166
- if traced?
167
- traces.raw_traces = ScoutApm::Instruments::Stacks.profile_frames
168
- traces.skipped_in_gc = ScoutApm::Instruments::Stacks.skipped_in_gc
169
- traces.skipped_in_handler = ScoutApm::Instruments::Stacks.skipped_in_handler
170
- traces.skipped_in_job_registered = ScoutApm::Instruments::Stacks.skipped_in_job_registered
171
- traces.skipped_in_not_running = ScoutApm::Instruments::Stacks.skipped_in_not_running
172
- end
173
- end
174
- end
175
-
176
-
177
126
  ######################################
178
127
  # Debugging Helpers
179
128
  ######################################
@@ -46,9 +46,15 @@ module ScoutApm
46
46
  set = child_set(metric_type)
47
47
 
48
48
  if set.size >= unique_cutoff
49
- # find limited_layer
50
- @limited_layers || init_limited_layers
51
- @limited_layers[metric_type].absorb(child)
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)
52
58
  else
53
59
  # we have space just add it
54
60
  set << child
@@ -69,9 +75,12 @@ module ScoutApm
69
75
  end
70
76
  end
71
77
 
72
- # hold off initializing this until we know we need it
73
- def init_limited_layers
74
- @limited_layers ||= Hash.new { |hash, key| hash[key] = LimitedLayer.new(key) }
78
+ def length
79
+ @children.length
80
+ end
81
+
82
+ def size
83
+ @children.size
75
84
  end
76
85
  end
77
86
  end