Permalink
Browse files

added mongoid support. still need to add tests

  • Loading branch information...
1 parent 1682dae commit 8e6fafed92580cdc02700fc4130b08c462b2a7db Karl committed May 15, 2010
@@ -0,0 +1,60 @@
+if defined?(::MongoMapper) && !NewRelic::Control.instance['disable_mongodb']
+
+ module Mongoid #:nodoc:
+ module Document
+
+ #adding call to super
+ class << self
+ alias :old_included :included
+
+ def included(model)
+ old_included(model)
+ super
+ end
+ end
+ end
+ end
+
+ module RPMContrib::Instrumentation
+
+ module Mongoid
+ def included(model)
+ model.metaclass.class_eval do
+ add_method_tracer :create, 'Database/#{self.name}/create'
+ add_method_tracer :create!, 'Database/#{self.name}/create!'
+ add_method_tracer :delete_all, 'Database/#{self.name}/delete_all'
+ add_method_tracer :destroy_all, 'Database/#{self.name}/destroy_all'
+ add_method_tracer :all, 'Database/#{self.name}/all'
+ add_method_tracer :find, 'Database/#{self.name}/find'
+ add_method_tracer :first, 'Database/#{self.name}/first'
+ add_method_tracer :last, 'Database/#{self.name}/last'
+ add_method_tracer :find_or_create_by, 'Database/#{self.name}/find_or_create_by'
+ add_method_tracer :find_or_initialize_by, 'Database/#{self.name}/find_or_initialize_by'
+ add_method_tracer :min, 'Database/#{self.name}/min'
+ add_method_tracer :max, 'Database/#{self.name}/max'
+ add_method_tracer :sum, 'Database/#{self.name}/sum'
+ end
+
+ model.class_eval do
+ add_method_tracer :update_attributes, 'Database/#{self.class.name}/update_attributes'
+ add_method_tracer :update_attributes!, 'Database/#{self.class.name}/update_attributes!'
+ add_method_tracer :save, 'Database/#{self.class.name}/save'
+ add_method_tracer :save!, 'Database/#{self.class.name}/save!'
+ add_method_tracer :delete, 'Database/#{self.class.name}/delete'
+ add_method_tracer :destroy, 'Database/#{self.class.name}/destroy'
+
+ end
+ super
+ end
+ end
+ ::Mongoid::Document.extend(RPMContrib::Instrumentation::Mongoid)
+ end
+end
+
+
+
+
+
+
+
+
View
@@ -30,6 +30,7 @@ the New Relic Ruby monitoring gem newrelic_rpm.
"lib/rpm_contrib/detection/resque.rb",
"lib/rpm_contrib/instrumentation/camping.rb",
"lib/rpm_contrib/instrumentation/mongodb.rb",
+ "lib/rpm_contrib/instrumentation/mongoid.rb",
"lib/rpm_contrib/instrumentation/paperclip.rb",
"lib/rpm_contrib/instrumentation/redis.rb",
"lib/rpm_contrib/instrumentation/resque.rb",
View
@@ -0,0 +1,31 @@
+require "#{File.dirname(__FILE__)}/helper"
+require 'mongoid'
+
+class Dog
+ include Mongoid::Document
+
+ field :name
+end
+
+class MongoidTest < Test::Unit::TestCase
+
+ # Called before every test method runs. Can be used
+ # to set up fixture information.
+ def setup
+ # Do nothing
+ end
+
+ # Called after every test method runs. Can be used to tear
+ # down fixture information.
+
+ def teardown
+ # Do nothing
+ end
+
+ # Fake test
+ def test_fail
+
+ # To change this template use File | Settings | File Templates.
+ fail("Not implemented")
+ end
+end
View
0 test/test_rpm_contrib.rb 100644 → 100755
No changes.

0 comments on commit 8e6fafe

Please sign in to comment.