Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from airbrake/curb-integration
rack: add support for Curb for HTTP performance breakdown
- Loading branch information
Showing
9 changed files
with
180 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Curl | ||
# Monkey-patch to measure request timing. | ||
class Easy | ||
alias http_without_airbrake http | ||
|
||
def http(verb) | ||
Airbrake::Rack.capture_http_performance do | ||
http_without_airbrake(verb) | ||
end | ||
end | ||
|
||
alias perform_without_airbrake perform | ||
|
||
def perform(&block) | ||
Airbrake::Rack.capture_http_performance do | ||
perform_without_airbrake(&block) | ||
end | ||
end | ||
end | ||
end | ||
|
||
module Curl | ||
# Monkey-patch to measure request timing. | ||
class Multi | ||
class << self | ||
alias http_without_airbrake http | ||
|
||
def http(urls_with_config, multi_options = {}, &block) | ||
Airbrake::Rack.capture_http_performance do | ||
http_without_airbrake(urls_with_config, multi_options, &block) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,10 @@ | ||
require 'net/http' | ||
|
||
# Monkey-patch Net::HTTP to benchmark it. | ||
Net::HTTP.class_eval do | ||
alias_method :request_without_airbrake, :request | ||
|
||
def request(request, *args, &block) | ||
routes = Airbrake::Rack::RequestStore[:routes] | ||
if !routes || routes.none? | ||
response = request_without_airbrake(request, *args, &block) | ||
else | ||
elapsed = Airbrake::Benchmark.measure do | ||
response = request_without_airbrake(request, *args, &block) | ||
end | ||
|
||
routes.each do |route_path, _params| | ||
Airbrake::Rack::RequestStore[:routes][route_path][:groups][:http] = elapsed | ||
end | ||
Airbrake::Rack.capture_http_performance do | ||
request_without_airbrake(request, *args, &block) | ||
end | ||
|
||
response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
RSpec.describe Airbrake::Rack do | ||
describe ".capture_http_performance" do | ||
context "when request store doesn't have any routes" do | ||
before { Airbrake::Rack::RequestStore.clear } | ||
|
||
it "doesn't store http time" do | ||
described_class.capture_http_performance {} | ||
expect(Airbrake::Rack::RequestStore.store).to be_empty | ||
end | ||
|
||
it "returns what the given block returns" do | ||
expect(described_class.capture_http_performance { 1 }).to eq(1) | ||
end | ||
end | ||
|
||
context "when request store has a route" do | ||
let(:routes) { Airbrake::Rack::RequestStore[:routes] } | ||
|
||
before do | ||
Airbrake::Rack::RequestStore[:routes] = { | ||
'/about' => { | ||
method: 'GET', | ||
response_type: :html, | ||
groups: {} | ||
} | ||
} | ||
end | ||
|
||
after { Airbrake::Rack::RequestStore.clear } | ||
|
||
it "attaches http timing to the route" do | ||
described_class.capture_http_performance {} | ||
expect(routes['/about'][:groups][:http]).to be > 0 | ||
end | ||
end | ||
end | ||
end |