-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rails/net_http: monkey-patch with prepend instead of method chaining
Fixes #1077 (Airbrake's new Performance metrics instrumentation leads to infinite loop with Datadog) Since we don't care about Ruby 1.9 support, we can safely rely on `prepend` to monkey-patch methods safely. This is more robust because nobody will overwrite our implementation (unless they forget to call `super`) and we will also respect other libraries that monkey-patch `Net::HTTP#request`.
- Loading branch information
Showing
2 changed files
with
15 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# Monkey-patch Net::HTTP to benchmark it. | ||
Net::HTTP.class_eval do | ||
alias_method :request_without_airbrake, :request | ||
|
||
def request(request, *args, &block) | ||
Airbrake::Rack.capture_timing(:http) do | ||
request_without_airbrake(request, *args, &block) | ||
module Airbrake | ||
module Rails | ||
# Monkey-patch Net::HTTP to benchmark it. | ||
# @api private | ||
# @since v10.0.2 | ||
module NetHttp | ||
def request(request, *args, &block) | ||
Airbrake::Rack.capture_timing(:http) do | ||
super(request, *args, &block) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Net::HTTP.prepend(Airbrake::Rails::NetHttp) |