diff --git a/.env b/.env index 508087ddc5..51aae70321 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ +DD_AGENT_HOST=localhost +DD_TRACE_AGENT_PORT=8126 TEST_DDAGENT_API_KEY=invalid_key_but_this_is_fine -TEST_DDAGENT_HOST=localhost -TEST_DDAGENT_PORT=8126 TEST_ELASTICSEARCH_HOST=127.0.0.1 TEST_ELASTICSEARCH_NATIVE_PORT=9300 TEST_ELASTICSEARCH_REST_PORT=9200 diff --git a/docker-compose.yml b/docker-compose.yml index 5215531fe8..99a6319533 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -46,8 +46,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -76,8 +76,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -106,8 +106,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -136,8 +136,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -166,8 +166,8 @@ services: env_file: ./.env environment: - BUNDLE_GEMFILE=/app/Gemfile + - DD_AGENT_HOST=ddagent - TEST_DATADOG_INTEGRATION=1 - - TEST_DDAGENT_HOST=ddagent - TEST_ELASTICSEARCH_HOST=elasticsearch - TEST_MEMCACHED_HOST=memcached - TEST_MONGODB_HOST=mongodb @@ -189,7 +189,7 @@ services: expose: - "8126" ports: - - "${TEST_DDAGENT_PORT}:8126" + - "${DD_TRACE_AGENT_PORT}:8126" elasticsearch: # Note: ES 5.0 dies with error: # max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] diff --git a/lib/ddtrace/sync_writer.rb b/lib/ddtrace/sync_writer.rb index 4742b4ac1f..3c489d60e1 100644 --- a/lib/ddtrace/sync_writer.rb +++ b/lib/ddtrace/sync_writer.rb @@ -5,7 +5,8 @@ class SyncWriter def initialize(options = {}) @transport = options.fetch(:transport) do - HTTPTransport.new(Writer::HOSTNAME, Writer::PORT) + transport_options = options.fetch(:transport_options, {}) + HTTPTransport.new(transport_options) end end diff --git a/lib/ddtrace/transport.rb b/lib/ddtrace/transport.rb index 56877f0b1f..6b9e49e29d 100644 --- a/lib/ddtrace/transport.rb +++ b/lib/ddtrace/transport.rb @@ -13,6 +13,9 @@ class HTTPTransport attr_accessor :hostname, :port attr_reader :traces_endpoint, :services_endpoint + DEFAULT_AGENT_HOST = '127.0.0.1'.freeze + DEFAULT_TRACE_AGENT_PORT = '8126'.freeze + # seconds before the transport timeout TIMEOUT = 1 @@ -45,11 +48,11 @@ class HTTPTransport private_constant :API - def initialize(hostname, port, options = {}) + def initialize(options = {}) api_version = options.fetch(:api_version, V3) - @hostname = hostname - @port = port + @hostname = options[:hostname] || ENV['DD_AGENT_HOST'] || DEFAULT_AGENT_HOST + @port = options[:port] || ENV['DD_TRACE_AGENT_PORT'] || DEFAULT_TRACE_AGENT_PORT @api = API.fetch(api_version) @encoder = options[:encoder] || @api[:encoder] @response_callback = options[:response_callback] diff --git a/lib/ddtrace/writer.rb b/lib/ddtrace/writer.rb index 416752a807..628e08b34e 100644 --- a/lib/ddtrace/writer.rb +++ b/lib/ddtrace/writer.rb @@ -7,9 +7,6 @@ module Datadog class Writer attr_reader :transport, :worker, :priority_sampler - HOSTNAME = '127.0.0.1'.freeze - PORT = '8126'.freeze - def initialize(options = {}) # writer and transport parameters @buff_size = options.fetch(:buffer_size, 100) @@ -24,7 +21,7 @@ def initialize(options = {}) # transport and buffers @transport = options.fetch(:transport) do - HTTPTransport.new(HOSTNAME, PORT, transport_options) + HTTPTransport.new(transport_options) end @services = {} diff --git a/spec/ddtrace/contrib/active_record/multi_db_spec.rb b/spec/ddtrace/contrib/active_record/multi_db_spec.rb index 58ca696422..18dbf955f7 100644 --- a/spec/ddtrace/contrib/active_record/multi_db_spec.rb +++ b/spec/ddtrace/contrib/active_record/multi_db_spec.rb @@ -84,7 +84,6 @@ def mysql_connection_string Datadog.registry[:active_record].reset_configuration! Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :active_record, configuration_options end end diff --git a/spec/ddtrace/contrib/active_record/tracer_spec.rb b/spec/ddtrace/contrib/active_record/tracer_spec.rb index 95b74c8619..8ea9f47995 100644 --- a/spec/ddtrace/contrib/active_record/tracer_spec.rb +++ b/spec/ddtrace/contrib/active_record/tracer_spec.rb @@ -15,7 +15,6 @@ Datadog.configuration[:active_record].reset_options! Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :active_record, configuration_options end end diff --git a/spec/ddtrace/contrib/rack/middleware_spec.rb b/spec/ddtrace/contrib/rack/middleware_spec.rb index df2b0afcd0..887083afa4 100644 --- a/spec/ddtrace/contrib/rack/middleware_spec.rb +++ b/spec/ddtrace/contrib/rack/middleware_spec.rb @@ -13,7 +13,6 @@ before(:each) do Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :rack, configuration_options end end diff --git a/spec/ddtrace/contrib/rails/railtie_spec.rb b/spec/ddtrace/contrib/rails/railtie_spec.rb index 60914eaf13..7aaa2825d2 100644 --- a/spec/ddtrace/contrib/rails/railtie_spec.rb +++ b/spec/ddtrace/contrib/rails/railtie_spec.rb @@ -32,7 +32,6 @@ def index before(:each) do Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :rails, rails_options if use_rails end end diff --git a/spec/ddtrace/contrib/redis/integration_spec.rb b/spec/ddtrace/contrib/redis/integration_spec.rb index 162a773402..b3bd3e332d 100644 --- a/spec/ddtrace/contrib/redis/integration_spec.rb +++ b/spec/ddtrace/contrib/redis/integration_spec.rb @@ -8,9 +8,7 @@ RSpec.describe 'Redis integration test' do # Use real tracer let(:tracer) do - Datadog::Tracer.new.tap do |tracer| - tracer.configure(hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost')) - end + Datadog::Tracer.new end before(:each) do diff --git a/spec/ddtrace/contrib/redis/method_replaced_spec.rb b/spec/ddtrace/contrib/redis/method_replaced_spec.rb index 129698489a..9121861db8 100644 --- a/spec/ddtrace/contrib/redis/method_replaced_spec.rb +++ b/spec/ddtrace/contrib/redis/method_replaced_spec.rb @@ -9,7 +9,6 @@ skip unless ENV['TEST_DATADOG_INTEGRATION'] Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :redis end end diff --git a/spec/ddtrace/integration_spec.rb b/spec/ddtrace/integration_spec.rb index 08c5ba5bc6..901e874126 100644 --- a/spec/ddtrace/integration_spec.rb +++ b/spec/ddtrace/integration_spec.rb @@ -11,9 +11,7 @@ let(:tracer) do Datadog::Tracer.new.tap do |t| t.configure( - enabled: true, - hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost'), - port: ENV.fetch('TEST_DDAGENT_PORT', 8126) + enabled: true ) end end @@ -189,8 +187,6 @@ def agent_receives_span_step3(previous_success) before(:each) do tracer.configure( enabled: true, - hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost'), - port: ENV.fetch('TEST_DDAGENT_PORT', 8126), priority_sampling: true ) end diff --git a/spec/ddtrace/transport_spec.rb b/spec/ddtrace/transport_spec.rb index d2349472fd..c602ee3686 100644 --- a/spec/ddtrace/transport_spec.rb +++ b/spec/ddtrace/transport_spec.rb @@ -3,13 +3,7 @@ require 'ddtrace' RSpec.describe Datadog::HTTPTransport do - let(:transport) do - described_class.new( - ENV.fetch('TEST_DDAGENT_HOST', 'localhost'), - ENV.fetch('TEST_DDAGENT_PORT', 8126), - options - ) - end + let(:transport) { described_class.new(options) } let(:options) { {} } before(:each) do @@ -66,7 +60,7 @@ end context 'and a bad transport' do - let(:transport) { described_class.new('localhost', '8888') } + let(:transport) { described_class.new(hostname: 'localhost', port: '8888') } it { expect(transport.server_error?(code)).to be true } end diff --git a/spec/ddtrace/workers_integration_spec.rb b/spec/ddtrace/workers_integration_spec.rb index fe563870c3..c2653accbf 100644 --- a/spec/ddtrace/workers_integration_spec.rb +++ b/spec/ddtrace/workers_integration_spec.rb @@ -42,7 +42,7 @@ end end - let(:transport) { SpyTransport.new(hostname, port) } + let(:transport) { SpyTransport.new } def wait_for_flush(num = 1, period = 0.1) (20 * flush_interval).to_i.times do diff --git a/spec/ddtrace/writer_spec.rb b/spec/ddtrace/writer_spec.rb index 6efafdd7dd..c03b25ba27 100644 --- a/spec/ddtrace/writer_spec.rb +++ b/spec/ddtrace/writer_spec.rb @@ -25,9 +25,7 @@ context 'and default transport options' do it do sampling_method = described_class.new.method(:sampling_updater) - expect(Datadog::HTTPTransport).to receive(:new) do |hostname, port, options| - expect(hostname).to eq(described_class::HOSTNAME) - expect(port).to eq(described_class::PORT) + expect(Datadog::HTTPTransport).to receive(:new) do |options| expect(options).to be_a_kind_of(Hash) expect(options[:api_version]).to eq(Datadog::HTTPTransport::V4) expect(options[:response_callback].source_location).to eq(sampling_method.source_location) @@ -43,9 +41,7 @@ let(:response_callback) { double('response callback') } it do - expect(Datadog::HTTPTransport).to receive(:new) do |hostname, port, options| - expect(hostname).to eq(described_class::HOSTNAME) - expect(port).to eq(described_class::PORT) + expect(Datadog::HTTPTransport).to receive(:new) do |options| expect(options).to include( api_version: api_version, response_callback: response_callback @@ -70,7 +66,9 @@ let(:callback) { double('callback method') } let!(:request) { stub_request(:post, endpoint).to_return(response) } - let(:endpoint) { "#{Datadog::Writer::HOSTNAME}:#{Datadog::Writer::PORT}/#{api_version}/traces" } + let(:hostname) { ENV.fetch('DD_AGENT_HOST', Datadog::HTTPTransport::DEFAULT_AGENT_HOST) } + let(:port) { ENV.fetch('DD_TRACE_AGENT_PORT', Datadog::HTTPTransport::DEFAULT_TRACE_AGENT_PORT) } + let(:endpoint) { "#{hostname}:#{port}/#{api_version}/traces" } let(:response) { { body: body } } let(:body) { 'body' } @@ -96,7 +94,7 @@ let(:response) { super().merge!(status: 404) } let!(:fallback_request) { stub_request(:post, fallback_endpoint).to_return(body: body) } let(:fallback_endpoint) do - "#{Datadog::Writer::HOSTNAME}:#{Datadog::Writer::PORT}/#{fallback_version}/traces" + "#{hostname}:#{port}/#{fallback_version}/traces" end let(:body) { 'body' } diff --git a/spec/support/faux_writer.rb b/spec/support/faux_writer.rb index 2b21da7a13..a034603b5a 100644 --- a/spec/support/faux_writer.rb +++ b/spec/support/faux_writer.rb @@ -5,7 +5,7 @@ # FauxWriter is a dummy writer that buffers spans locally. class FauxWriter < Datadog::Writer def initialize(options = {}) - options[:transport] ||= FauxTransport.new(HOSTNAME, PORT) + options[:transport] ||= FauxTransport.new super @mutex = Mutex.new diff --git a/spec/support/spy_transport.rb b/spec/support/spy_transport.rb index 97fa2bdffd..a17b5c7ce5 100644 --- a/spec/support/spy_transport.rb +++ b/spec/support/spy_transport.rb @@ -5,8 +5,8 @@ class SpyTransport < Datadog::HTTPTransport attr_reader :helper_sent - def initialize(hostname, port) - super(hostname, port) + def initialize(options = {}) + super @helper_sent = { 200 => {}, 500 => {} } @helper_mutex = Mutex.new @helper_error_mode = false diff --git a/test/contrib/rack/helpers.rb b/test/contrib/rack/helpers.rb index 03db3f2764..7d4f67fbff 100644 --- a/test/contrib/rack/helpers.rb +++ b/test/contrib/rack/helpers.rb @@ -122,7 +122,6 @@ def setup @tracer = get_test_tracer Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :http c.use :rack, tracer: @tracer end diff --git a/test/contrib/rails/apps/application.rb b/test/contrib/rails/apps/application.rb index 41a6f3d184..f2800732eb 100644 --- a/test/contrib/rails/apps/application.rb +++ b/test/contrib/rails/apps/application.rb @@ -42,7 +42,6 @@ def config.database_configuration def test_config # Enables the auto-instrumentation for the testing application Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :rails c.use :redis end diff --git a/test/contrib/rails/apps/rails3.rb b/test/contrib/rails/apps/rails3.rb index f659222e28..0fab71ea43 100644 --- a/test/contrib/rails/apps/rails3.rb +++ b/test/contrib/rails/apps/rails3.rb @@ -17,7 +17,6 @@ class Rails3 < Rails::Application # Enables the auto-instrumentation for the testing application Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :rails c.use :redis end diff --git a/test/contrib/sinatra/tracer_activerecord_test.rb b/test/contrib/sinatra/tracer_activerecord_test.rb index ea540fbe43..930887c3b3 100644 --- a/test/contrib/sinatra/tracer_activerecord_test.rb +++ b/test/contrib/sinatra/tracer_activerecord_test.rb @@ -47,7 +47,6 @@ def setup app.set :datadog_test_conn, conn Datadog.configure do |c| - c.tracer hostname: ENV.fetch('TEST_DDAGENT_HOST', 'localhost') c.use :active_record end