Skip to content

Commit

Permalink
Merge pull request #7 from instrumentl/expose-timings
Browse files Browse the repository at this point in the history
feat: expose libcurl timings in the faraday env
  • Loading branch information
dleavitt authored Oct 20, 2023
2 parents c1faf4b + abd7df8 commit 17ed8e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/faraday/adapter/typhoeus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def request(env)
end
end

env[:typhoeus_timings] = %i[
appconnect connect namelookup pretransfer redirect starttransfer total
].to_h do |key|
[key, resp.public_send("#{key}_time")]
end

save_response(env, resp.code, resp.body, nil, resp.status_message) do |response_headers|
response_headers.parse resp.response_headers
end
Expand Down
14 changes: 14 additions & 0 deletions spec/faraday/adapter/typhoeus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@
it 'succeeds' do
expect(conn.get('/').status).to be(200)
end

it 'sets timings' do
response = conn.get('/')
# TODO: make these not-nil after https://github.com/bblimke/webmock/pull/1038 lands
expect(response.env.custom_members[:typhoeus_timings]).to eq({
appconnect: nil,
connect: nil,
namelookup: nil,
pretransfer: nil,
redirect: nil,
starttransfer: nil,
total: nil
})
end
end

context 'failed connection' do
Expand Down

0 comments on commit 17ed8e5

Please sign in to comment.