module OneApm::Support::MethodTracer::Helpers

Constants

OA_MAX_ALLOWED_METRIC_DURATION

Public Instance Methods

log_errors(code_area) { || ... } click to toggle source
# File lib/one_apm/support/method_tracer/helpers.rb, line 22
def log_errors(code_area)
  yield
rescue => e
  OneApm::Manager.logger.error("Caught exception in #{code_area}.", e)
end
record_metrics(state, first_name, other_names, duration, exclusive, options) click to toggle source
# File lib/one_apm/support/method_tracer/helpers.rb, line 11
def record_metrics(state, first_name, other_names, duration, exclusive, options)
  record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
  stats_engine = OneApm::Manager.agent.stats_engine
  if record_scoped_metric
    stats_engine.record_scoped_and_unscoped_metrics(state, first_name, other_names, duration, exclusive)
  else
    metrics = [first_name].concat(other_names)
    stats_engine.record_unscoped_metrics(state, metrics, duration, exclusive)
  end
end
trace_execution_scoped(metric_names, options={}) { || ... } click to toggle source
# File lib/one_apm/support/method_tracer/helpers.rb, line 70
def trace_execution_scoped(metric_names, options={})
  state = OneApm::TransactionState.tl_get
  return yield unless state.is_execution_traced?

  metric_names = Array(metric_names)
  first_name   = metric_names.shift
  return yield unless first_name

  additional_metrics_callback = options[:additional_metrics_callback]
  start_time = Time.now.to_f
  expected_scope = trace_execution_scoped_header(state, start_time)

  begin
    result = yield
    metric_names += Array(additional_metrics_callback.call) if additional_metrics_callback
    result
  ensure
    trace_execution_scoped_footer(state, start_time, first_name, metric_names, expected_scope, options)
  end
end
trace_execution_scoped_header(state, t0) click to toggle source
# File lib/one_apm/support/method_tracer/helpers.rb, line 28
def trace_execution_scoped_header(state, t0)
  log_errors(:trace_execution_scoped_header) do
    stack = state.traced_method_stack
    stack.push_frame(state, :method_tracer, t0)
  end
end