Class: LogBrew::NetHttpTracingClient

Inherits:
Object
  • Object
show all
Defined in:
lib/logbrew/http_client_tracing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http, client:, on_capture_error: nil) ⇒ NetHttpTracingClient

Returns a new instance of NetHttpTracingClient.



83
84
85
86
87
# File 'lib/logbrew/http_client_tracing.rb', line 83

def initialize(http, client:, on_capture_error: nil)
  @http = http
  @client = client
  @on_capture_error = on_capture_error
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object



107
108
109
110
111
# File 'lib/logbrew/http_client_tracing.rb', line 107

def method_missing(name, *arguments, &block)
  return super unless @http.respond_to?(name)

  @http.public_send(name, *arguments, &block)
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



81
82
83
# File 'lib/logbrew/http_client_tracing.rb', line 81

def http
  @http
end

Instance Method Details

#request(request, body = nil, &block) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/logbrew/http_client_tracing.rb', line 89

def request(request, body = nil, &block)
  HttpClientTracing.capture_net_http(
    @http,
    request,
    client: @client,
    on_capture_error: @on_capture_error
  ) { @http.request(request, body, &block) }
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/logbrew/http_client_tracing.rb', line 113

def respond_to_missing?(name, include_private = false)
  @http.respond_to?(name, include_private) || super
end

#start(*arguments) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/logbrew/http_client_tracing.rb', line 98

def start(*arguments)
  unless block_given?
    started = @http.start(*arguments)
    return started.equal?(@http) ? self : started
  end

  @http.start(*arguments) { yield self }
end