Class: ScoutApm::Instruments::NetHttp
- Inherits:
-
Object
- Object
- ScoutApm::Instruments::NetHttp
- Defined in:
- lib/scout_apm/instruments/net_http.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(context) ⇒ NetHttp
constructor
A new instance of NetHttp.
- #install(prepend:) ⇒ Object
- #installed? ⇒ Boolean
- #logger ⇒ Object
Constructor Details
#initialize(context) ⇒ NetHttp
Returns a new instance of NetHttp.
6 7 8 9 |
# File 'lib/scout_apm/instruments/net_http.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/net_http.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 55 56 57 58 |
# File 'lib/scout_apm/instruments/net_http.rb', line 19 def install(prepend:) if defined?(::Net) && defined?(::Net::HTTP) @installed = true logger.info "Instrumenting Net::HTTP. Prepend: #{prepend}" if prepend ::Net::HTTP.send(:include, ScoutApm::Tracer) ::Net::HTTP.send(:prepend, NetHttpInstrumentationPrepend) else ::Net::HTTP.class_eval do include ScoutApm::Tracer def request_with_scout_instruments(*args, &block) self.class.instrument("HTTP", "request", :ignore_children => true, :desc => request_scout_description(args.first)) do request_without_scout_instruments(*args, &block) end end def request_scout_description(req) path = req.path path = path.path if path.respond_to?(:path) # Protect against a nil address value if @address.nil? return "No Address Found" end max_length = ScoutApm::Agent.instance.context.config.value('instrument_http_url_length') (@address + path.split('?').first)[0..(max_length - 1)] rescue "" end alias request_without_scout_instruments request alias request request_with_scout_instruments end end end end |
#installed? ⇒ Boolean
15 16 17 |
# File 'lib/scout_apm/instruments/net_http.rb', line 15 def installed? @installed end |
#logger ⇒ Object
11 12 13 |
# File 'lib/scout_apm/instruments/net_http.rb', line 11 def logger context.logger end |