class Fbe::Middleware::Trace
- License
- MIT
Copyright - Copyright © 2024-2025 Zerocracy
Author -
Yegor Bugayenko (yegor256@gmail.com)<br><br>trace.first #=> 200<br>trace.first #=> ‘example.com/api/endpoint’<br>trace.first[:method] #=> :get
connection.get(‘/api/endpoint’)
end
f.use Fbe::Middleware::Trace, trace
connection = Faraday.new do |f|
trace = []
@example Usage in Faraday middleware stack
monitoring purposes.
capturing method, URL, status, and timing information for debugging and
This middleware records all HTTP requests and responses in a trace array,
Faraday middleware that traces all API calls.
- Copyright © 2024-2025 Zerocracy
- MIT
def call(env)
-
(Faraday::Response)
- The response from the next middleware
Parameters:
-
env
(Faraday::Env
) -- The request environment
def call(env) entry = { method: env.method, url: env.url.to_s, started_at: Time.now } @app.call(env).on_complete do |response_env| finished = Time.now duration = finished - entry[:started_at] entry[:status] = response_env.status entry[:finished_at] = finished entry[:duration] = duration @trace << entry end end
def initialize(app, trace)
-
trace
(Array
) -- The array to store trace entries -
app
(Object
) -- The next middleware in the stack
def initialize(app, trace) super(app) @trace = trace end