18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/new_relic/agent/instrumentation/active_record_instrumentation.rb', line 18
def log_with_newrelic_instrumentation(sql, name, &block)
return log_without_newrelic_instrumentation(sql, name, &block) unless NewRelic::Agent.is_execution_traced?
if (defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)) ||
(defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter))
supported_config = @config
end
if name && (parts = name.split " ") && parts.size == 2
model = parts.first
operation = parts.last.downcase
metric_name = case operation
when 'load' then 'find'
when 'indexes', 'columns' then nil when 'destroy', 'find', 'save', 'create' then operation
when 'update' then 'save'
else
if model == 'Join'
operation
end
end
metric = "ActiveRecord/#{model}/#{metric_name}" if metric_name
end
if metric.nil?
metric = NewRelic::Agent::Instrumentation::MetricFrame.database_metric_name
if metric.nil?
if sql =~ /^(select|update|insert|delete|show)/i
metric = "Database/SQL/#{$1.downcase}"
else
metric = "Database/SQL/other"
end
end
end
if !metric
log_without_newrelic_instrumentation(sql, name, &block)
else
metrics = [metric, "ActiveRecord/all"]
metrics << "ActiveRecord/#{metric_name}" if metric_name
self.class.trace_execution_scoped(metrics) do
t0 = Time.now
begin
log_without_newrelic_instrumentation(sql, name, &block)
ensure
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, supported_config, (Time.now - t0).to_f)
end
end
end
end
|