Class: StackifyRubyAPM::Spies::HTTPartySpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/httparty.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
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
47
48
49
50
51
52
53
54
55
# File 'lib/stackify_apm/spies/httparty.rb', line 12

def install
  # puts HTTParty::ClassMethods.instance_methods(false).inspect
  HTTParty::ClassMethods.module_eval do
    alias_method 'perform_request_without_apm', 'perform_request'

    # singleton_class.send(:alias_method, :perform_request_without_apm, :perform_request)

    private :perform_request

    def perform_request(http_method, path, options, &block)
      req = nil
      return perform_request_without_apm(http_method, path, options, &block) unless StackifyRubyAPM.current_transaction
      # Data configuration
      #
      method = http_method.to_s.gsub('Net::HTTP::', '').upcase
      uri = path.strip
      name = "#{method} #{uri}"
      type = "ext.HTTParty.#{method}"
      # Submits HTTP request
      #
      # req = perform_request_without_apm(http_method, path, options, &block)
      # Builds span context
      #
      # status_code = req.code

      ctx = Span::Context.new(
        CATEGORY: 'Web External',
        SUBCATEGORY: 'Execute',
        URL: uri,
        STATUS: '',
        METHOD: method
      )
      # Creates new span from HTTP result
      #
      # class_info = { 'classname' => 'httparty', 'hostname' => URI.parse(uri).host }
      StackifyRubyAPM.span name, type, context: ctx do
        req = perform_request_without_apm(http_method, path, options, &block)
        status_code = req.code
        ctx.update_status(status_code)
        req
      end
    end
  end
end