Class: ScoutApm::InstrumentManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ InstrumentManager

Returns a new instance of InstrumentManager.



7
8
9
10
# File 'lib/scout_apm/instrument_manager.rb', line 7

def initialize(context)
  @context = context
  @installed_instruments = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/scout_apm/instrument_manager.rb', line 3

def context
  @context
end

#installed_instrumentsObject (readonly)

Returns the value of attribute installed_instruments.



5
6
7
# File 'lib/scout_apm/instrument_manager.rb', line 5

def installed_instruments
  @installed_instruments
end

Instance Method Details

#install!Object

Loads the instrumention logic.



13
14
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
45
46
# File 'lib/scout_apm/instrument_manager.rb', line 13

def install!
  case framework
  when :rails then
    install_instrument(ScoutApm::Instruments::ActionControllerRails2)
  when :rails3_or_4 then
    install_instrument(ScoutApm::Instruments::ActionControllerRails3Rails4)
    install_instrument(ScoutApm::Instruments::RailsRouter)

    if config.value("detailed_middleware")
      install_instrument(ScoutApm::Instruments::MiddlewareDetailed)
    else
      install_instrument(ScoutApm::Instruments::MiddlewareSummary)
    end
  end

  install_instrument(ScoutApm::Instruments::ActionView)
  install_instrument(ScoutApm::Instruments::ActiveRecord)
  install_instrument(ScoutApm::Instruments::Moped)
  install_instrument(ScoutApm::Instruments::Mongoid)
  install_instrument(ScoutApm::Instruments::NetHttp)
  install_instrument(ScoutApm::Instruments::Typhoeus)
  install_instrument(ScoutApm::Instruments::HttpClient)
  install_instrument(ScoutApm::Instruments::HTTP)
  install_instrument(ScoutApm::Instruments::Memcached)
  install_instrument(ScoutApm::Instruments::Redis)
  install_instrument(ScoutApm::Instruments::Redis5)
  install_instrument(ScoutApm::Instruments::InfluxDB)
  install_instrument(ScoutApm::Instruments::Elasticsearch)
  install_instrument(ScoutApm::Instruments::Grape)
rescue
  logger.warn "Exception loading instruments:"
  logger.warn $!.message
  logger.warn $!.backtrace
end

#prepend_for_instrument?(instrument_klass) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/scout_apm/instrument_manager.rb', line 54

def prepend_for_instrument?(instrument_klass)
  instrument_short_name = instrument_klass.name.split("::").last

  # `use_prepend` defaults to false, which means we use `alias_method` by default.
  # If `use_prepend` is `true`, then we should default to using `prepend` unless
  # the instrument is explicitly listed in the `alias_method_instruments` config array.
  if config.value("use_prepend")
    return false if (config.value("alias_method_instruments") || []).include?(instrument_short_name)
    return true
  else
    # `use_prepend` is false, but we should use `prepend` if the instrument is
    # explicitly listed in the `prepend_instruments` array.
    return true if (config.value("prepend_instruments") || []).include?(instrument_short_name)
    return false
  end
end

#skip_instrument?(instrument_klass) ⇒ Boolean

Allows users to skip individual instruments via the config file

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/scout_apm/instrument_manager.rb', line 49

def skip_instrument?(instrument_klass)
  instrument_short_name = instrument_klass.name.split("::").last
  (config.value("disabled_instruments") || []).include?(instrument_short_name)
end