Module: HTTPX::Plugins::Tracing::RequestMethods

Defined in:
lib/httpx/plugins/tracing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#init_timeObject

Returns the value of attribute init_time.



71
72
73
# File 'lib/httpx/plugins/tracing.rb', line 71

def init_time
  @init_time
end

Instance Method Details

#initializeObject

intercepts request initialization to inject the tracing logic.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/httpx/plugins/tracing.rb', line 74

def initialize(*)
  super

  @init_time = nil

  tracer = @options.tracer

  return unless tracer && tracer.enabled?(self)

  on(:idle) do
    tracer.reset(self)

    # request is reset when it's retried.
    @init_time = nil
  end
  on(:headers) do
    # the usual request init time (when not including the connection handshake)
    # should be the time the request is buffered the first time.
    @init_time ||= ::Time.now.utc

    tracer.start(self)
  end
  on(:response) { |response| tracer.finish(self, response) }
end

#response=Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/httpx/plugins/tracing.rb', line 99

def response=(*)
  # init_time should be set when it's send to a connection.
  # However, there are situations where connection initialization fails.
  # Example is the :ssrf_filter plugin, which raises an error on
  # initialize if the host is an IP which matches against the known set.
  # in such cases, we'll just set here right here.
  @init_time ||= ::Time.now.utc

  super
end