module NewRelic::Agent::MethodTracerHelpers

Constants

MAX_ALLOWED_METRIC_DURATION

Public Instance Methods

log_errors(code_area) { || ... } click to toggle source

helper for logging errors to the newrelic_agent.log properly. Logs the error at error level

# File lib/new_relic/agent/method_tracer_helpers.rb, line 13
def log_errors(code_area)
  yield
rescue => e
  ::NewRelic::Agent.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/new_relic/agent/method_tracer_helpers.rb, line 26
def record_metrics(state, first_name, other_names, duration, exclusive, options)
  record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
  stat_engine = NewRelic::Agent.instance.stats_engine
  if record_scoped_metric
    stat_engine.record_scoped_and_unscoped_metrics(state, first_name, other_names, duration, exclusive)
  else
    metrics = [first_name].concat(other_names)
    stat_engine.record_unscoped_metrics(state, metrics, duration, exclusive)
  end
end
trace_execution_scoped(metric_names, options={}) { || ... } click to toggle source
# File lib/new_relic/agent/method_tracer_helpers.rb, line 68
def trace_execution_scoped(metric_names, options={}) #THREAD_LOCAL_ACCESS
  state = NewRelic::Agent::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/new_relic/agent/method_tracer_helpers.rb, line 19
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