From 0db0ed7d2429cbfcd8206487154e384bfbbc7e7f Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 10:51:27 +0100 Subject: [PATCH 01/19] Shared example for environment service name --- .../environment_service_name_examples.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/datadog/tracing/contrib/environment_service_name_examples.rb diff --git a/spec/datadog/tracing/contrib/environment_service_name_examples.rb b/spec/datadog/tracing/contrib/environment_service_name_examples.rb new file mode 100644 index 0000000000..90c2f3340a --- /dev/null +++ b/spec/datadog/tracing/contrib/environment_service_name_examples.rb @@ -0,0 +1,29 @@ +# typed: ignore + +RSpec.shared_examples_for 'environment service name' do |env_service_name_key, error: nil| + context "when given `#{env_service_name_key}` environment variable" do + around do |example| + ClimateControl.modify(env_service_name_key => 'environment_default') do + example.run + end + end + + before do + if error + expect { subject }.to raise_error error + else + subject + end + end + + context 'when none configured' do + it { expect(span.service).to eq('environment_default') } + end + + context 'when given service_name' do + let(:configuration_options) { { service_name: 'configured' } } + + it { expect(span.service).to eq(configuration_options[:service_name]) } + end + end +end From baf298ca688d5915a3b8c123d87281e4de17073d Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 10:51:49 +0100 Subject: [PATCH 02/19] Environment variable service_name for `dalli` --- .../tracing/contrib/dalli/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/dalli/ext.rb | 1 + .../tracing/contrib/dalli/instrumentation_spec.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb index df15b502cf..f19578aafd 100644 --- a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb @@ -26,7 +26,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/dalli/ext.rb b/lib/datadog/tracing/contrib/dalli/ext.rb index e180228898..b73a5bb0b2 100644 --- a/lib/datadog/tracing/contrib/dalli/ext.rb +++ b/lib/datadog/tracing/contrib/dalli/ext.rb @@ -10,6 +10,7 @@ module Ext ENV_ENABLED = 'DD_TRACE_DALLI_ENABLED'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_DALLI_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_DALLI_ANALYTICS_SAMPLE_RATE'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_DALLI_SERVICE_NAME'.freeze QUANTIZE_MAX_CMD_LENGTH = 100 DEFAULT_PEER_SERVICE_NAME = 'memcached'.freeze SPAN_COMMAND = 'memcached.command'.freeze diff --git a/spec/datadog/tracing/contrib/dalli/instrumentation_spec.rb b/spec/datadog/tracing/contrib/dalli/instrumentation_spec.rb index df26990c1f..b18ce81b83 100644 --- a/spec/datadog/tracing/contrib/dalli/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/dalli/instrumentation_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/integration_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'dalli' require 'ddtrace' @@ -29,6 +30,13 @@ Datadog.registry[:dalli].reset_configuration! end + it_behaves_like 'environment service name', 'DD_TRACE_DALLI_SERVICE_NAME' do + subject do + client.set('abc', 123) + try_wait_until { fetch_spans.any? } + end + end + describe 'when a client calls #set' do before do client.set('abc', 123) From e75a528d20393115e71320bb8dd26c811b2d12ef Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 11:00:17 +0100 Subject: [PATCH 03/19] Environment variable service_name for `aws` --- .../tracing/contrib/aws/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/aws/ext.rb | 1 + spec/datadog/tracing/contrib/aws/instrumentation_spec.rb | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/aws/configuration/settings.rb b/lib/datadog/tracing/contrib/aws/configuration/settings.rb index e41ddc50a4..0f782929d5 100644 --- a/lib/datadog/tracing/contrib/aws/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/aws/configuration/settings.rb @@ -26,7 +26,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/aws/ext.rb b/lib/datadog/tracing/contrib/aws/ext.rb index 4a4a48eb9d..5938857a4b 100644 --- a/lib/datadog/tracing/contrib/aws/ext.rb +++ b/lib/datadog/tracing/contrib/aws/ext.rb @@ -8,6 +8,7 @@ module Aws # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_AWS_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_AWS_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_AWS_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_AWS_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'aws'.freeze diff --git a/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb b/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb index 3a1358872c..a0993b7623 100644 --- a/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/aws/instrumentation_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/integration_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'aws-sdk' @@ -43,6 +44,7 @@ it_behaves_like 'measured span for integration' it_behaves_like 'a peer service span' + it_behaves_like 'environment service name', 'DD_TRACE_AWS_SERVICE_NAME' it 'generates a span' do expect(span.name).to eq('aws.command') @@ -90,6 +92,7 @@ end it_behaves_like 'measured span for integration' + it_behaves_like 'environment service name', 'DD_TRACE_AWS_SERVICE_NAME' it 'generates a span' do expect(span.name).to eq('aws.command') From 0dcc2f892feaebfd6c084e63ae57b37e33308ecf Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 11:19:14 +0100 Subject: [PATCH 04/19] Environment variable service_name for `elasticsearch` --- .../contrib/elasticsearch/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/elasticsearch/ext.rb | 1 + .../tracing/contrib/elasticsearch/patcher_spec.rb | 5 +++++ .../tracing/contrib/elasticsearch/transport_spec.rb | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb index 34f6406f17..2bc557d19d 100644 --- a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb @@ -27,7 +27,14 @@ class Settings < Contrib::Configuration::Settings end option :quantize, default: {} - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/elasticsearch/ext.rb b/lib/datadog/tracing/contrib/elasticsearch/ext.rb index 2cdf8a14cc..704ee3e880 100644 --- a/lib/datadog/tracing/contrib/elasticsearch/ext.rb +++ b/lib/datadog/tracing/contrib/elasticsearch/ext.rb @@ -8,6 +8,7 @@ module Elasticsearch # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_ELASTICSEARCH_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'elasticsearch'.freeze diff --git a/spec/datadog/tracing/contrib/elasticsearch/patcher_spec.rb b/spec/datadog/tracing/contrib/elasticsearch/patcher_spec.rb index 2e12ef8147..34f95da715 100644 --- a/spec/datadog/tracing/contrib/elasticsearch/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/elasticsearch/patcher_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/integration_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ddtrace' @@ -62,6 +63,8 @@ describe 'health request span' do before { request } + it_behaves_like 'environment service name', 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME' + it { expect(span.name).to eq('elasticsearch.query') } it { expect(span.service).to eq('elasticsearch') } it { expect(span.resource).to eq('GET _cluster/health') } @@ -121,6 +124,8 @@ it_behaves_like 'measured span for integration', false + it_behaves_like 'environment service name', 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME' + it { expect(span.name).to eq('elasticsearch.query') } it { expect(span.service).to eq('elasticsearch') } it { expect(span.span_type).to eq('elasticsearch') } diff --git a/spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb b/spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb index 8a5b696acb..b5d67ac4bf 100644 --- a/spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb +++ b/spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb @@ -1,6 +1,7 @@ # typed: ignore require 'datadog/tracing/contrib/integration_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'time' require 'elasticsearch' @@ -102,6 +103,7 @@ def call(env) end it_behaves_like 'a peer service span' + it_behaves_like 'environment service name', 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME' end context 'PUT request' do @@ -133,6 +135,7 @@ def call(env) end it_behaves_like 'a peer service span' + it_behaves_like 'environment service name', 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME' end context 'with Hash params' do From 0d613ed78e88f92e702394b12d64050393170ece Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 11:46:05 +0100 Subject: [PATCH 05/19] Environment variable service_name for `ethon` --- .../tracing/contrib/ethon/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/ethon/ext.rb | 1 + spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb | 5 +++++ .../datadog/tracing/contrib/ethon/multi_patch_spec.rb | 5 +++++ spec/datadog/tracing/contrib/ethon/shared_examples.rb | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb index 6f705eece6..ea80314736 100644 --- a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb @@ -27,8 +27,17 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :split_by_domain, default: false + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/ethon/ext.rb b/lib/datadog/tracing/contrib/ethon/ext.rb index 048d90ec03..ee3d6251be 100644 --- a/lib/datadog/tracing/contrib/ethon/ext.rb +++ b/lib/datadog/tracing/contrib/ethon/ext.rb @@ -8,6 +8,7 @@ module Ethon # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_ETHON_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_ETHON_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_ETHON_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ETHON_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'ethon'.freeze diff --git a/spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb b/spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb index 26c9e6e8db..4fc617b747 100644 --- a/spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb +++ b/spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb @@ -1,6 +1,7 @@ # typed: false require 'datadog/tracing/contrib/support/spec_helper' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ethon' require 'datadog/tracing/contrib/ethon/easy_patch' @@ -112,6 +113,10 @@ let(:span) { span_op } before { subject } end + + it_behaves_like 'environment service name', 'DD_TRACE_ETHON_SERVICE_NAME' do + let(:span) { span_op } + end end describe '#complete' do diff --git a/spec/datadog/tracing/contrib/ethon/multi_patch_spec.rb b/spec/datadog/tracing/contrib/ethon/multi_patch_spec.rb index d1ed7dd5e7..e7552b8f15 100644 --- a/spec/datadog/tracing/contrib/ethon/multi_patch_spec.rb +++ b/spec/datadog/tracing/contrib/ethon/multi_patch_spec.rb @@ -6,6 +6,7 @@ require 'datadog/tracing/contrib/ethon/multi_patch' require 'datadog/tracing/contrib/ethon/shared_examples' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'spec/datadog/tracing/contrib/ethon/support/thread_helpers' @@ -114,6 +115,10 @@ let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Ethon::Ext::ENV_ANALYTICS_ENABLED } let(:analytics_sample_rate_var) { Datadog::Tracing::Contrib::Ethon::Ext::ENV_ANALYTICS_SAMPLE_RATE } end + + it_behaves_like 'environment service name', 'DD_TRACE_ETHON_SERVICE_NAME' do + let(:span) { multi_span } + end end it 'submits parent and child traces' do diff --git a/spec/datadog/tracing/contrib/ethon/shared_examples.rb b/spec/datadog/tracing/contrib/ethon/shared_examples.rb index 1956827f2f..549871ec9e 100644 --- a/spec/datadog/tracing/contrib/ethon/shared_examples.rb +++ b/spec/datadog/tracing/contrib/ethon/shared_examples.rb @@ -4,6 +4,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/ethon/integration_context' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'datadog/tracing/metadata/ext' require 'datadog/tracing/span' @@ -62,6 +63,8 @@ it_behaves_like 'a peer service span' do let(:peer_hostname) { host } end + + it_behaves_like 'environment service name', 'DD_TRACE_ETHON_SERVICE_NAME' end RSpec.shared_examples_for 'instrumented request' do From 9d23cf6dedefa72dac624e1c62f64f62cec34ba6 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 11:56:30 +0100 Subject: [PATCH 06/19] Environment variable service_name for `excon` --- .../tracing/contrib/excon/configuration/settings.rb | 10 +++++++++- lib/datadog/tracing/contrib/excon/ext.rb | 1 + .../tracing/contrib/excon/instrumentation_spec.rb | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/excon/configuration/settings.rb b/lib/datadog/tracing/contrib/excon/configuration/settings.rb index 3252eeb145..c04aabc89f 100644 --- a/lib/datadog/tracing/contrib/excon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/excon/configuration/settings.rb @@ -28,8 +28,16 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :error_handler - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME option :split_by_domain, default: false + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/excon/ext.rb b/lib/datadog/tracing/contrib/excon/ext.rb index 0f07b0ef0d..82c9637a1d 100644 --- a/lib/datadog/tracing/contrib/excon/ext.rb +++ b/lib/datadog/tracing/contrib/excon/ext.rb @@ -8,6 +8,7 @@ module Excon # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_EXCON_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_EXCON_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_EXCON_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_EXCON_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'excon'.freeze diff --git a/spec/datadog/tracing/contrib/excon/instrumentation_spec.rb b/spec/datadog/tracing/contrib/excon/instrumentation_spec.rb index ec67eeb572..e4459b369b 100644 --- a/spec/datadog/tracing/contrib/excon/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/excon/instrumentation_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'excon' require 'ddtrace' @@ -74,11 +75,15 @@ expect(response.body).to eq('OK') expect(response.status).to eq(200) end + + it_behaves_like 'environment service name', 'DD_TRACE_EXCON_SERVICE_NAME' end context 'when there is successful request' do subject!(:response) { connection.get(path: '/success') } + it_behaves_like 'environment service name', 'DD_TRACE_EXCON_SERVICE_NAME' + it_behaves_like 'analytics for integration' do let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Excon::Ext::ENV_ANALYTICS_ENABLED } let(:analytics_sample_rate_var) { Datadog::Tracing::Contrib::Excon::Ext::ENV_ANALYTICS_SAMPLE_RATE } @@ -113,6 +118,8 @@ context 'when there is a failing request' do subject!(:response) { connection.post(path: '/failure') } + it_behaves_like 'environment service name', 'DD_TRACE_EXCON_SERVICE_NAME' + it do expect(request_span.service).to eq(Datadog::Tracing::Contrib::Excon::Ext::DEFAULT_PEER_SERVICE_NAME) expect(request_span.name).to eq(Datadog::Tracing::Contrib::Excon::Ext::SPAN_REQUEST) @@ -140,12 +147,16 @@ context 'when the path is not found' do subject!(:response) { connection.get(path: '/not_found') } + it_behaves_like 'environment service name', 'DD_TRACE_EXCON_SERVICE_NAME' + it { expect(request_span).to_not have_error } end context 'when the request times out' do subject(:response) { connection.get(path: '/timeout') } + it_behaves_like 'environment service name', 'DD_TRACE_EXCON_SERVICE_NAME', error: Excon::Error::Timeout + it do expect { subject }.to raise_error(Excon::Error::Timeout) expect(request_span.finished?).to eq(true) From 1fbcfcf67bc47931078fbd0db8b4506b0c8f4bf9 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 12:08:09 +0100 Subject: [PATCH 07/19] Environment variable service_name for `faraday` --- .../contrib/faraday/configuration/settings.rb | 10 +++++++++- lib/datadog/tracing/contrib/faraday/ext.rb | 1 + .../tracing/contrib/faraday/middleware_spec.rb | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb index 5c5ad66258..b752d2c539 100644 --- a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb @@ -32,8 +32,16 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :error_handler, default: DEFAULT_ERROR_HANDLER - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME option :split_by_domain, default: false + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/faraday/ext.rb b/lib/datadog/tracing/contrib/faraday/ext.rb index e0dc9d0d07..9f8f4993c5 100644 --- a/lib/datadog/tracing/contrib/faraday/ext.rb +++ b/lib/datadog/tracing/contrib/faraday/ext.rb @@ -8,6 +8,7 @@ module Faraday # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_FARADAY_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_FARADAY_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_FARADAY_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_FARADAY_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'faraday'.freeze diff --git a/spec/datadog/tracing/contrib/faraday/middleware_spec.rb b/spec/datadog/tracing/contrib/faraday/middleware_spec.rb index b05f9be204..f76be3c1df 100644 --- a/spec/datadog/tracing/contrib/faraday/middleware_spec.rb +++ b/spec/datadog/tracing/contrib/faraday/middleware_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'faraday' @@ -44,6 +45,8 @@ let(:use_middleware) { false } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' + it 'uses default configuration' do expect(response.status).to eq(200) @@ -86,6 +89,8 @@ after { WebMock.disable! } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' + it 'uses default configuration' do expect(response.status).to eq(200) @@ -114,6 +119,8 @@ context 'when there is no interference' do subject!(:response) { client.get('/success') } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' + it do expect(response).to be_a_kind_of(::Faraday::Response) expect(response.body).to eq('OK') @@ -124,6 +131,8 @@ context 'when there is successful request' do subject!(:response) { client.get('/success') } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' + it_behaves_like 'analytics for integration' do let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Faraday::Ext::ENV_ANALYTICS_ENABLED } let(:analytics_sample_rate_var) { Datadog::Tracing::Contrib::Faraday::Ext::ENV_ANALYTICS_SAMPLE_RATE } @@ -157,6 +166,8 @@ context 'when there is a failing request' do subject!(:response) { client.post('/failure') } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' + it do expect(span.service).to eq(Datadog::Tracing::Contrib::Faraday::Ext::DEFAULT_PEER_SERVICE_NAME) expect(span.name).to eq(Datadog::Tracing::Contrib::Faraday::Ext::SPAN_REQUEST) @@ -184,6 +195,8 @@ context 'with library error' do subject(:response) { client.get('/error') } + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME', error: Faraday::ConnectionFailed + it do expect { response }.to raise_error(Faraday::ConnectionFailed) expect(span.service).to eq(Datadog::Tracing::Contrib::Faraday::Ext::DEFAULT_PEER_SERVICE_NAME) @@ -221,6 +234,8 @@ subject!(:response) { client.get('/not_found') } it { expect(span).to_not have_error } + + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' end context 'when there is custom error handling' do @@ -230,6 +245,8 @@ let(:custom_handler) { ->(env) { (400...600).cover?(env[:status]) } } it { expect(span).to have_error } + + it_behaves_like 'environment service name', 'DD_TRACE_FARADAY_SERVICE_NAME' end context 'when split by domain' do From 4cbd41766ac61ae8c0e25741b7087af37d307b20 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 13:49:01 +0100 Subject: [PATCH 08/19] Environment variable service_name for `grpc` --- .../tracing/contrib/grpc/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/grpc/ext.rb | 1 + .../contrib/grpc/datadog_interceptor/client_spec.rb | 4 ++++ .../contrib/grpc/datadog_interceptor/server_spec.rb | 4 ++++ .../tracing/contrib/grpc/interception_context_spec.rb | 7 +++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb index 4a7e5f8e73..cfc7209244 100644 --- a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb @@ -28,7 +28,16 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end + option :error_handler, default: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR end end diff --git a/lib/datadog/tracing/contrib/grpc/ext.rb b/lib/datadog/tracing/contrib/grpc/ext.rb index 1169aa6649..ead7c42620 100644 --- a/lib/datadog/tracing/contrib/grpc/ext.rb +++ b/lib/datadog/tracing/contrib/grpc/ext.rb @@ -8,6 +8,7 @@ module GRPC # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_GRPC_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_GRPC_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_GRPC_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_GRPC_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'grpc'.freeze diff --git a/spec/datadog/tracing/contrib/grpc/datadog_interceptor/client_spec.rb b/spec/datadog/tracing/contrib/grpc/datadog_interceptor/client_spec.rb index dc83d992b8..68df3ad3f5 100644 --- a/spec/datadog/tracing/contrib/grpc/datadog_interceptor/client_spec.rb +++ b/spec/datadog/tracing/contrib/grpc/datadog_interceptor/client_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'grpc' require 'ddtrace' @@ -91,6 +92,9 @@ end it_behaves_like 'measured span for integration', false + it_behaves_like 'environment service name', 'DD_TRACE_GRPC_SERVICE_NAME' do + let(:configuration_options) { {} } + end end shared_examples 'inject distributed tracing metadata' do diff --git a/spec/datadog/tracing/contrib/grpc/datadog_interceptor/server_spec.rb b/spec/datadog/tracing/contrib/grpc/datadog_interceptor/server_spec.rb index dcaf7a6062..b5817f8cfa 100644 --- a/spec/datadog/tracing/contrib/grpc/datadog_interceptor/server_spec.rb +++ b/spec/datadog/tracing/contrib/grpc/datadog_interceptor/server_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'grpc' require 'ddtrace' @@ -50,6 +51,9 @@ it_behaves_like 'a non-peer service span' it_behaves_like 'measured span for integration', true + it_behaves_like 'environment service name', 'DD_TRACE_GRPC_SERVICE_NAME' do + let(:configuration_options) { {} } + end end describe '#request_response' do diff --git a/spec/datadog/tracing/contrib/grpc/interception_context_spec.rb b/spec/datadog/tracing/contrib/grpc/interception_context_spec.rb index dcb22f16f1..16ae56ffbe 100644 --- a/spec/datadog/tracing/contrib/grpc/interception_context_spec.rb +++ b/spec/datadog/tracing/contrib/grpc/interception_context_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'grpc' require 'ddtrace' @@ -43,6 +44,9 @@ end it_behaves_like 'a peer service span' + it_behaves_like 'environment service name', 'DD_TRACE_GRPC_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'request response call type' do @@ -117,6 +121,9 @@ end it_behaves_like 'a non-peer service span' + it_behaves_like 'environment service name', 'DD_TRACE_GRPC_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'request response call type' do From 0cefe92511751a5ceebbb1537b12d0231f774743 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:01:42 +0100 Subject: [PATCH 09/19] Environment variable service_name for `http` --- .../tracing/contrib/http/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/http/ext.rb | 1 + spec/datadog/tracing/contrib/http/request_spec.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/http/configuration/settings.rb b/lib/datadog/tracing/contrib/http/configuration/settings.rb index 9c4d508103..4197443a0e 100644 --- a/lib/datadog/tracing/contrib/http/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/http/configuration/settings.rb @@ -27,7 +27,16 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end + option :split_by_domain, default: false end end diff --git a/lib/datadog/tracing/contrib/http/ext.rb b/lib/datadog/tracing/contrib/http/ext.rb index ba73d63703..a30defa286 100644 --- a/lib/datadog/tracing/contrib/http/ext.rb +++ b/lib/datadog/tracing/contrib/http/ext.rb @@ -8,6 +8,7 @@ module HTTP # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_HTTP_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_HTTP_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTP_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTP_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'net/http'.freeze diff --git a/spec/datadog/tracing/contrib/http/request_spec.rb b/spec/datadog/tracing/contrib/http/request_spec.rb index f3cc61b06a..92df4d93c8 100644 --- a/spec/datadog/tracing/contrib/http/request_spec.rb +++ b/spec/datadog/tracing/contrib/http/request_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ddtrace' require 'net/http' @@ -74,6 +75,8 @@ it_behaves_like 'a peer service span' do let(:peer_hostname) { host } end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' end context 'that returns 404' do @@ -102,6 +105,8 @@ let(:peer_hostname) { host } end + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' + context 'when configured with #after_request hook' do before { Datadog::Tracing::Contrib::HTTP::Instrumentation.after_request(&callback) } @@ -170,6 +175,8 @@ it_behaves_like 'a peer service span' do let(:peer_hostname) { host } end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' end end @@ -203,6 +210,8 @@ it_behaves_like 'a peer service span' do let(:peer_hostname) { host } end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' end end @@ -437,6 +446,8 @@ def expect_request_without_distributed_headers expect(span).to have_error_type(timeout_error.class.to_s) expect(span).to have_error_message(timeout_error.message) end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME', error: Net::OpenTimeout end context 'that raises an error' do @@ -460,6 +471,8 @@ def expect_request_without_distributed_headers expect(span).to have_error_type(custom_error.class.to_s) expect(span).to have_error_message(custom_error.message) end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME', error: StandardError end end end From 279edc90bc6a98be0f85b4cc2ad24e15b630b06b Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:09:45 +0100 Subject: [PATCH 10/19] Environment variable service_name for `httpclient` --- .../contrib/httpclient/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/httpclient/ext.rb | 1 + .../contrib/httpclient/instrumentation_spec.rb | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb index 5d734966e9..9d51ced1e4 100644 --- a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb @@ -27,7 +27,16 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end + option :split_by_domain, default: false end end diff --git a/lib/datadog/tracing/contrib/httpclient/ext.rb b/lib/datadog/tracing/contrib/httpclient/ext.rb index 7d929140fa..a2b0c39be6 100644 --- a/lib/datadog/tracing/contrib/httpclient/ext.rb +++ b/lib/datadog/tracing/contrib/httpclient/ext.rb @@ -8,6 +8,7 @@ module Httpclient # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_HTTPCLIENT_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_HTTPCLIENT_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTPCLIENT_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTPCLIENT_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'httpclient'.freeze diff --git a/spec/datadog/tracing/contrib/httpclient/instrumentation_spec.rb b/spec/datadog/tracing/contrib/httpclient/instrumentation_spec.rb index fbf151ae59..c33d2bcab8 100644 --- a/spec/datadog/tracing/contrib/httpclient/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/httpclient/instrumentation_spec.rb @@ -14,6 +14,7 @@ require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'spec/support/thread_helpers' RSpec.describe Datadog::Tracing::Contrib::Httpclient::Instrumentation do @@ -137,6 +138,8 @@ let(:peer_hostname) { host } end + it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME' + it_behaves_like 'analytics for integration' do let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Httpclient::Ext::ENV_ANALYTICS_ENABLED } let(:analytics_sample_rate_var) { Datadog::Tracing::Contrib::Httpclient::Ext::ENV_ANALYTICS_SAMPLE_RATE } @@ -164,6 +167,8 @@ it 'has error message' do expect(span).to have_error_message(body.to_json) end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME' end context 'response has not found status' do @@ -187,6 +192,8 @@ it 'has error message' do expect(span).to have_error_message(body.to_json) end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME' end context 'distributed tracing default' do From 3a398b7d963e246157c27da37be8f46be017f854 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:14:10 +0100 Subject: [PATCH 11/19] Environment variable service_name for `httprb` --- .../tracing/contrib/httprb/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/httprb/ext.rb | 1 + .../tracing/contrib/httprb/instrumentation_spec.rb | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb index 8943c75bd8..e810571985 100644 --- a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb @@ -27,7 +27,16 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end + option :split_by_domain, default: false end end diff --git a/lib/datadog/tracing/contrib/httprb/ext.rb b/lib/datadog/tracing/contrib/httprb/ext.rb index 5c1c516d74..61a7dae977 100644 --- a/lib/datadog/tracing/contrib/httprb/ext.rb +++ b/lib/datadog/tracing/contrib/httprb/ext.rb @@ -8,6 +8,7 @@ module Httprb # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_HTTPRB_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_HTTPRB_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTPRB_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_EHTTPRB_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'httprb'.freeze diff --git a/spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb b/spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb index 72e0a00cd2..d3d81541b7 100644 --- a/spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb @@ -13,6 +13,7 @@ require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'spec/support/thread_helpers' RSpec.describe Datadog::Tracing::Contrib::Httprb::Instrumentation do @@ -146,6 +147,8 @@ let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Httprb::Ext::ENV_ANALYTICS_ENABLED } let(:analytics_sample_rate_var) { Datadog::Tracing::Contrib::Httprb::Ext::ENV_ANALYTICS_SAMPLE_RATE } end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTPRB_SERVICE_NAME' end context 'response has internal server error status' do @@ -170,6 +173,8 @@ it 'has error message' do expect(span).to have_error_message('Error') end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTPRB_SERVICE_NAME' end context 'response has not found status' do @@ -194,6 +199,8 @@ it 'has error message' do expect(span).to have_error_message('Error') end + + it_behaves_like 'environment service name', 'DD_TRACE_HTTPRB_SERVICE_NAME' end context 'distributed tracing default' do From 6e70ec1df94adbb4ca13c4bdcb9b572af7f62062 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:24:14 +0100 Subject: [PATCH 12/19] Environment variable service_name for `mongodb` --- .../tracing/contrib/mongodb/configuration/settings.rb | 10 +++++++++- lib/datadog/tracing/contrib/mongodb/ext.rb | 1 + spec/datadog/tracing/contrib/mongodb/client_spec.rb | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb index 671e09ec75..c578706f88 100644 --- a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb @@ -29,7 +29,15 @@ class Settings < Contrib::Configuration::Settings end option :quantize, default: DEFAULT_QUANTIZE - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/mongodb/ext.rb b/lib/datadog/tracing/contrib/mongodb/ext.rb index e5dea5bae3..2ec1f3b131 100644 --- a/lib/datadog/tracing/contrib/mongodb/ext.rb +++ b/lib/datadog/tracing/contrib/mongodb/ext.rb @@ -8,6 +8,7 @@ module MongoDB # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_MONGO_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_MONGO_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_MONGO_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MONGO_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'mongodb'.freeze diff --git a/spec/datadog/tracing/contrib/mongodb/client_spec.rb b/spec/datadog/tracing/contrib/mongodb/client_spec.rb index be9b5bb3d6..ebbb8c3143 100644 --- a/spec/datadog/tracing/contrib/mongodb/client_spec.rb +++ b/spec/datadog/tracing/contrib/mongodb/client_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ddtrace' require 'mongo' @@ -167,6 +168,7 @@ end it_behaves_like 'measured span for integration', false + it_behaves_like 'environment service name', 'DD_TRACE_MONGO_SERVICE_NAME' end # Expects every value (except for keys) to be quantized. From b7133eb275477d408d82b8fe822454715715b5ed Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:32:06 +0100 Subject: [PATCH 13/19] Environment variable service_name for `mysql2` --- .../tracing/contrib/mysql2/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/mysql2/ext.rb | 1 + spec/datadog/tracing/contrib/mysql2/patcher_spec.rb | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb index 4bd8cac76e..3187a38707 100644 --- a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb @@ -28,7 +28,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end option :comment_propagation do |o| o.default do diff --git a/lib/datadog/tracing/contrib/mysql2/ext.rb b/lib/datadog/tracing/contrib/mysql2/ext.rb index a97d055659..885df0b805 100644 --- a/lib/datadog/tracing/contrib/mysql2/ext.rb +++ b/lib/datadog/tracing/contrib/mysql2/ext.rb @@ -8,6 +8,7 @@ module Mysql2 # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_MYSQL2_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_MYSQL2_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_MYSQL2_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MYSQL2_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'mysql2'.freeze diff --git a/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb b/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb index 23d086cbd4..dca140ad16 100644 --- a/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb @@ -5,6 +5,7 @@ require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/propagation/sql_comment' require 'datadog/tracing/contrib/sql_comment_propagation_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ddtrace' require 'mysql2' @@ -108,6 +109,10 @@ end it_behaves_like 'with sql comment propagation', span_op_name: 'mysql2.query' + + it_behaves_like 'environment service name', 'DD_TRACE_MYSQL2_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -125,6 +130,10 @@ end it_behaves_like 'with sql comment propagation', span_op_name: 'mysql2.query', error: Mysql2::Error + + it_behaves_like 'environment service name', 'DD_TRACE_MYSQL2_SERVICE_NAME', error: Mysql2::Error do + let(:configuration_options) { {} } + end end end end From 3d4593f6b70eb23915fa982e8634eb423c284ac9 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 14:49:29 +0100 Subject: [PATCH 14/19] Environment variable service_name for `pg` --- .../contrib/pg/configuration/settings.rb | 9 ++- lib/datadog/tracing/contrib/pg/ext.rb | 1 + .../tracing/contrib/pg/patcher_spec.rb | 76 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/pg/configuration/settings.rb b/lib/datadog/tracing/contrib/pg/configuration/settings.rb index d779a74406..dcb2f29eb6 100644 --- a/lib/datadog/tracing/contrib/pg/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/pg/configuration/settings.rb @@ -28,7 +28,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end option :comment_propagation do |o| o.default do diff --git a/lib/datadog/tracing/contrib/pg/ext.rb b/lib/datadog/tracing/contrib/pg/ext.rb index 799ecf1f8e..32e7970cb6 100644 --- a/lib/datadog/tracing/contrib/pg/ext.rb +++ b/lib/datadog/tracing/contrib/pg/ext.rb @@ -8,6 +8,7 @@ module Pg # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_PG_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_PG_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_PG_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_PG_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'pg'.freeze diff --git a/spec/datadog/tracing/contrib/pg/patcher_spec.rb b/spec/datadog/tracing/contrib/pg/patcher_spec.rb index c6dfa882fa..f1f49ff29e 100644 --- a/spec/datadog/tracing/contrib/pg/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/pg/patcher_spec.rb @@ -4,6 +4,7 @@ require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' require 'datadog/tracing/contrib/sql_comment_propagation_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'datadog/tracing/contrib/propagation/sql_comment/mode' @@ -124,6 +125,10 @@ it_behaves_like 'measured span for integration', false do before { exec } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -138,6 +143,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('column "invalid" does not exist')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -217,6 +226,10 @@ it_behaves_like 'measured span for integration', false do before { exec_params } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -233,6 +246,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('could not determine data type of parameter $1')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -305,6 +322,10 @@ it_behaves_like 'measured span for integration', false do before { exec_prepared } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -316,6 +337,11 @@ include('ERROR') & include('prepared statement "invalid prepared select 1" does not exist') ) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + subject { conn.exec_prepared('invalid prepared select 1', ['INVALID']) } + end end end @@ -395,6 +421,10 @@ it_behaves_like 'measured span for integration', false do before { async_exec } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -410,6 +440,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('column "invalid" does not exist')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -493,6 +527,10 @@ it_behaves_like 'measured span for integration', false do before { async_exec_params } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -508,6 +546,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('could not determine data type of parameter $1')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -585,6 +627,10 @@ it_behaves_like 'measured span for integration', false do before { async_exec_prepared } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -596,6 +642,11 @@ include('ERROR') & include('prepared statement "invalid prepared select 1" does not exist') ) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + subject { conn.async_exec_prepared('invalid prepared select 1', ['INVALID']) } + end end end @@ -681,6 +732,10 @@ it_behaves_like 'measured span for integration', false do before { sync_exec } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -694,6 +749,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('column "invalid" does not exist')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -774,6 +833,10 @@ it_behaves_like 'measured span for integration', false do before { sync_exec_params } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -790,6 +853,10 @@ expect(span).to have_error expect(span).to have_error_message(include('ERROR') & include('could not determine data type of parameter $1')) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + end end end @@ -865,6 +932,10 @@ it_behaves_like 'measured span for integration', false do before { sync_exec_prepared } end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME' do + let(:configuration_options) { {} } + end end context 'when a failed query is made' do @@ -876,6 +947,11 @@ include('ERROR') & include('prepared statement "invalid prepared select 1" does not exist') ) end + + it_behaves_like 'environment service name', 'DD_TRACE_PG_SERVICE_NAME', error: PG::Error do + let(:configuration_options) { {} } + subject { conn.sync_exec_prepared('invalid prepared select 1', ['INVALID']) } + end end end end From 135848fad71cb2ed2480d8bd2fbac3677216d1ed Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 15:45:03 +0100 Subject: [PATCH 15/19] Environment variable service_name for `redis` --- .../tracing/contrib/redis/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/redis/ext.rb | 1 + spec/datadog/tracing/contrib/redis/redis_spec.rb | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/redis/configuration/settings.rb b/lib/datadog/tracing/contrib/redis/configuration/settings.rb index 075c6d9f89..22c1979fe3 100644 --- a/lib/datadog/tracing/contrib/redis/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/redis/configuration/settings.rb @@ -31,7 +31,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/redis/ext.rb b/lib/datadog/tracing/contrib/redis/ext.rb index 3f0187c8b6..13882fbe2a 100644 --- a/lib/datadog/tracing/contrib/redis/ext.rb +++ b/lib/datadog/tracing/contrib/redis/ext.rb @@ -8,6 +8,7 @@ module Redis # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_REDIS_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_REDIS_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_REDIS_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_REDIS_ANALYTICS_SAMPLE_RATE'.freeze ENV_COMMAND_ARGS = 'DD_REDIS_COMMAND_ARGS'.freeze diff --git a/spec/datadog/tracing/contrib/redis/redis_spec.rb b/spec/datadog/tracing/contrib/redis/redis_spec.rb index bb76f8909a..8065fa5bab 100644 --- a/spec/datadog/tracing/contrib/redis/redis_spec.rb +++ b/spec/datadog/tracing/contrib/redis/redis_spec.rb @@ -6,6 +6,7 @@ require 'ddtrace' require_relative './shared_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' RSpec.describe 'Redis test' do let(:configuration_options) { {} } @@ -33,6 +34,10 @@ let(:redis_options) { default_redis_options } let(:redis) { Redis.new(redis_options.freeze) } + it_behaves_like 'environment service name', 'DD_TRACE_REDIS_SERVICE_NAME' do + subject { redis.ping } + end + context 'with default settings' do let(:configuration_options) { {} } From cd1a11b3839f80851f0075cccda8b99c85801bf0 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 15:57:13 +0100 Subject: [PATCH 16/19] Environment variable service_name for `rest_client` --- .../contrib/rest_client/configuration/settings.rb | 11 ++++++++++- lib/datadog/tracing/contrib/rest_client/ext.rb | 1 + .../tracing/contrib/rest_client/request_patch_spec.rb | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb index 36c0347c7e..6cff664730 100644 --- a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb @@ -27,7 +27,16 @@ class Settings < Contrib::Configuration::Settings end option :distributed_tracing, default: true - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end + option :split_by_domain, default: false end end diff --git a/lib/datadog/tracing/contrib/rest_client/ext.rb b/lib/datadog/tracing/contrib/rest_client/ext.rb index d429b83e8b..1f49072389 100644 --- a/lib/datadog/tracing/contrib/rest_client/ext.rb +++ b/lib/datadog/tracing/contrib/rest_client/ext.rb @@ -8,6 +8,7 @@ module RestClient # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_REST_CLIENT_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_REST_CLIENT_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_REST_CLIENT_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_REST_CLIENT_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'rest_client'.freeze diff --git a/spec/datadog/tracing/contrib/rest_client/request_patch_spec.rb b/spec/datadog/tracing/contrib/rest_client/request_patch_spec.rb index 06cec916e6..78fb497bd9 100644 --- a/spec/datadog/tracing/contrib/rest_client/request_patch_spec.rb +++ b/spec/datadog/tracing/contrib/rest_client/request_patch_spec.rb @@ -12,6 +12,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' RSpec.describe Datadog::Tracing::Contrib::RestClient::RequestPatch do let(:configuration_options) { {} } @@ -54,6 +55,8 @@ expect(request.body).to eq(response) end + it_behaves_like 'environment service name', 'DD_TRACE_REST_CLIENT_SERVICE_NAME' + describe 'created span' do context 'response is successfull' do before { request } @@ -228,6 +231,8 @@ it_behaves_like 'a peer service span' do let(:peer_hostname) { host } end + + it_behaves_like 'environment service name', 'DD_TRACE_REST_CLIENT_SERVICE_NAME' end end end From 9cd6b985a9f31e568b2df5432d9a40ade38ba662 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 6 Dec 2022 16:24:26 +0100 Subject: [PATCH 17/19] Environment variable service_name for `presto` --- .env | 2 +- docker-compose.yml | 1 + .../tracing/contrib/presto/configuration/settings.rb | 9 ++++++++- lib/datadog/tracing/contrib/presto/ext.rb | 1 + spec/datadog/tracing/contrib/presto/client_spec.rb | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 05685b76d8..0f6d55f4cc 100644 --- a/.env +++ b/.env @@ -24,7 +24,7 @@ TEST_POSTGRES_HOST=127.0.0.1 TEST_POSTGRES_PASSWORD=postgres TEST_POSTGRES_PORT=5432 TEST_POSTGRES_USER=postgres -TEST_PRESTO_HOST=localhost +TEST_PRESTO_HOST=presto TEST_PRESTO_PORT=8080 TEST_REDIS_HOST=127.0.0.1 TEST_REDIS_PORT=6379 diff --git a/docker-compose.yml b/docker-compose.yml index 35c9a2ebb6..759ca6ea49 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -179,6 +179,7 @@ services: - mongodb - mysql - postgres + - presto - redis - redis_old env_file: ./.env diff --git a/lib/datadog/tracing/contrib/presto/configuration/settings.rb b/lib/datadog/tracing/contrib/presto/configuration/settings.rb index f9f9511ba1..e3af4c5655 100644 --- a/lib/datadog/tracing/contrib/presto/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/presto/configuration/settings.rb @@ -26,7 +26,14 @@ class Settings < Contrib::Configuration::Settings o.lazy end - option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME + option :service_name do |o| + o.default do + ENV.fetch(Ext::ENV_SERVICE_NAME) do + Ext::DEFAULT_PEER_SERVICE_NAME + end + end + o.lazy + end end end end diff --git a/lib/datadog/tracing/contrib/presto/ext.rb b/lib/datadog/tracing/contrib/presto/ext.rb index 00e3eb48fd..a3dc8f65ba 100644 --- a/lib/datadog/tracing/contrib/presto/ext.rb +++ b/lib/datadog/tracing/contrib/presto/ext.rb @@ -8,6 +8,7 @@ module Presto # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_PRESTO_ENABLED'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_PRESTO_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_PRESTO_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_PRESTO_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'presto'.freeze diff --git a/spec/datadog/tracing/contrib/presto/client_spec.rb b/spec/datadog/tracing/contrib/presto/client_spec.rb index 9d2f640041..063a310c73 100644 --- a/spec/datadog/tracing/contrib/presto/client_spec.rb +++ b/spec/datadog/tracing/contrib/presto/client_spec.rb @@ -3,6 +3,7 @@ require 'datadog/tracing/contrib/integration_examples' require 'datadog/tracing/contrib/support/spec_helper' require 'datadog/tracing/contrib/analytics_examples' +require 'datadog/tracing/contrib/environment_service_name_examples' require 'ddtrace' require 'presto-client' @@ -108,6 +109,8 @@ def presto_online? shared_examples_for 'a configurable Presto trace' do context 'when the client is configured' do + it_behaves_like 'environment service name', 'DD_TRACE_PRESTO_SERVICE_NAME' + context 'with a different service name' do let(:service) { 'presto-primary' } let(:configuration_options) { { service_name: service } } From 70e2a084ca79cc0d2b790c0fab681b9cdb189b1b Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Wed, 7 Dec 2022 11:40:22 +0100 Subject: [PATCH 18/19] Rename environment variable with `DD_TRACE_NET_HTTP_SERVICE_NAME` --- lib/datadog/tracing/contrib/http/ext.rb | 2 +- spec/datadog/tracing/contrib/http/request_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/datadog/tracing/contrib/http/ext.rb b/lib/datadog/tracing/contrib/http/ext.rb index a30defa286..c34fa9f025 100644 --- a/lib/datadog/tracing/contrib/http/ext.rb +++ b/lib/datadog/tracing/contrib/http/ext.rb @@ -8,7 +8,7 @@ module HTTP # @public_api Changing resource names, tag names, or environment variables creates breaking changes. module Ext ENV_ENABLED = 'DD_TRACE_HTTP_ENABLED'.freeze - ENV_SERVICE_NAME = 'DD_TRACE_HTTP_SERVICE_NAME'.freeze + ENV_SERVICE_NAME = 'DD_TRACE_NET_HTTP_SERVICE_NAME'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTP_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTP_ANALYTICS_SAMPLE_RATE'.freeze DEFAULT_PEER_SERVICE_NAME = 'net/http'.freeze diff --git a/spec/datadog/tracing/contrib/http/request_spec.rb b/spec/datadog/tracing/contrib/http/request_spec.rb index 92df4d93c8..1822f66357 100644 --- a/spec/datadog/tracing/contrib/http/request_spec.rb +++ b/spec/datadog/tracing/contrib/http/request_spec.rb @@ -76,7 +76,7 @@ let(:peer_hostname) { host } end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME' end context 'that returns 404' do @@ -105,7 +105,7 @@ let(:peer_hostname) { host } end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME' context 'when configured with #after_request hook' do before { Datadog::Tracing::Contrib::HTTP::Instrumentation.after_request(&callback) } @@ -176,7 +176,7 @@ let(:peer_hostname) { host } end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME' end end @@ -211,7 +211,7 @@ let(:peer_hostname) { host } end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME' + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME' end end @@ -447,7 +447,7 @@ def expect_request_without_distributed_headers expect(span).to have_error_message(timeout_error.message) end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME', error: Net::OpenTimeout + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME', error: Net::OpenTimeout end context 'that raises an error' do @@ -472,7 +472,7 @@ def expect_request_without_distributed_headers expect(span).to have_error_message(custom_error.message) end - it_behaves_like 'environment service name', 'DD_TRACE_HTTP_SERVICE_NAME', error: StandardError + it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME', error: StandardError end end end From 45f4d522ab05e5e38a8eaa95a734a03095843725 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Wed, 7 Dec 2022 11:47:06 +0100 Subject: [PATCH 19/19] Refactor fetch semantic to evaluate string immediately --- lib/datadog/tracing/contrib/aws/configuration/settings.rb | 6 +----- .../tracing/contrib/dalli/configuration/settings.rb | 6 +----- .../contrib/elasticsearch/configuration/settings.rb | 7 ++----- .../tracing/contrib/ethon/configuration/settings.rb | 6 +----- .../tracing/contrib/excon/configuration/settings.rb | 6 +----- .../tracing/contrib/faraday/configuration/settings.rb | 6 +----- lib/datadog/tracing/contrib/grpc/configuration/settings.rb | 6 +----- lib/datadog/tracing/contrib/http/configuration/settings.rb | 6 +----- .../tracing/contrib/httpclient/configuration/settings.rb | 6 +----- .../tracing/contrib/httprb/configuration/settings.rb | 6 +----- .../tracing/contrib/mongodb/configuration/settings.rb | 6 +----- .../tracing/contrib/mysql2/configuration/settings.rb | 6 +----- lib/datadog/tracing/contrib/pg/configuration/settings.rb | 6 +----- .../tracing/contrib/presto/configuration/settings.rb | 6 +----- .../tracing/contrib/redis/configuration/settings.rb | 6 +----- .../tracing/contrib/rest_client/configuration/settings.rb | 6 +----- 16 files changed, 17 insertions(+), 80 deletions(-) diff --git a/lib/datadog/tracing/contrib/aws/configuration/settings.rb b/lib/datadog/tracing/contrib/aws/configuration/settings.rb index 0f782929d5..84d7190d1d 100644 --- a/lib/datadog/tracing/contrib/aws/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/aws/configuration/settings.rb @@ -27,11 +27,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb index f19578aafd..cea23452c1 100644 --- a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb @@ -27,11 +27,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb index 2bc557d19d..c5a94a02ac 100644 --- a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb @@ -27,12 +27,9 @@ class Settings < Contrib::Configuration::Settings end option :quantize, default: {} + option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb index ea80314736..bea2d12171 100644 --- a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb @@ -31,11 +31,7 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/excon/configuration/settings.rb b/lib/datadog/tracing/contrib/excon/configuration/settings.rb index c04aabc89f..db8ca40a4b 100644 --- a/lib/datadog/tracing/contrib/excon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/excon/configuration/settings.rb @@ -31,11 +31,7 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb index b752d2c539..df4e79b582 100644 --- a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb @@ -35,11 +35,7 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb index cfc7209244..aced6a1909 100644 --- a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb @@ -30,11 +30,7 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/http/configuration/settings.rb b/lib/datadog/tracing/contrib/http/configuration/settings.rb index 4197443a0e..bb7a37b941 100644 --- a/lib/datadog/tracing/contrib/http/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/http/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb index 9d51ced1e4..e919f4d36e 100644 --- a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb index e810571985..b977027520 100644 --- a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb index c578706f88..1f71212562 100644 --- a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb @@ -31,11 +31,7 @@ class Settings < Contrib::Configuration::Settings option :quantize, default: DEFAULT_QUANTIZE option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb index 3187a38707..82e5f73a27 100644 --- a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/pg/configuration/settings.rb b/lib/datadog/tracing/contrib/pg/configuration/settings.rb index dcb2f29eb6..0f11c283c8 100644 --- a/lib/datadog/tracing/contrib/pg/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/pg/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end diff --git a/lib/datadog/tracing/contrib/presto/configuration/settings.rb b/lib/datadog/tracing/contrib/presto/configuration/settings.rb index e3af4c5655..12fc3d2a77 100644 --- a/lib/datadog/tracing/contrib/presto/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/presto/configuration/settings.rb @@ -27,11 +27,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/redis/configuration/settings.rb b/lib/datadog/tracing/contrib/redis/configuration/settings.rb index 22c1979fe3..c2a45ae7c4 100644 --- a/lib/datadog/tracing/contrib/redis/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/redis/configuration/settings.rb @@ -32,11 +32,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end end diff --git a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb index 6cff664730..0434e77fe3 100644 --- a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb @@ -29,11 +29,7 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :service_name do |o| - o.default do - ENV.fetch(Ext::ENV_SERVICE_NAME) do - Ext::DEFAULT_PEER_SERVICE_NAME - end - end + o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) } o.lazy end