Module: OneApm::Support::MethodTracer

Extended by:
ClassMethods
Included in:
Agent::Instrumentation::ActiveJobHelper, Sequel::OneApmInstrumentation, Sequel::Plugins::OneapmInstrumentation::ClassMethods, Sequel::Plugins::OneapmInstrumentation::InstanceMethods
Defined in:
lib/one_apm/support/method_tracer.rb,
lib/one_apm/support/method_tracer/helpers.rb

Overview

This module contains class methods added to support installing custom metric tracers and executing for individual metrics.

Examples

When the agent initializes, it extends Module with these methods. However if you want to use the API in code that might get loaded before the agent is initialized you will need to require this file:

require 'one_apm/support/method_tracer'
class A
  include OneApm::Support::MethodTracer
  def process
    ...
  end
  add_method_tracer :process
end

To instrument a class method:

require 'one_apm/support/method_tracer'
class An
  def self.process
    ...
  end
  class << self
    include OneApm::Support::MethodTracer
    add_method_tracer :process
  end
end

Defined Under Namespace

Modules: ClassMethods, Helpers

Constant Summary

Constants included from ClassMethods::AddMethodTracer

ClassMethods::AddMethodTracer::ALLOWED_KEYS, ClassMethods::AddMethodTracer::DEPRECATED_KEYS, ClassMethods::AddMethodTracer::OA_DEFAULT_SETTINGS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

add_method_tracer, remove_method_tracer

Methods included from ClassMethods::AddMethodTracer

#assemble_code_header, #check_for_illegal_keys!, #check_for_push_scope_and_metric, #code_to_eval, #default_metric_name_code, #method_with_push_scope, #method_without_push_scope, #oneapm_method_exists?, #traced_method_exists?, #validate_options

Class Method Details

.extended(clazz) ⇒ Object



48
49
50
# File 'lib/one_apm/support/method_tracer.rb', line 48

def self.extended clazz
  clazz.extend ClassMethods
end

.included(clazz) ⇒ Object



44
45
46
# File 'lib/one_apm/support/method_tracer.rb', line 44

def self.included clazz
  clazz.extend ClassMethods
end

Instance Method Details

#trace_execution_scoped(metric_names, options = {}) ⇒ Object

Trace a given block with stats and keep track of the caller. See OneApm::Support::MethodTracer::ClassMethods#add_method_tracer for a description of the arguments. metric_names is either a single name or an array of metric names. If more than one metric is passed, the produce_metric option only applies to the first. The others are always recorded. Only the first metric is pushed onto the scope stack.

Generally you pass an array of metric names if you want to record the metric under additional categories, but generally this *should never ever be done*. Most of the time you can aggregate on the server.



64
65
66
67
68
69
# File 'lib/one_apm/support/method_tracer.rb', line 64

def trace_execution_scoped(metric_names, options={})
  OneApm::Support::MethodTracer::Helpers.trace_execution_scoped(metric_names, options) do
    # Using an implicit block avoids object allocation for a &block param
    yield
  end
end

#trace_execution_unscoped(metric_names, options = {}) ⇒ Object

Trace a given block with stats assigned to the given metric_name. It does not provide scoped measurements, meaning whatever is being traced will not ‘blame the Controller’–that is to say appear in the breakdown chart. This is code is inlined in #add_method_tracer.

  • metric_names is a single name or an array of names of metrics



79
80
81
82
83
84
85
86
87
88
# File 'lib/one_apm/support/method_tracer.rb', line 79

def trace_execution_unscoped(metric_names, options={})
  return yield unless OneApm::Manager.tl_is_execution_traced?
  t0 = Time.now
  begin
    yield
  ensure
    duration = (Time.now - t0).to_f              # for some reason this is 3 usec faster than Time - Time
    OneApm::Manager.agent.stats_engine.tl_record_unscoped_metrics(metric_names, duration)
  end
end