Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #16 from titanous/mongoid-instrumentation

Detailed MongoDB/Mongoid instrumentation
  • Loading branch information...
commit 9c9ccd0f6f63bdcb7884ba05ca684370f7e9fd7d 2 parents b9d6cbe + 5ba7563
Sam Goldstein samg authored
14 lib/rpm_contrib/instrumentation/mongo.rb
View
@@ -11,7 +11,7 @@
end
executes do
- ::Mongo::Connection.class_eval do
+ ::Mongo::Logging.class_eval do
include NewRelic::Agent::MethodTracer
def instrument_with_newrelic_trace(name, payload = {}, &blk)
@@ -32,17 +32,21 @@ def instrument_with_newrelic_trace(name, payload = {}, &blk)
alias_method :instrument_without_newrelic_trace, :instrument
alias_method :instrument, :instrument_with_newrelic_trace
end
+ class Mongo::Collection; include Mongo::Logging; end
+ class Mongo::Connection; include Mongo::Logging; end
+ class Mongo::Cursor; include Mongo::Logging; end
+ # cursor refresh is not currently instrumented in mongo driver, so not picked up by above - have to add our own here
::Mongo::Cursor.class_eval do
include NewRelic::Agent::MethodTracer
- def refresh_with_newrelic_trace
+ def send_get_more_with_newrelic_trace
trace_execution_scoped("Database/#{collection.name}/refresh") do
- refresh_without_newrelic_trace
+ send_get_more_without_newrelic_trace
end
end
- alias_method :refresh_without_newrelic_trace, :refresh
- alias_method :refresh, :refresh_with_newrelic_trace
+ alias_method :send_get_more_without_newrelic_trace, :send_get_more
+ alias_method :send_get_more, :send_get_more_with_newrelic_trace
add_method_tracer :close, 'Database/#{collection.name}/close'
end
end
21 lib/rpm_contrib/instrumentation/mongoid.rb
View
@@ -0,0 +1,21 @@
+DependencyDetection.defer do
+ @name = :mongoid
+
+ depends_on do
+ defined?(::Mongoid) and not NewRelic::Control.instance['disable_mongoid']
+ end
+
+ executes do
+ NewRelic::Agent.logger.debug 'Installing Mongoid instrumentation'
+ end
+
+ executes do
+ Mongoid::Collection.class_eval do
+ include NewRelic::Agent::MethodTracer
+
+ (Mongoid::Collections::Operations::ALL - [:<<, :[]]).each do |method|
+ add_method_tracer method, "ActiveRecord/\#{@klass}/#{method}"
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.