Class: StackifyRubyAPM::Spies::CurbMultiSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/curb/multi.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.



10
11
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
# File 'lib/stackify_apm/spies/curb/multi.rb', line 10

def install
  Curl::Multi.class_eval do
    singleton_class.send(:alias_method, :http_without_apm, :http)

    def self.http(urls_with_config, _multi_options = {}, &blk)
      return http_without_apm(urls_with_config, _multi_options = {}, &blk) unless StackifyRubyAPM.current_transaction
      http_without_apm(urls_with_config, _multi_options = {}) do |c, code, method|
        begin
          status_code = code.zero? ? 404 : code
          method = method.upcase
          uri = c.url.to_s.strip
          name = "#{method} #{uri}"
          type = "ext.Curb.Multi.#{method}"

          ctx = Span::Context.new(
            CATEGORY: 'Web External',
            SUBCATEGORY: 'Execute',
            URL: uri,
            STATUS: status_code,
            METHOD: method
          )

          if StackifyRubyAPM.agent.config.prefix_enabled
            ctx.update_request_body(c.post_body || "")
            ctx.update_request_headers(c.headers || Hash.new)
            ctx.update_response_body(c.body || "")
            ctx.update_response_headers(c.proxy_headers || Hash.new)
          end
        rescue Exception => e
          StackifyRubyAPM.agent.error "[CurbMultiSpy] Error: creating span context."
          StackifyRubyAPM.agent.error "[CurbMultiSpy] #{e.inspect}"
          return blk.call(c, code, method)
        end

        # Creates new span from HTTP result
        StackifyRubyAPM.span name, type, context: ctx do
          blk.call(c, code, method)
        end
      end
    end
  end
end