Class: Honeycomb::Faraday

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/honeycomb/integrations/faraday.rb

Overview

Faraday middleware to create spans around outgoing http requests

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ Faraday

Returns a new instance of Faraday.



8
9
10
11
# File 'lib/honeycomb/integrations/faraday.rb', line 8

def initialize(app, options)
  super(app)
  @client = options[:client]
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/honeycomb/integrations/faraday.rb', line 13

def call(env)
  return @app.call(env) if @client.nil?

  @client.start_span(name: "http_client") do |span|
    span.add_field "request.method", env.method.upcase
    span.add_field "request.scheme", env.url.scheme
    span.add_field "request.host", env.url.host
    span.add_field "request.path", env.url.path
    span.add_field "meta.type", "http_client"
    span.add_field "meta.package", "faraday"
    span.add_field "meta.package_version", ::Faraday::VERSION

    if (headers = span.trace_headers(env)).is_a?(Hash)
      env.request_headers.merge!(headers)
    end

    @app.call(env).tap do |response|
      span.add_field "response.status_code", response.status
    end
  end
end