Module: NewRelic::Security::Instrumentation::Mongo::Collection::Chain

Defined in:
lib/newrelic_security/instrumentation-security/mongo/chain.rb

Class Method Summary collapse

Class Method Details

.instrument!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/newrelic_security/instrumentation-security/mongo/chain.rb', line 6

def self.instrument!
  ::Mongo::Collection.class_eval do
    include NewRelic::Security::Instrumentation::Mongo::Collection
  
    alias_method :find_without_security, :find
    
    def find(filter = nil, options = {})
      retval = nil
      event = find_on_enter(filter, options) { retval = find_without_security(filter, options) }
      find_on_exit(event) { return retval }
    end

    alias_method :insert_one_without_security, :insert_one
    
    def insert_one(document, opts = {})
      retval = nil
      event = insert_one_on_enter(document, opts) { retval = insert_one_without_security(document, opts) }
      insert_one_on_exit(event) { return retval }
    end

    alias_method :insert_many_without_security, :insert_many
    
    def insert_many(documents, options = {})
      retval = nil
      event = insert_many_on_enter(documents, options) { retval = insert_many_without_security(documents, options) }
      insert_many_on_exit(event) { return retval }
    end
  end
end