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

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

Overview

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

Constant Summary collapse

HTTP_STATUS_SUCCESS_RANGE =

Constant for the HTTP status range

(100..399)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject (readonly)

Versions prior to 1.0 do not define an accessor for app



65
66
67
# File 'lib/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware.rb', line 65

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  span_data = HttpHelper.span_attrs_for(env.method, semconv: :old)

  config = Faraday::Instrumentation.instance.config

  attributes = span_creation_attributes(
    http_method: span_data.normalized_method, url: env.url, config: config
  )

  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
    tracer.in_span(
      span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
    ) do |span|
      OpenTelemetry.propagation.inject(env.request_headers)

      if config[:enable_internal_instrumentation] == false
        OpenTelemetry::Common::Utilities.untraced do
          app.call(env).on_complete { |resp| trace_response(span, resp.status) }
        end
      else
        app.call(env).on_complete { |resp| trace_response(span, resp.status) }
      end
    rescue ::Faraday::Error => e
      trace_response(span, e.response[:status]) if e.response

      raise
    end
  end
end