1 2 3 4 5 6 7 8 9 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
|
# frozen_string_literal: true
module Excon
module Middleware
class Instrumentor < Excon::Middleware::Base
def self.valid_parameter_keys
[
:logger,
:instrumentor,
:instrumentor_name
]
end
def error_call(datum)
if datum.has_key?(:instrumentor)
datum[:instrumentor].instrument("#{datum[:instrumentor_name]}.error", :error => datum[:error]) do
@stack.error_call(datum)
end
else
@stack.error_call(datum)
end
end
def request_call(datum)
if datum.has_key?(:instrumentor)
if datum[:retries_remaining] < datum[:retry_limit]
event_name = "#{datum[:instrumentor_name]}.retry"
else
event_name = "#{datum[:instrumentor_name]}.request"
end
datum[:instrumentor].instrument(event_name, datum) do
@stack.request_call(datum)
end
else
@stack.request_call(datum)
end
end
def response_call(datum)
if datum.has_key?(:instrumentor)
datum[:instrumentor].instrument("#{datum[:instrumentor_name]}.response", datum[:response]) do
@stack.response_call(datum)
end
else
@stack.response_call(datum)
end
end
end
end
end
|