From c33dc355799694db7d1914971b97d0038451ad25 Mon Sep 17 00:00:00 2001 From: David Elner Date: Mon, 17 Dec 2018 12:17:03 -0500 Subject: [PATCH] Fixed: Priority sampling with specs. --- spec/ddtrace/configuration/pin_setup_spec.rb | 2 +- spec/ddtrace/context_spec.rb | 2 +- .../active_model_serializers/patcher_spec.rb | 2 +- .../contrib/active_record/multi_db_spec.rb | 2 +- .../contrib/active_record/performance_spec.rb | 2 +- .../contrib/active_record/tracer_spec.rb | 2 +- .../notifications/subscription_spec.rb | 2 +- .../contrib/aws/instrumentation_spec.rb | 2 +- .../concurrent_ruby/integration_spec.rb | 2 +- .../contrib/dalli/instrumentation_spec.rb | 2 +- .../contrib/delayed_job/plugin_spec.rb | 2 +- .../contrib/elasticsearch/patcher_spec.rb | 2 +- .../contrib/elasticsearch/transport_spec.rb | 2 +- .../contrib/excon/instrumentation_spec.rb | 2 +- .../contrib/faraday/middleware_spec.rb | 2 +- spec/ddtrace/contrib/graphql/tracer_spec.rb | 2 +- spec/ddtrace/contrib/http/patcher_spec.rb | 2 +- spec/ddtrace/contrib/mongodb/client_spec.rb | 2 +- spec/ddtrace/contrib/mysql2/patcher_spec.rb | 2 +- spec/ddtrace/contrib/racecar/patcher_spec.rb | 2 +- spec/ddtrace/contrib/rack/distributed_spec.rb | 2 +- spec/ddtrace/contrib/rack/integration_spec.rb | 2 +- spec/ddtrace/contrib/rack/middleware_spec.rb | 2 +- .../contrib/rack/request_queuing_spec.rb | 2 +- .../contrib/rack/resource_name_spec.rb | 2 +- .../contrib/rails/action_controller_spec.rb | 2 +- spec/ddtrace/contrib/rails/middleware_spec.rb | 2 +- spec/ddtrace/contrib/rails/railtie_spec.rb | 2 +- .../contrib/rake/instrumentation_spec.rb | 2 +- spec/ddtrace/contrib/redis/miniapp_spec.rb | 2 +- spec/ddtrace/contrib/redis/redis_spec.rb | 2 +- .../contrib/resque/instrumentation_spec.rb | 2 +- .../contrib/rest_client/request_patch_spec.rb | 2 +- .../contrib/sequel/configuration_spec.rb | 2 +- .../contrib/sequel/instrumentation_spec.rb | 2 +- spec/ddtrace/contrib/shoryuken/tracer_spec.rb | 2 +- .../contrib/sinatra/activerecord_spec.rb | 2 +- .../ddtrace/contrib/sinatra/multi_app_spec.rb | 2 +- spec/ddtrace/contrib/sinatra/tracer_spec.rb | 4 +-- spec/ddtrace/integration_spec.rb | 12 ++----- spec/ddtrace/pin_spec.rb | 4 +-- .../propagation/http_propagator_spec.rb | 2 +- .../propagation_integration_spec.rb | 2 +- spec/support/tracer_helpers.rb | 35 +++++++++++++++++-- 44 files changed, 80 insertions(+), 55 deletions(-) diff --git a/spec/ddtrace/configuration/pin_setup_spec.rb b/spec/ddtrace/configuration/pin_setup_spec.rb index ab3bbf732f0..d9d3d89bf0f 100644 --- a/spec/ddtrace/configuration/pin_setup_spec.rb +++ b/spec/ddtrace/configuration/pin_setup_spec.rb @@ -24,7 +24,7 @@ } end - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } it do expect(target.datadog_pin.service).to eq('my-service') diff --git a/spec/ddtrace/context_spec.rb b/spec/ddtrace/context_spec.rb index acf986d598b..677df748037 100644 --- a/spec/ddtrace/context_spec.rb +++ b/spec/ddtrace/context_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Datadog::Context do subject(:context) { described_class.new(options) } let(:options) { {} } - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } describe '#current_root_span' do subject(:current_root_span) { context.current_root_span } diff --git a/spec/ddtrace/contrib/active_model_serializers/patcher_spec.rb b/spec/ddtrace/contrib/active_model_serializers/patcher_spec.rb index eb17b8d37d2..28ddf0c5ff8 100644 --- a/spec/ddtrace/contrib/active_model_serializers/patcher_spec.rb +++ b/spec/ddtrace/contrib/active_model_serializers/patcher_spec.rb @@ -10,7 +10,7 @@ RSpec.describe 'ActiveModelSerializers patcher' do include_context 'AMS serializer' - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def all_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/active_record/multi_db_spec.rb b/spec/ddtrace/contrib/active_record/multi_db_spec.rb index 18dbf955f70..924b2df1a1c 100644 --- a/spec/ddtrace/contrib/active_record/multi_db_spec.rb +++ b/spec/ddtrace/contrib/active_record/multi_db_spec.rb @@ -6,7 +6,7 @@ require 'sqlite3' RSpec.describe 'ActiveRecord multi-database implementation' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer, service_name: default_db_service_name } } let(:default_db_service_name) { 'default-db' } diff --git a/spec/ddtrace/contrib/active_record/performance_spec.rb b/spec/ddtrace/contrib/active_record/performance_spec.rb index a1b4aac1f3d..aee3eaba788 100644 --- a/spec/ddtrace/contrib/active_record/performance_spec.rb +++ b/spec/ddtrace/contrib/active_record/performance_spec.rb @@ -5,7 +5,7 @@ require 'sqlite3' RSpec.describe 'ActiveRecord tracing performance' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:options) { { tracer: tracer } } let(:spans) { tracer.writer.spans } diff --git a/spec/ddtrace/contrib/active_record/tracer_spec.rb b/spec/ddtrace/contrib/active_record/tracer_spec.rb index 8ea9f479951..decef947731 100644 --- a/spec/ddtrace/contrib/active_record/tracer_spec.rb +++ b/spec/ddtrace/contrib/active_record/tracer_spec.rb @@ -4,7 +4,7 @@ require_relative 'app' RSpec.describe 'ActiveRecord instrumentation' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer } } before(:each) do diff --git a/spec/ddtrace/contrib/active_support/notifications/subscription_spec.rb b/spec/ddtrace/contrib/active_support/notifications/subscription_spec.rb index afee9f296e1..3e6fd6b27db 100644 --- a/spec/ddtrace/contrib/active_support/notifications/subscription_spec.rb +++ b/spec/ddtrace/contrib/active_support/notifications/subscription_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Datadog::Contrib::ActiveSupport::Notifications::Subscription do describe 'instance' do subject(:subscription) { described_class.new(tracer, span_name, options, &block) } - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:span_name) { double('span_name') } let(:options) { {} } let(:payload) { {} } diff --git a/spec/ddtrace/contrib/aws/instrumentation_spec.rb b/spec/ddtrace/contrib/aws/instrumentation_spec.rb index a7eed337119..36a46f61aea 100644 --- a/spec/ddtrace/contrib/aws/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/aws/instrumentation_spec.rb @@ -6,7 +6,7 @@ require 'ddtrace/ext/http' RSpec.describe 'AWS instrumentation' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:client) { ::Aws::S3::Client.new(stub_responses: responses) } let(:responses) { true } diff --git a/spec/ddtrace/contrib/concurrent_ruby/integration_spec.rb b/spec/ddtrace/contrib/concurrent_ruby/integration_spec.rb index b32bae667ad..0ea383c421b 100644 --- a/spec/ddtrace/contrib/concurrent_ruby/integration_spec.rb +++ b/spec/ddtrace/contrib/concurrent_ruby/integration_spec.rb @@ -12,7 +12,7 @@ remove_patch!(:concurrent_ruby) end - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer } } subject(:deferred_execution) do diff --git a/spec/ddtrace/contrib/dalli/instrumentation_spec.rb b/spec/ddtrace/contrib/dalli/instrumentation_spec.rb index f6592f73c46..a626ecb6b26 100644 --- a/spec/ddtrace/contrib/dalli/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/dalli/instrumentation_spec.rb @@ -9,7 +9,7 @@ let(:test_port) { ENV.fetch('TEST_MEMCACHED_PORT', '11211') } let(:client) { ::Dalli::Client.new("#{test_host}:#{test_port}") } - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:pin) { ::Dalli.datadog_pin } def all_spans diff --git a/spec/ddtrace/contrib/delayed_job/plugin_spec.rb b/spec/ddtrace/contrib/delayed_job/plugin_spec.rb index 23a70b01f69..1157c02bb07 100644 --- a/spec/ddtrace/contrib/delayed_job/plugin_spec.rb +++ b/spec/ddtrace/contrib/delayed_job/plugin_spec.rb @@ -24,7 +24,7 @@ def job_data end) end - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } before do Datadog.configure { |c| c.use :delayed_job, tracer: tracer } diff --git a/spec/ddtrace/contrib/elasticsearch/patcher_spec.rb b/spec/ddtrace/contrib/elasticsearch/patcher_spec.rb index e8798fea60e..2ad06417758 100644 --- a/spec/ddtrace/contrib/elasticsearch/patcher_spec.rb +++ b/spec/ddtrace/contrib/elasticsearch/patcher_spec.rb @@ -9,7 +9,7 @@ let(:client) { Elasticsearch::Client.new(url: server) } let(:pin) { Datadog::Pin.get_from(client) } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } before do Datadog.configure do |c| diff --git a/spec/ddtrace/contrib/elasticsearch/transport_spec.rb b/spec/ddtrace/contrib/elasticsearch/transport_spec.rb index dbe5206a475..e93b747b0f2 100644 --- a/spec/ddtrace/contrib/elasticsearch/transport_spec.rb +++ b/spec/ddtrace/contrib/elasticsearch/transport_spec.rb @@ -22,7 +22,7 @@ let(:server) { "http://#{host}:#{port}" } let(:client) { Elasticsearch::Client.new(url: server) } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:spans) { tracer.writer.spans } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/excon/instrumentation_spec.rb b/spec/ddtrace/contrib/excon/instrumentation_spec.rb index 9ab1d64abf0..452c2b7f73a 100644 --- a/spec/ddtrace/contrib/excon/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/excon/instrumentation_spec.rb @@ -5,7 +5,7 @@ require 'ddtrace/contrib/excon/middleware' RSpec.describe Datadog::Contrib::Excon::Middleware do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:connection_options) { { mock: true } } let(:middleware_options) { {} } diff --git a/spec/ddtrace/contrib/faraday/middleware_spec.rb b/spec/ddtrace/contrib/faraday/middleware_spec.rb index 04dc8bc6547..469c0dfa2bb 100644 --- a/spec/ddtrace/contrib/faraday/middleware_spec.rb +++ b/spec/ddtrace/contrib/faraday/middleware_spec.rb @@ -5,7 +5,7 @@ require 'ddtrace/ext/distributed' RSpec.describe 'Faraday middleware' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:client) do ::Faraday.new('http://example.com') do |builder| diff --git a/spec/ddtrace/contrib/graphql/tracer_spec.rb b/spec/ddtrace/contrib/graphql/tracer_spec.rb index 32c2e8af07a..9cb6651538f 100644 --- a/spec/ddtrace/contrib/graphql/tracer_spec.rb +++ b/spec/ddtrace/contrib/graphql/tracer_spec.rb @@ -14,7 +14,7 @@ end end - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def pop_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/http/patcher_spec.rb b/spec/ddtrace/contrib/http/patcher_spec.rb index 69dd7ff040d..e65b596f497 100644 --- a/spec/ddtrace/contrib/http/patcher_spec.rb +++ b/spec/ddtrace/contrib/http/patcher_spec.rb @@ -3,7 +3,7 @@ require 'net/http' RSpec.describe 'net/http patcher' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:host) { 'example.com' } before do diff --git a/spec/ddtrace/contrib/mongodb/client_spec.rb b/spec/ddtrace/contrib/mongodb/client_spec.rb index 04d83b8864f..7a7990c1b7c 100644 --- a/spec/ddtrace/contrib/mongodb/client_spec.rb +++ b/spec/ddtrace/contrib/mongodb/client_spec.rb @@ -4,7 +4,7 @@ require 'mongo' RSpec.describe 'Mongo::Client instrumentation' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:client) { Mongo::Client.new(*client_options) } let(:client_options) { [["#{host}:#{port}"], { database: database }] } diff --git a/spec/ddtrace/contrib/mysql2/patcher_spec.rb b/spec/ddtrace/contrib/mysql2/patcher_spec.rb index 44924f94219..c68e67f6691 100644 --- a/spec/ddtrace/contrib/mysql2/patcher_spec.rb +++ b/spec/ddtrace/contrib/mysql2/patcher_spec.rb @@ -4,7 +4,7 @@ require 'mysql2' RSpec.describe 'Mysql2::Client patcher' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:client) do Mysql2::Client.new( diff --git a/spec/ddtrace/contrib/racecar/patcher_spec.rb b/spec/ddtrace/contrib/racecar/patcher_spec.rb index 2679b4f87f0..e1a039e17a5 100644 --- a/spec/ddtrace/contrib/racecar/patcher_spec.rb +++ b/spec/ddtrace/contrib/racecar/patcher_spec.rb @@ -5,7 +5,7 @@ require 'active_support' require 'ddtrace' RSpec.describe 'Racecar patcher' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def all_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/rack/distributed_spec.rb b/spec/ddtrace/contrib/rack/distributed_spec.rb index 63bef3fbb5f..de13aa804b4 100644 --- a/spec/ddtrace/contrib/rack/distributed_spec.rb +++ b/spec/ddtrace/contrib/rack/distributed_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'Rack integration distributed tracing' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rack_options) { { tracer: tracer } } let(:spans) { tracer.writer.spans } diff --git a/spec/ddtrace/contrib/rack/integration_spec.rb b/spec/ddtrace/contrib/rack/integration_spec.rb index 900161789cc..e2e9aa1a745 100644 --- a/spec/ddtrace/contrib/rack/integration_spec.rb +++ b/spec/ddtrace/contrib/rack/integration_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'Rack integration tests' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rack_options) { { tracer: tracer } } let(:spans) { tracer.writer.spans } diff --git a/spec/ddtrace/contrib/rack/middleware_spec.rb b/spec/ddtrace/contrib/rack/middleware_spec.rb index 337155a94cb..fd8c20bf363 100644 --- a/spec/ddtrace/contrib/rack/middleware_spec.rb +++ b/spec/ddtrace/contrib/rack/middleware_spec.rb @@ -8,7 +8,7 @@ subject(:middleware) { described_class.new(app) } let(:app) { instance_double(Rack::Builder) } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer } } before(:each) do diff --git a/spec/ddtrace/contrib/rack/request_queuing_spec.rb b/spec/ddtrace/contrib/rack/request_queuing_spec.rb index c6f9f9b014d..4fe5aa06d7c 100644 --- a/spec/ddtrace/contrib/rack/request_queuing_spec.rb +++ b/spec/ddtrace/contrib/rack/request_queuing_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'Rack integration request queuing' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rack_options) { { tracer: tracer } } let(:spans) { tracer.writer.spans } diff --git a/spec/ddtrace/contrib/rack/resource_name_spec.rb b/spec/ddtrace/contrib/rack/resource_name_spec.rb index f9bc60f650d..190b7e1624d 100644 --- a/spec/ddtrace/contrib/rack/resource_name_spec.rb +++ b/spec/ddtrace/contrib/rack/resource_name_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'Rack integration with other middleware' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rack_options) do { application: app, diff --git a/spec/ddtrace/contrib/rails/action_controller_spec.rb b/spec/ddtrace/contrib/rails/action_controller_spec.rb index f6f65f1ec5e..af852c237aa 100644 --- a/spec/ddtrace/contrib/rails/action_controller_spec.rb +++ b/spec/ddtrace/contrib/rails/action_controller_spec.rb @@ -1,7 +1,7 @@ require 'ddtrace/contrib/rails/rails_helper' RSpec.describe 'ActionController tracing' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rails_options) { { tracer: tracer } } before(:each) do diff --git a/spec/ddtrace/contrib/rails/middleware_spec.rb b/spec/ddtrace/contrib/rails/middleware_spec.rb index d9baf2dc101..e20fe8b7bfb 100644 --- a/spec/ddtrace/contrib/rails/middleware_spec.rb +++ b/spec/ddtrace/contrib/rails/middleware_spec.rb @@ -15,7 +15,7 @@ def index end) end - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def all_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/rails/railtie_spec.rb b/spec/ddtrace/contrib/rails/railtie_spec.rb index 29e0c33f9e7..fe134fec204 100644 --- a/spec/ddtrace/contrib/rails/railtie_spec.rb +++ b/spec/ddtrace/contrib/rails/railtie_spec.rb @@ -7,7 +7,7 @@ before(:each) { skip 'Test not compatible with Rails < 4.0' if Rails.version < '4.0' } include_context 'Rails test application' - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:routes) { { '/' => 'test#index' } } let(:controllers) { [controller] } diff --git a/spec/ddtrace/contrib/rake/instrumentation_spec.rb b/spec/ddtrace/contrib/rake/instrumentation_spec.rb index 5e8568f8d59..ab9c8e3893f 100644 --- a/spec/ddtrace/contrib/rake/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/rake/instrumentation_spec.rb @@ -7,7 +7,7 @@ require 'ddtrace/contrib/rake/patcher' RSpec.describe Datadog::Contrib::Rake::Instrumentation do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer, enabled: true } } let(:spans) { tracer.writer.spans } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/redis/miniapp_spec.rb b/spec/ddtrace/contrib/redis/miniapp_spec.rb index 3c77353b521..1e6e9b674f8 100644 --- a/spec/ddtrace/contrib/redis/miniapp_spec.rb +++ b/spec/ddtrace/contrib/redis/miniapp_spec.rb @@ -6,7 +6,7 @@ require 'ddtrace' RSpec.describe 'Redis mini app test' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def all_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/redis/redis_spec.rb b/spec/ddtrace/contrib/redis/redis_spec.rb index 8e4314820d4..accdb9e496c 100644 --- a/spec/ddtrace/contrib/redis/redis_spec.rb +++ b/spec/ddtrace/contrib/redis/redis_spec.rb @@ -6,7 +6,7 @@ require 'ddtrace' RSpec.describe 'Redis test' do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } def all_spans tracer.writer.spans(:keep) diff --git a/spec/ddtrace/contrib/resque/instrumentation_spec.rb b/spec/ddtrace/contrib/resque/instrumentation_spec.rb index 67594b55607..39ff4f0319a 100644 --- a/spec/ddtrace/contrib/resque/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/resque/instrumentation_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Resque instrumentation' do include_context 'Resque job' - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:pin) { ::Resque.datadog_pin } let(:spans) { tracer.writer.spans } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/rest_client/request_patch_spec.rb b/spec/ddtrace/contrib/rest_client/request_patch_spec.rb index b5a73641d5a..6abaf01a14f 100644 --- a/spec/ddtrace/contrib/rest_client/request_patch_spec.rb +++ b/spec/ddtrace/contrib/rest_client/request_patch_spec.rb @@ -5,7 +5,7 @@ require 'restclient/request' RSpec.describe Datadog::Contrib::RestClient::RequestPatch do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:rest_client_options) { {} } before do diff --git a/spec/ddtrace/contrib/sequel/configuration_spec.rb b/spec/ddtrace/contrib/sequel/configuration_spec.rb index c94f6423c12..de5e5a1dc50 100644 --- a/spec/ddtrace/contrib/sequel/configuration_spec.rb +++ b/spec/ddtrace/contrib/sequel/configuration_spec.rb @@ -6,7 +6,7 @@ require 'ddtrace/contrib/sequel/patcher' RSpec.describe 'Sequel configuration' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:spans) { tracer.writer.spans } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/sequel/instrumentation_spec.rb b/spec/ddtrace/contrib/sequel/instrumentation_spec.rb index fc1c890d110..f1f39dba60f 100644 --- a/spec/ddtrace/contrib/sequel/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/sequel/instrumentation_spec.rb @@ -6,7 +6,7 @@ require 'ddtrace/contrib/sequel/integration' RSpec.describe 'Sequel instrumentation' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:configuration_options) { { tracer: tracer } } let(:sequel) do Sequel.sqlite(':memory:').tap do |s| diff --git a/spec/ddtrace/contrib/shoryuken/tracer_spec.rb b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb index 00b8be4423d..afa15f5c60b 100644 --- a/spec/ddtrace/contrib/shoryuken/tracer_spec.rb +++ b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb @@ -3,7 +3,7 @@ require 'shoryuken' RSpec.describe Datadog::Contrib::Shoryuken::Tracer do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:options) { { tracer: tracer } } let(:spans) { tracer.writer.spans } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/sinatra/activerecord_spec.rb b/spec/ddtrace/contrib/sinatra/activerecord_spec.rb index 0ad21d92ad0..96501580945 100644 --- a/spec/ddtrace/contrib/sinatra/activerecord_spec.rb +++ b/spec/ddtrace/contrib/sinatra/activerecord_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'Sinatra instrumentation with ActiveRecord' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:options) { { tracer: tracer } } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/sinatra/multi_app_spec.rb b/spec/ddtrace/contrib/sinatra/multi_app_spec.rb index 925f070a740..580f7a63966 100644 --- a/spec/ddtrace/contrib/sinatra/multi_app_spec.rb +++ b/spec/ddtrace/contrib/sinatra/multi_app_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'Sinatra instrumentation for multi-apps' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:options) { { tracer: tracer } } let(:span) { spans.first } diff --git a/spec/ddtrace/contrib/sinatra/tracer_spec.rb b/spec/ddtrace/contrib/sinatra/tracer_spec.rb index 38bb8949620..8bd41ec3b36 100644 --- a/spec/ddtrace/contrib/sinatra/tracer_spec.rb +++ b/spec/ddtrace/contrib/sinatra/tracer_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'Sinatra instrumentation' do include Rack::Test::Methods - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } let(:options) { { tracer: tracer } } let(:span) { spans.first } @@ -386,7 +386,7 @@ include_context 'app with simple route' subject(:response) { get '/' } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new, enabled: false) } + let(:tracer) { get_test_tracer(enabled: false) } it do is_expected.to be_ok diff --git a/spec/ddtrace/integration_spec.rb b/spec/ddtrace/integration_spec.rb index 0b632cd0114..86b43fef140 100644 --- a/spec/ddtrace/integration_spec.rb +++ b/spec/ddtrace/integration_spec.rb @@ -160,14 +160,8 @@ def agent_receives_span_step3 end describe 'sampling priority metrics' do - let(:tracer) do - get_test_tracer.tap do |t| - t.configure(priority_sampling: true) - t.writer = writer - end - end - - let(:writer) { FauxWriter.new(priority_sampler: Datadog::PrioritySampler.new) } + # Sampling priority is enabled by default + let(:tracer) { get_test_tracer } context 'when #sampling_priority is set on a child span' do let(:parent_span) { tracer.start_span('parent span') } @@ -180,7 +174,7 @@ def agent_receives_span_step3 end.finish end.finish - try_wait_until(attempts: 30) { writer.spans(:keep).any? } + try_wait_until(attempts: 30) { tracer.writer.spans(:keep).any? } end it do diff --git a/spec/ddtrace/pin_spec.rb b/spec/ddtrace/pin_spec.rb index c6d1d80182a..41cbb08e621 100644 --- a/spec/ddtrace/pin_spec.rb +++ b/spec/ddtrace/pin_spec.rb @@ -23,7 +23,7 @@ context 'when given sufficient info' do let(:options) { { app: 'test-app', app_type: 'test-type', tracer: tracer } } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } it 'sets the service info' do expect(tracer.services.key?(service_name)).to be true @@ -35,7 +35,7 @@ context 'when given insufficient info' do let(:options) { { app_type: 'test-type', tracer: tracer } } - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } it 'does not sets the service info' do expect(tracer.services).to be_empty diff --git a/spec/ddtrace/propagation/http_propagator_spec.rb b/spec/ddtrace/propagation/http_propagator_spec.rb index 1bbf84db715..5a868ddc782 100644 --- a/spec/ddtrace/propagation/http_propagator_spec.rb +++ b/spec/ddtrace/propagation/http_propagator_spec.rb @@ -4,7 +4,7 @@ require 'ddtrace/propagation/http_propagator' RSpec.describe Datadog::HTTPPropagator do - let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } describe '#inject!' do let(:env) { { 'something' => 'alien' } } diff --git a/spec/ddtrace/propagation/propagation_integration_spec.rb b/spec/ddtrace/propagation/propagation_integration_spec.rb index 51197163e8e..72c7384d44d 100644 --- a/spec/ddtrace/propagation/propagation_integration_spec.rb +++ b/spec/ddtrace/propagation/propagation_integration_spec.rb @@ -4,7 +4,7 @@ require 'ddtrace/propagation/http_propagator' RSpec.describe 'Context propagation' do - let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) } + let(:tracer) { get_test_tracer } describe 'when max context size is exceeded' do let(:max_size) { 3 } diff --git a/spec/support/tracer_helpers.rb b/spec/support/tracer_helpers.rb index 706a22ee4ce..3d87f1606dd 100644 --- a/spec/support/tracer_helpers.rb +++ b/spec/support/tracer_helpers.rb @@ -4,8 +4,39 @@ module TracerHelpers # Return a test tracer instance with a faux writer. - def get_test_tracer - Datadog::Tracer.new(writer: FauxWriter.new) + def get_test_tracer(options = {}) + options = { writer: FauxWriter.new }.merge(options) + Datadog::Tracer.new(options).tap do |tracer| + # TODO: Let's try to get rid of this override, which has too much + # knowledge about the internal workings of the tracer. + # It is done to prevent the activation of priority sampling + # from wiping out the configured test writer, by replacing it. + tracer.define_singleton_method(:configure) do |opts = {}| + super(opts) + + # Re-configure the tracer with a new test writer + # since priority sampling will wipe out the old test writer. + unless @writer.is_a?(FauxWriter) + @writer = if @sampler.is_a?(Datadog::PrioritySampler) + FauxWriter.new(priority_sampler: @sampler) + else + FauxWriter.new + end + + hostname = opts.fetch(:hostname, nil) + port = opts.fetch(:port, nil) + + @writer.transport.hostname = hostname unless hostname.nil? + @writer.transport.port = port unless port.nil? + + statsd = opts.fetch(:statsd, nil) + unless statsd.nil? + @writer.statsd = statsd + @writer.transport.statsd = statsd + end + end + end + end end # Return some test traces