Skip to content

Commit

Permalink
added mongoid support. still need to add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl committed May 15, 2010
1 parent 1682dae commit 8e6fafe
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/rpm_contrib/instrumentation/mongoid.rb
Original file line number Diff line number Diff line change
@@ -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








1 change: 1 addition & 0 deletions rpm_contrib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions test/mongoid_test.rb
Original file line number Diff line number Diff line change
@@ -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
Empty file modified test/test_rpm_contrib.rb
100644 → 100755
Empty file.

0 comments on commit 8e6fafe

Please sign in to comment.