Class: EpsagonFaradayMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/instrumentation/epsagon_faraday_middleware.rb

Overview

Faraday middleware for epsagon instrumentaton

Constant Summary collapse

HTTP_METHODS_SYMBOL_TO_STRING =
{
  connect: 'CONNECT',
  delete: 'DELETE',
  get: 'GET',
  head: 'HEAD',
  options: 'OPTIONS',
  patch: 'PATCH',
  post: 'POST',
  put: 'PUT',
  trace: 'TRACE'
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



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
52
53
54
55
56
# File 'lib/instrumentation/epsagon_faraday_middleware.rb', line 26

def call(env)
  http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
  path, path_params = env.url.path.split(';')

  attributes = {
    'type' => 'http',
    'operation' => http_method,
    'http.scheme' => env.url.scheme,
    'http.request.path' => path
  }

  unless config[:epsagon][:metadata_only]
    attributes.merge!(Util.epsagon_query_attributes(env.url.query))
    attributes.merge!({
      'http.request.path_params' => path_params,
      'http.request.headers' => Hash[env.request_headers],
      'http.request.body' => env.body,
      'http.request.headers.User-Agent' => env.request_headers['User-Agent']
    })
  end

  tracer.in_span(
    env.url.host,
    attributes: attributes,
    kind: :client
  ) do |span|
    OpenTelemetry.propagation.http.inject(env.request_headers)

    app.call(env).on_complete { |req| trace_response(span, req.response) }
  end
end

#configObject



10
11
12
# File 'lib/instrumentation/epsagon_faraday_middleware.rb', line 10

def config
  EpsagonFaradayInstrumentation.instance.config
end