Class: ScoutApm::Instruments::Moped

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/moped.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/moped.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/moped.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scout_apm/instruments/moped.rb', line 15

def install
  @installed = true

  if defined?(::Moped)
    ScoutApm::Agent.instance.logger.info "Instrumenting Moped"
    ::Moped::Node.class_eval do
      include ScoutApm::Tracer

      def process_with_scout_instruments(operation, &callback)
        if operation.respond_to?(:collection)
          collection = operation.collection
          name = "Process/#{collection}/#{operation.class.to_s.split('::').last}"
          self.class.instrument("MongoDB", name, :annotate_layer => { :query => scout_sanitize_log(operation.log_inspect) }) do
            process_without_scout_instruments(operation, &callback)
          end
        end
      end
      alias_method :process_without_scout_instruments, :process
      alias_method :process, :process_with_scout_instruments

      # replaces values w/ ?
      def scout_sanitize_log(log)
        return nil if log.length > 1000 # safeguard - don't sanitize large SQL statements
        log.gsub(/(=>")((?:[^"]|"")*)"/) do
          $1 + '?' + '"'
        end
      end
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


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

def installed?
  @installed
end