Skip to content

Instantly share code, notes, and snippets.

@johnf
Created December 19, 2011 10:49
Show Gist options
  • Save johnf/1496601 to your computer and use it in GitHub Desktop.
Save johnf/1496601 to your computer and use it in GitHub Desktop.
new relic example
require 'newrelic_rpm'
# https://support.newrelic.com/help/discussions/support/7631-not-seeing-database-data
NewRelic::Agent.add_instrumentation(File.join(Gem.loaded_specs['newrelic_rpm'].full_gem_path, "lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb"))
# From lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb
require 'new_relic/agent/instrumentation/rails3/active_record_instrumentation'
ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
include ::NewRelic::Agent::Instrumentation::ActiveRecordInstrumentation
end
ActiveRecord::Base.class_eval do
class << self
add_method_tracer :find_by_sql, 'ActiveRecord/#{self.name}/find_by_sql', :metric => false
add_method_tracer :transaction, 'ActiveRecord/#{self.name}/transaction', :metric => false
end
end
NewRelic::Agent.manual_start
def moo(r)
sleep rand(r)
end
add_transaction_tracer :moo, :class_name => 'moo', :name => 'sleep'
1.upto(5) do |i|
moo i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment