class OpenTracing::Instrumentation::Faraday::TraceMiddleware
TraceMiddleware
inject tracing header into request and trace request
Usage with default config:
Faraday.new(url) do |connection| connection.use \ OpenTracing::Instrumentation::Faraday::TraceMiddleware end
Usage with config block:
Faraday.new(url) do |connection| connection.use \ OpenTracing::Instrumentation::Faraday::TraceMiddleware do |c| # c is instance of Config c.tracer = tracer end end
Public Class Methods
new( app, config = Config.new ) { |config| ... }
click to toggle source
@param config [Config]
@yieldparam config [Config]
# File lib/opentracing/instrumentation/faraday/trace_middleware.rb, line 82 def initialize( app, config = Config.new ) @app = app @config = config yield(config) if block_given? end
Public Instance Methods
call(env)
click to toggle source
Wrap Faraday
request to trace it with OpenTracing
@param env [Faraday::Env] @return [Faraday::Response]
# File lib/opentracing/instrumentation/faraday/trace_middleware.rb, line 94 def call(env) trace_request(env) do |span| inject_tracing(span, env) if inject response_logger&.log_request(span, env.request_headers) @app.call(env).on_complete do |response| set_response_tags(span, response) response_logger&.log_response(span, response.response_headers) end end end
Private Instance Methods
build_scope(env)
click to toggle source
# File lib/opentracing/instrumentation/faraday/trace_middleware.rb, line 128 def build_scope(env) tracer.start_active_span( operation_name, tags: request_tags(env), ) end
inject_tracing(span, env)
click to toggle source
# File lib/opentracing/instrumentation/faraday/trace_middleware.rb, line 135 def inject_tracing(span, env) tracer.inject( span.context, OpenTracing::FORMAT_RACK, env[:request_headers], ) end
trace_request(env) { |span| ... }
click to toggle source
# File lib/opentracing/instrumentation/faraday/trace_middleware.rb, line 116 def trace_request(env) scope = build_scope(env) span = scope.span yield(span) rescue *expected_errors => e set_exception_tags(span, e) raise ensure scope.close end