module Mmtrix::Agent::Instrumentation::ActiveRecordHelper
Constants
- ACTIVE_RECORD
- ACTIVE_RECORD_DEFAULT_PRODUCT_NAME
- EMPTY
- OPERATION_NAMES
These are used primarily to optimize and avoid allocation on well known operations coming in. Anything not matching the list is fine, it just needs to get downcased directly for use.
- OTHER
- PRODUCT_NAMES
- SPACE
Public Instance Methods
delete_all(*args, &blk)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 45 def delete_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do delete_all_without_mmtrix(*args, &blk) end end
destroy_all(*args, &blk)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 53 def destroy_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do destroy_all_without_mmtrix(*args, &blk) end end
instrument_writer_methods()
click to toggle source
Used by both the AR 3.x and 4.x instrumentation
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 15 def instrument_writer_methods ::ActiveRecord::Base.class_eval do alias_method :save_without_mmtrix, :save def save(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.class.name, nil, ACTIVE_RECORD) do save_without_mmtrix(*args, &blk) end end alias_method :save_without_mmtrix!, :save! def save!(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.class.name, nil, ACTIVE_RECORD) do save_without_mmtrix!(*args, &blk) end end end ::ActiveRecord::Relation.class_eval do alias_method :update_all_without_mmtrix, :update_all def update_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do update_all_without_mmtrix(*args, &blk) end end alias_method :delete_all_without_mmtrix, :delete_all def delete_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do delete_all_without_mmtrix(*args, &blk) end end alias_method :destroy_all_without_mmtrix, :destroy_all def destroy_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do destroy_all_without_mmtrix(*args, &blk) end end end end
map_operation(raw_operation)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 134 def map_operation(raw_operation) direct_op = OPERATION_NAMES[raw_operation] return direct_op if direct_op raw_operation.downcase end
map_product(adapter_name)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 181 def map_product(adapter_name) PRODUCT_NAMES.fetch(adapter_name, ACTIVE_RECORD_DEFAULT_PRODUCT_NAME) end
metrics_for(name, sql, adapter_name)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 64 def metrics_for(name, sql, adapter_name) product = map_product(adapter_name) splits = split_name(name) model = model_from_splits(splits) operation = operation_from_splits(splits, sql) Mmtrix::Agent::Datastores::MetricHelper.metrics_for(product, operation, model, ACTIVE_RECORD) end
model_from_splits(splits)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 102 def model_from_splits(splits) if splits.length == 2 splits.first else nil end end
operation_from_splits(splits, sql)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 110 def operation_from_splits(splits, sql) if splits.length == 2 map_operation(splits[1]) else Mmtrix::Agent::Database.parse_operation_from_query(sql) || OTHER end end
rollup_metrics_for(*_)
click to toggle source
@deprecated
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 77 def rollup_metrics_for(*_) Mmtrix::Agent::Deprecator.deprecate("ActiveRecordHelper.rollup_metrics_for", "Mmtrix::Agent::Datastores::MetricHelper.metrics_for") rollup_metric = if Mmtrix::Agent::Transaction.recording_web_transaction? Mmtrix::Agent::Datastores::MetricHelper::WEB_ROLLUP_METRIC else Mmtrix::Agent::Datastores::MetricHelper::OTHER_ROLLUP_METRIC end [rollup_metric, Mmtrix::Agent::Datastores::MetricHelper::ROLLUP_METRIC] end
save(*args, &blk)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 19 def save(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.class.name, nil, ACTIVE_RECORD) do save_without_mmtrix(*args, &blk) end end
save!(*args, &blk)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 27 def save!(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.class.name, nil, ACTIVE_RECORD) do save_without_mmtrix!(*args, &blk) end end
split_name(name)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 94 def split_name(name) if name && name.respond_to?(:split) name.split(SPACE) else EMPTY end end
update_all(*args, &blk)
click to toggle source
# File lib/mmtrix/agent/instrumentation/active_record_helper.rb, line 37 def update_all(*args, &blk) ::Mmtrix::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do update_all_without_mmtrix(*args, &blk) end end