Class: HubStep::Faraday::Middleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- HubStep::Faraday::Middleware
- Defined in:
- lib/hubstep/faraday/middleware.rb
Overview
Faraday middleware for wrapping a request in a span.
tracer = HubStep::Tracer.new Faraday.new do |b|
b.request(:hubstep, tracer)
b.adapter(:typhoeus)
end
Class Attribute Summary collapse
-
.uri_parser ⇒ Object
Get the URI parser.
Instance Method Summary collapse
- #call(request_env) ⇒ Object
-
#initialize(app, tracer, include_urls: false) ⇒ Middleware
constructor
Create a Middleware.
Constructor Details
#initialize(app, tracer, include_urls: false) ⇒ Middleware
Create a Middleware
tracer - a HubStep::Tracer instance include_urls - Boolean specifying whether the ‘http.url` tag should be
added to the spans this middleware creates. URLs can
contain sensitive information, so they are omitted by
default.
42 43 44 45 46 |
# File 'lib/hubstep/faraday/middleware.rb', line 42 def initialize(app, tracer, include_urls: false) super(app) @tracer = tracer @include_urls = include_urls end |
Class Attribute Details
.uri_parser ⇒ Object
Get the URI parser.
29 30 31 |
# File 'lib/hubstep/faraday/middleware.rb', line 29 def uri_parser @uri_parser end |
Instance Method Details
#call(request_env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hubstep/faraday/middleware.rb', line 48 def call(request_env) # We pass `finish: false` so that the span won't have its end time # recorded until #on_complete runs (which could be after #call returns # if the request is asynchronous). @tracer.span("faraday", finish: false) do |span| begin span.configure { record_request(span, request_env) } @app.call(request_env).on_complete do |response_env| span.configure do record_response(span, response_env) span.finish if span.end_micros.nil? end end ensure span.configure { record_exception(span, $ERROR_INFO) } end end end |