Class: ScoutApm::Instruments::Moped
- Inherits:
-
Object
- Object
- ScoutApm::Instruments::Moped
- Defined in:
- lib/scout_apm/instruments/moped.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(context) ⇒ Moped
constructor
A new instance of Moped.
- #install(prepend:) ⇒ Object
- #installed? ⇒ Boolean
- #logger ⇒ Object
Constructor Details
#initialize(context) ⇒ Moped
Returns a new instance of Moped.
6 7 8 9 |
# File 'lib/scout_apm/instruments/moped.rb', line 6 def initialize(context) @context = context @installed = false end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/scout_apm/instruments/moped.rb', line 4 def context @context end |
Instance Method Details
#install(prepend:) ⇒ Object
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 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/scout_apm/instruments/moped.rb', line 19 def install(prepend:) if defined?(::Moped) @installed = true logger.info "Instrumenting Moped. Prepend: #{prepend}" if prepend ::Moped::Node.send(:include, ScoutApm::Tracer) ::Moped::Node.send(:prepend, MopedInstrumentationPrepend) else ::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 end |
#installed? ⇒ Boolean
15 16 17 |
# File 'lib/scout_apm/instruments/moped.rb', line 15 def installed? @installed end |
#logger ⇒ Object
11 12 13 |
# File 'lib/scout_apm/instruments/moped.rb', line 11 def logger context.logger end |