module Mmtrix::Agent::Instrumentation::ActiveRecord
Constants
- EXPLAINER
Public Class Methods
included(instrumented_class)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record.rb, line 29 def self.included(instrumented_class) instrumented_class.class_eval do unless instrumented_class.method_defined?(:log_without_mmtrix_instrumentation) alias_method :log_without_mmtrix_instrumentation, :log alias_method :log, :log_with_mmtrix_instrumentation protected :log end end end
insert_instrumentation()
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record.rb, line 19 def self.insert_instrumentation if defined?(::ActiveRecord::VERSION::MAJOR) && ::ActiveRecord::VERSION::MAJOR.to_i >= 3 ::Mmtrix::Agent::Instrumentation::ActiveRecordHelper.instrument_writer_methods end ::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do include ::Mmtrix::Agent::Instrumentation::ActiveRecord end end
Public Instance Methods
log_with_mmtrix_instrumentation(*args, &block)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record.rb, line 39 def log_with_mmtrix_instrumentation(*args, &block) #THREAD_LOCAL_ACCESS state = Mmtrix::Agent::TransactionState.tl_get if !state.is_execution_traced? return log_without_mmtrix_instrumentation(*args, &block) end sql, name, _ = args metrics = ActiveRecordHelper.metrics_for( Mmtrix::Helper.correctly_encoded(name), Mmtrix::Helper.correctly_encoded(sql), @config && @config[:adapter]) # It is critical that we grab this name before trace_execution_scoped # because that method mutates the metrics list passed in. scoped_metric = metrics.first Mmtrix::Agent::MethodTracer.trace_execution_scoped(metrics) do t0 = Time.now begin log_without_mmtrix_instrumentation(*args, &block) ensure elapsed_time = (Time.now - t0).to_f Mmtrix::Agent.instance.transaction_sampler.notice_sql(sql, @config, elapsed_time, state, EXPLAINER) Mmtrix::Agent.instance.sql_sampler.notice_sql(sql, scoped_metric, @config, elapsed_time, state, EXPLAINER) end end end