Class: OpenTelemetry::Instrumentation::Faraday::Middlewares::TracerMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb

Overview

TracerMiddleware propagates context and instruments Faraday requests by way of its middlware system

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
# File 'lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb', line 26

def call(env)
  http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
  attributes = span_creation_attributes(
    http_method: http_method, url: env.url
  )
  tracer.in_span(
    "HTTP #{http_method}", attributes: attributes, kind: :client
  ) do |span|
    OpenTelemetry.propagation.inject(env.request_headers)

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