Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Faraday warnings on v0.x #971

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'sucker_punch'
gem 'typhoeus'
end

appraise 'contrib-old' do
gem 'faraday', '0.17'
end
end
elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
Expand Down Expand Up @@ -591,6 +595,10 @@ elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'sucker_punch'
gem 'typhoeus'
end

appraise 'contrib-old' do
gem 'faraday', '0.17'
end
end
elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
Expand Down Expand Up @@ -698,6 +706,10 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'sucker_punch'
gem 'typhoeus'
end

appraise 'contrib-old' do
gem 'faraday', '0.17'
end
end
elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
Expand Down Expand Up @@ -806,6 +818,10 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'sucker_punch'
gem 'typhoeus'
end

appraise 'contrib-old' do
gem 'faraday', '0.17'
end
end
elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION)
if RUBY_PLATFORM != 'java'
Expand Down Expand Up @@ -916,5 +932,9 @@ elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION)
gem 'sucker_punch'
gem 'typhoeus'
end

appraise 'contrib-old' do
gem 'faraday', '0.17'
end
end
end
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:shoryuken'
sh 'bundle exec appraisal contrib rake spec:sinatra'
sh 'bundle exec appraisal contrib rake spec:ethon'
# Contrib specs with old gem versions
sh 'bundle exec appraisal contrib-old rake spec:faraday'
# Rails minitests
sh 'bundle exec appraisal rails30-postgres rake test:rails'
sh 'bundle exec appraisal rails30-postgres rake spec:railsdisableenv'
Expand Down Expand Up @@ -451,6 +453,8 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:shoryuken'
sh 'bundle exec appraisal contrib rake spec:sinatra'
sh 'bundle exec appraisal contrib rake spec:ethon'
# Contrib specs with old gem versions
sh 'bundle exec appraisal contrib-old rake spec:faraday'
# Rails minitests
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
Expand Down Expand Up @@ -506,6 +510,8 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:shoryuken'
sh 'bundle exec appraisal contrib rake spec:sinatra'
sh 'bundle exec appraisal contrib rake spec:ethon'
# Contrib specs with old gem versions
sh 'bundle exec appraisal contrib-old rake spec:faraday'
# Rails minitests
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
Expand Down Expand Up @@ -571,6 +577,8 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:shoryuken'
sh 'bundle exec appraisal contrib rake spec:sinatra'
sh 'bundle exec appraisal contrib rake spec:ethon'
# Contrib specs with old gem versions
sh 'bundle exec appraisal contrib-old rake spec:faraday'
# Rails minitests
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
Expand Down Expand Up @@ -635,6 +643,8 @@ task :ci do
sh 'bundle exec appraisal contrib rake spec:shoryuken'
sh 'bundle exec appraisal contrib rake spec:sinatra'
sh 'bundle exec appraisal contrib rake spec:ethon'
# Contrib specs with old gem versions
sh 'bundle exec appraisal contrib-old rake spec:faraday'
# Rails minitests
# We only test Rails 5+ because older versions require Bundler < 2.0
sh 'bundle exec appraisal rails5-mysql2 rake test:rails'
Expand Down
7 changes: 6 additions & 1 deletion lib/ddtrace/contrib/faraday/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/faraday/ext'
require 'ddtrace/contrib/faraday/connection'
require 'ddtrace/contrib/faraday/rack_builder'

module Datadog
module Contrib
Expand Down Expand Up @@ -39,7 +40,11 @@ def register_middleware!
end

def add_default_middleware!
::Faraday::Connection.send(:prepend, Connection)
if target_version >= Gem::Version.new('1.0.0')
::Faraday::Connection.send(:prepend, Connection)
else
::Faraday::RackBuilder.send(:prepend, RackBuilder)
end
end

def get_option(option)
Expand Down
18 changes: 18 additions & 0 deletions lib/ddtrace/contrib/faraday/rack_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Datadog
module Contrib
module Faraday
# Handles installation of our middleware if the user has *not*
# already explicitly configured it for this correction.
#
# RackBuilder class was introduced in faraday 0.9.0:
# https://github.com/lostisland/faraday/commit/77d7546d6d626b91086f427c56bc2cdd951353b3
module RackBuilder
def adapter(*args)
use(:ddtrace) unless @handlers.any? { |h| h.klass == Middleware }

super
end
end
end
end
end
6 changes: 5 additions & 1 deletion spec/ddtrace/contrib/faraday/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end

context 'without explicit middleware configured' do
subject!(:response) { client.get('/success') }
subject(:response) { client.get('/success') }
let(:use_middleware) { false }

it 'uses default configuration' do
Expand All @@ -60,6 +60,10 @@
expect(request_span.span_type).to eq(Datadog::Ext::HTTP::TYPE_OUTBOUND)
expect(request_span).to_not have_error
end

it 'executes without warnings' do
expect { response }.to_not output(/WARNING/).to_stderr
end
end

context 'when there is no interference' do
Expand Down