Skip to content

Commit

Permalink
ATTENTION: remove one more alias_method_chain call.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed Jul 17, 2008
1 parent 0c12e54 commit 9389ebc
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions lib/newrelic/agent/instrumentation/active_record.rb
Expand Up @@ -36,7 +36,21 @@ class AbstractAdapter

@@my_sql_defined = defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
@@postgres_defined = defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter


def log_with_newrelic_instrumentation(sql, name, &block)
# if we aren't in a blamed context, then add one so that we can see that
# controllers are calling SQL directly
# we check scope_depth vs 2 since the controller is 1, and the
#
if NewRelic::Agent.instance.transaction_sampler.scope_depth < 2
self.class.trace_method_execution "Database/DirectSQL", true, true, false do
log_with_capture_sql(sql, name, &block)
end
else
log_with_capture_sql(sql, name, &block)
end
end

def log_with_capture_sql(sql, name, &block)
if @@my_sql_defined && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
config = @config
Expand All @@ -45,45 +59,28 @@ def log_with_capture_sql(sql, name, &block)
else
config = nil
end
result = log_without_capture_sql(sql, name, &block)


result = log_without_newrelic_instrumentation(sql, name, &block)
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, config)

result
end

# Compare with #alias_method_chain, which is not available in
# Rails 1.1:
alias_method :log_without_capture_sql, :log
alias_method :log, :log_with_capture_sql
alias_method :log_without_newrelic_instrumentation, :log
alias_method :log, :log_with_newrelic_instrumentation
protected :log

# FIXME
# The method tracer below meesses up the scope stack. We need to make sure
# that when :metric => false, the top of the scope stack does not deduct
# this traced method's run time from the calling component's exclusive time. If
# we don't then we get pie charts where all db activity is invisible.
# add_method_tracer :log, 'Database/#{adapter_name}/#{args[1]}', :metric => false
# add_method_tracer :log, 'Database/#{adapter_name}/#{args[1]}', :metric => false
add_method_tracer :log, 'Database/all', :push_scope => false


def log_with_add_scope(sql, name, &block)
# if we aren't in a blamed context, then add one so that we can see that
# controllers are calling SQL directly
# we check scope_depth vs 2 since the controller is 1, and the
#
if NewRelic::Agent.instance.transaction_sampler.scope_depth < 2
self.class.trace_method_execution "Database/DirectSQL", true, true, false do
log_without_add_scope(sql, name, &block)
end
else
log_without_add_scope(sql, name, &block)
end
end

alias_method_chain :log, :add_scope

end
end

Expand Down

0 comments on commit 9389ebc

Please sign in to comment.