Class: ScoutApm::LayerConverters::SlowRequestConverter
- Inherits:
-
ConverterBase
- Object
- ConverterBase
- ScoutApm::LayerConverters::SlowRequestConverter
- Defined in:
- lib/scout_apm/layer_converters/slow_request_converter.rb
Constant Summary
Constants inherited from ConverterBase
Instance Attribute Summary
Attributes inherited from ConverterBase
#request, #root_layer, #walker
Instance Method Summary collapse
-
#call ⇒ Object
Unconditionally attempts to convert this into a SlowTransaction object.
-
#create_metrics ⇒ Object
Full metrics from this request.
-
#initialize ⇒ SlowRequestConverter
constructor
A new instance of SlowRequestConverter.
- #name ⇒ Object
- #score ⇒ Object
Methods inherited from ConverterBase
#attach_backtraces, #find_first_layer_of_type, #limited?, #make_meta_options, #make_meta_options_desc_hash, #make_meta_options_scope, #over_metric_limit?, #scope_layer, #setup_subscopable_callbacks, #skip_layer?, #store_aggregate_metric, #store_backtrace, #store_specific_metric, #subscope_name, #subscoped?
Constructor Details
#initialize ⇒ SlowRequestConverter
Returns a new instance of SlowRequestConverter.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/scout_apm/layer_converters/slow_request_converter.rb', line 4 def initialize(*) super # After call to super, so @request is populated @points = if request.web? ScoutApm::Agent.instance.slow_request_policy.score(request) else -1 end setup_subscopable_callbacks end |
Instance Method Details
#call ⇒ Object
Unconditionally attempts to convert this into a SlowTransaction object. Can return nil if the request didn’t have any scope_layer.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/scout_apm/layer_converters/slow_request_converter.rb', line 27 def call return nil unless request.web? return nil unless scope_layer ScoutApm::Agent.instance.slow_request_policy.stored!(request) # record the change in memory usage mem_delta = ScoutApm::Instruments::Process::ProcessMemory.rss_to_mb(@request.capture_mem_delta!) uri = request.annotations[:uri] || "" timing_metrics, allocation_metrics = create_metrics unless ScoutApm::Instruments::Allocations::ENABLED allocation_metrics = {} end SlowTransaction.new(uri, scope_layer.legacy_metric_name, root_layer.total_call_time, timing_metrics, allocation_metrics, request.context, root_layer.stop_time, [], # stackprof, now unused. mem_delta, root_layer.total_allocations, @points, limited?) end |
#create_metrics ⇒ Object
Full metrics from this request. These get stored permanently in a SlowTransaction. Some merging of metrics will happen here, so if a request calls the same ActiveRecord or View repeatedly, it’ll get merged.
This returns a 2-element of Metric Hashes (the first element is timing metrics, the second element is allocation metrics)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/scout_apm/layer_converters/slow_request_converter.rb', line 63 def create_metrics metric_hash = Hash.new allocation_metric_hash = Hash.new walker.walk do |layer| next if skip_layer?(layer) store_specific_metric(layer, metric_hash, allocation_metric_hash) store_aggregate_metric(layer, metric_hash, allocation_metric_hash) end metric_hash = attach_backtraces(metric_hash) allocation_metric_hash = attach_backtraces(allocation_metric_hash) [metric_hash, allocation_metric_hash] end |
#name ⇒ Object
17 18 19 |
# File 'lib/scout_apm/layer_converters/slow_request_converter.rb', line 17 def name request.unique_name end |
#score ⇒ Object
21 22 23 |
# File 'lib/scout_apm/layer_converters/slow_request_converter.rb', line 21 def score @points end |