class Qs::Request::Tracker::FaradayMiddleware
Constants
- THREAD_LOCAL_MISMATCH_MESSAGES
Public Class Methods
new(app, options = {})
click to toggle source
Calls superclass method
# File lib/qs/request/tracker/faraday_middleware.rb, line 6 def initialize(app, options = {}) super(app) end
Public Instance Methods
call(env)
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 10 def call(env) annotate_env_with_request_id!(env) if thread_local_request_id @app.call(env) end
Protected Instance Methods
annotate_env_with_request_id!(env)
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 16 def annotate_env_with_request_id!(env) log_request_mismatch_error(env) unless request_ids_match?(env) env[:request_headers][HTTP_HEADER_FIELD] = thread_local_request_id end
headers_request_id(env)
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 30 def headers_request_id(env) env[:request_headers][HTTP_HEADER_FIELD] end
log_request_mismatch_error(env)
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 34 def log_request_mismatch_error(env) STDERR.puts(THREAD_LOCAL_MISMATCH_MESSAGES % [thread_local_request_id.inspect, headers_request_id(env).inspect]) end
request_ids_match?(env)
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 21 def request_ids_match?(env) return true unless headers_request_id(env) (thread_local_request_id && thread_local_request_id == headers_request_id(env)) end
thread_local_request_id()
click to toggle source
# File lib/qs/request/tracker/faraday_middleware.rb, line 26 def thread_local_request_id Qs::Request::Tracker.thread_request_id end