Class: OpenTelemetry::Instrumentation::Faraday::Middlewares::Stable::TracerMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- OpenTelemetry::Instrumentation::Faraday::Middlewares::Stable::TracerMiddleware
- Defined in:
- lib/opentelemetry/instrumentation/faraday/middlewares/stable/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
-
#app ⇒ Object
readonly
Versions prior to 1.0 do not define an accessor for app.
Instance Method Summary collapse
Instance Attribute Details
#app ⇒ Object (readonly)
Versions prior to 1.0 do not define an accessor for app
69 70 71 |
# File 'lib/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware.rb', line 69 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 47 48 49 |
# File 'lib/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware.rb', line 18 def call(env) span_data = HttpHelper.span_attrs_for(env.method) config = Faraday::Instrumentation.instance.config attributes = span_creation_attributes( http_method: span_data.normalized_method, original_method: span_data.original_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 |