Class: ScoutApm::Instruments::Mongoid

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/mongoid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/scout_apm/instruments/mongoid.rb', line 4

def logger
  @logger
end

Instance Method Details

#initalize(logger = ScoutApm::Agent.instance.logger) ⇒ Object



6
7
8
9
# File 'lib/scout_apm/instruments/mongoid.rb', line 6

def initalize(logger=ScoutApm::Agent.instance.logger)
  @logger = logger
  @installed = false
end

#installObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scout_apm/instruments/mongoid.rb', line 15

def install
  @installed = true

  # Mongoid versions that use Moped should instrument Moped.
  if defined?(::Mongoid) and !defined?(::Moped)
    ScoutApm::Agent.instance.logger.info "Instrumenting Mongoid"

    ::Mongoid::Collection.class_eval do
      include ScoutApm::Tracer
      (::Mongoid::Collections::Operations::ALL - [:<<, :[]]).each do |method|
        instrument_method method, :type => "MongoDB", :name => '#{@klass}/' + method.to_s
      end
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/scout_apm/instruments/mongoid.rb', line 11

def installed?
  @installed
end