module TingYun::Instrumentation::ActiveRecord

Constants

EXPLAINER

Public Class Methods

explain_plan(statement) click to toggle source
# File lib/ting_yun/instrumentation/active_record.rb, line 17
def self.explain_plan(statement)
  TingYun::Agent::Database.explain_plan(statement)
end
included(instrumented_class) click to toggle source
# File lib/ting_yun/instrumentation/active_record.rb, line 23
def self.included(instrumented_class)
  instrumented_class.class_eval do
    unless instrumented_class.method_defined?(:log_without_tingyun_instrumentation)
      alias_method :log_without_tingyun_instrumentation, :log
      alias_method :log, :log_with_tingyun_instrumentation
      protected :log
    end
  end
end
instrument() click to toggle source
# File lib/ting_yun/instrumentation/active_record.rb, line 33
def self.instrument
  if defined?(::ActiveRecord::VERSION::MAJOR) && ::ActiveRecord::VERSION::MAJOR.to_i >= 3
    ::TingYun::Instrumentation::Support::ActiveRecordHelper.instrument_additional_methods
  end

  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
    include ::TingYun::Instrumentation::ActiveRecord
  end
end

Public Instance Methods

log_with_tingyun_instrumentation(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/active_record.rb, line 43
def log_with_tingyun_instrumentation(*args, &block)
  state = TingYun::Agent::TransactionState.tl_get
  sql, name, _ = args
  @config= ::TingYun::Instrumentation::Support::ActiveRecordHelper.metrics_for(
      TingYun::Helper.correctly_encoded(name),
      TingYun::Helper.correctly_encoded(sql),
      @config)


  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(nil, {}, nil, nil) do
    t0 = Time.now
    begin
      log_without_tingyun_instrumentation(*args, &block)
    ensure
      elapsed_time = (Time.now - t0).to_f
      state.timings.sql_duration = state.timings.sql_duration  + elapsed_time * 1000

      ::TingYun::Agent::Collector::TransactionSampler.notice_sql(sql, @config, elapsed_time, state, EXPLAINER)
      # ::TingYun::Agent::Collector::SqlSampler.notice_sql(sql, scoped_metric, @config, elapsed_time, state, EXPLAINER)
    end

  end
end