diff --git a/lib/datadog/core/telemetry/event.rb b/lib/datadog/core/telemetry/event.rb index 7395cf8cdc0..a6c1c3d901c 100644 --- a/lib/datadog/core/telemetry/event.rb +++ b/lib/datadog/core/telemetry/event.rb @@ -103,6 +103,11 @@ def configuration config.tracing.contrib.global_default_service_name.enabled, seq_id ), + conf_value( + 'DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED', + config.tracing.contrib.peer_service_defaults, + seq_id + ), ] peer_service_mapping_str = '' diff --git a/lib/datadog/tracing/configuration/ext.rb b/lib/datadog/tracing/configuration/ext.rb index 5823d2f9e53..22660c509df 100644 --- a/lib/datadog/tracing/configuration/ext.rb +++ b/lib/datadog/tracing/configuration/ext.rb @@ -16,6 +16,7 @@ module Ext # @public_api module SpanAttributeSchema ENV_GLOBAL_DEFAULT_SERVICE_NAME_ENABLED = 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED' + ENV_PEER_SERVICE_DEFAULTS_ENABLED = 'DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' ENV_PEER_SERVICE_MAPPING = 'DD_TRACE_PEER_SERVICE_MAPPING' end diff --git a/lib/datadog/tracing/contrib/extensions.rb b/lib/datadog/tracing/contrib/extensions.rb index fde0a34c0f0..fa83e4a6f3b 100644 --- a/lib/datadog/tracing/contrib/extensions.rb +++ b/lib/datadog/tracing/contrib/extensions.rb @@ -123,6 +123,20 @@ def self.included(base) o.default({}) end + # Enables population of default in the `peer.service` span tag. + # Explicitly setting the `peer.service` for an integration will + # still be honored with this option disabled. + # + # Also when disabled, other peer service related configurations have no effect. + # + # @default `DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED` environment variable, otherwise `false` + # @return [Boolean] + option :peer_service_defaults do |o| + o.env Tracing::Configuration::Ext::SpanAttributeSchema::ENV_PEER_SERVICE_DEFAULTS_ENABLED + o.type :bool + o.default false + end + # Global service name behavior settings :global_default_service_name do # Overrides default service name to global service name diff --git a/lib/datadog/tracing/contrib/span_attribute_schema.rb b/lib/datadog/tracing/contrib/span_attribute_schema.rb index b90beb1a0df..a338dedef01 100644 --- a/lib/datadog/tracing/contrib/span_attribute_schema.rb +++ b/lib/datadog/tracing/contrib/span_attribute_schema.rb @@ -21,9 +21,14 @@ def self.fetch_service_name(env, default) end def self.set_peer_service!(span, sources) + config = Datadog.configuration.tracing.contrib + + # If `peer_service_defaults` is disabled, we only read peer service from an explicitly set `peer.service` tag + sources = Datadog::Tracing::Contrib::SpanAttributeSchema::REFLEXIVE_SOURCES unless config.peer_service_defaults + # Acquire all peer.service values as well as any potential remapping peer_service_val, peer_service_source = set_peer_service_from_source(span, sources) - remap_val = Datadog.configuration.tracing.contrib.peer_service_mapping[peer_service_val] + remap_val = config.peer_service_mapping[peer_service_val] # Only continue to setting peer.service if actual source is found return false unless peer_service_source diff --git a/sig/datadog/tracing/configuration/ext.rbs b/sig/datadog/tracing/configuration/ext.rbs index 01c18cd981f..4cea777ee40 100644 --- a/sig/datadog/tracing/configuration/ext.rbs +++ b/sig/datadog/tracing/configuration/ext.rbs @@ -7,6 +7,7 @@ module Datadog ENV_TRACE_ID_128_BIT_GENERATION_ENABLED: "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED" module SpanAttributeSchema ENV_GLOBAL_DEFAULT_SERVICE_NAME_ENABLED: "DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED" + ENV_PEER_SERVICE_DEFAULTS_ENABLED: string ENV_PEER_SERVICE_MAPPING: "DD_TRACE_PEER_SERVICE_MAPPING" end module Analytics diff --git a/sig/datadog/tracing/contrib/extensions.rbs b/sig/datadog/tracing/contrib/extensions.rbs index fd58d2fd56a..72e61e8a4dd 100644 --- a/sig/datadog/tracing/contrib/extensions.rbs +++ b/sig/datadog/tracing/contrib/extensions.rbs @@ -9,8 +9,8 @@ module Datadog module Configuration def configure: () ?{ () -> untyped } -> untyped module Settings - InvalidIntegrationError: untyped - def instrument: (untyped integration_name, ?::Hash[untyped, untyped] options) ?{ () -> untyped } -> untyped + InvalidIntegrationError: StandardError + def instrument: (Symbol integration_name, ?::Hash[Symbol, untyped] options) ?{ () -> untyped } -> Contrib::Integration alias use instrument def []: (untyped integration_name, ?::Symbol key) -> untyped def integrations_pending_activation: () -> untyped diff --git a/sig/datadog/tracing/contrib/span_attribute_schema.rbs b/sig/datadog/tracing/contrib/span_attribute_schema.rbs index 40360360bf1..17a2c5d3365 100644 --- a/sig/datadog/tracing/contrib/span_attribute_schema.rbs +++ b/sig/datadog/tracing/contrib/span_attribute_schema.rbs @@ -2,20 +2,18 @@ module Datadog module Tracing module Contrib module SpanAttributeSchema - PEER_SERVICE_SOURCE_DB: Array[string] - PEER_SERVICE_SOURCE_DEFAULT: Array[string] - PEER_SERVICE_SOURCE_MSG: Array[string] - PEER_SERVICE_SOURCE_RPC: Array[string] + NO_SOURCE: Array[string] + REFLEXIVE_SOURCES: Array[string] def self?.fetch_service_name: (string env, string default) -> bool - def not_empty_tag?: (string) -> bool + def self.filter_peer_service_sources: (SpanOperation span, Array[string] sources) -> Array[string] - def set_peer_service: -> bool + def self.not_empty_tag?: (string tag) -> bool - def set_peer_service?: -> bool + def self.set_peer_service!: (SpanOperation span, Array[string] sources) -> bool - def set_peer_service_from_source: -> bool + def self.set_peer_service_from_source: (SpanOperation span, Array[string] sources) -> [string, string] end end end diff --git a/spec/datadog/core/telemetry/event_spec.rb b/spec/datadog/core/telemetry/event_spec.rb index b8eee1f48d8..ae0af705b29 100644 --- a/spec/datadog/core/telemetry/event_spec.rb +++ b/spec/datadog/core/telemetry/event_spec.rb @@ -52,6 +52,7 @@ def contain_configuration(*array) ['DD_AGENT_TRANSPORT', 'TCP'], ['DD_TRACE_SAMPLE_RATE', '0.5'], ['DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED', true], + ['DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED', false], ['DD_TRACE_PEER_SERVICE_MAPPING', 'foo:bar'], ['logger.level', 0], ['profiling.advanced.code_provenance_enabled', true], diff --git a/spec/datadog/tracing/contrib/extensions_spec.rb b/spec/datadog/tracing/contrib/extensions_spec.rb index 461fd09852f..e7c338ceb4e 100644 --- a/spec/datadog/tracing/contrib/extensions_spec.rb +++ b/spec/datadog/tracing/contrib/extensions_spec.rb @@ -91,6 +91,30 @@ end end + describe '#peer_service_defaults' do + subject { settings.contrib.peer_service_defaults } + + context 'when given environment variable DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' do + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => env_var) do + example.run + end + end + + context 'is not defined' do + let(:env_var) { nil } + + it { is_expected.to be false } + end + + context 'is defined' do + let(:env_var) { 'true' } + + it { is_expected.to be true } + end + end + end + describe '#global_default_service_name_enabled' do subject { settings.contrib.global_default_service_name.enabled } diff --git a/spec/datadog/tracing/contrib/http/miniapp_spec.rb b/spec/datadog/tracing/contrib/http/miniapp_spec.rb index b8a9a04d216..d86adef8637 100644 --- a/spec/datadog/tracing/contrib/http/miniapp_spec.rb +++ b/spec/datadog/tracing/contrib/http/miniapp_spec.rb @@ -59,7 +59,6 @@ http_spans.each do |span| expect(span.name).to eq('http.request') expect(span.service).to eq('net/http') - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)).to eq(host) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.resource).to eq('GET') expect(span.get_tag('http.url')).to eq('/my/path') diff --git a/spec/datadog/tracing/contrib/integration_examples.rb b/spec/datadog/tracing/contrib/integration_examples.rb index 18ab561f855..652af73326d 100644 --- a/spec/datadog/tracing/contrib/integration_examples.rb +++ b/spec/datadog/tracing/contrib/integration_examples.rb @@ -5,12 +5,25 @@ skip('No let(:peer_service_source) defined.') unless defined?(peer_service_source) end - context 'extracted peer service' do + context 'with default peer services enabled' do + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => 'true') do + example.run + end + end + it 'contains extracted peer service tag' do expect(span.get_tag('peer.service')).to eq(peer_service_val) expect(span.get_tag('_dd.peer.service.source')).to eq(peer_service_source) end end + + context 'with default peer services disabled' do + it 'does not contain extracted peer service tag' do + expect(span.get_tag('peer.service')).to be_nil + expect(span.get_tag('_dd.peer.service.source')).to be_nil + end + end end RSpec.shared_examples 'a non-peer service span' do diff --git a/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb b/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb index b3bba5563cc..3c102346b37 100644 --- a/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/mysql2/patcher_spec.rb @@ -73,7 +73,6 @@ expect(span.service).to eq(service_name) expect(span.get_tag('span.kind')).to eq('client') expect(span.get_tag('db.system')).to eq('mysql') - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)).to eq(database) end it_behaves_like 'with sql comment propagation', span_op_name: 'mysql2.query' diff --git a/spec/datadog/tracing/contrib/peer_service_configuration_examples.rb b/spec/datadog/tracing/contrib/peer_service_configuration_examples.rb index 2b4014913f6..277aa9ffe78 100644 --- a/spec/datadog/tracing/contrib/peer_service_configuration_examples.rb +++ b/spec/datadog/tracing/contrib/peer_service_configuration_examples.rb @@ -14,19 +14,47 @@ end end - context 'when env_var configured' do - it 'expects peer.service to equal env var value and source to be peer.service' do - expect(span.get_tag('peer.service')).to eq('configured_peer_service_via_env_var') - expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + context 'with default peer services enabled' do + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => 'true') do + example.run + end + end + + context 'when env_var configured' do + it 'expects peer.service to equal env var value and source to be peer.service' do + expect(span.get_tag('peer.service')).to eq('configured_peer_service_via_env_var') + expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + end + end + + context 'when peer_service option is configured' do + let(:configuration_options) { { peer_service: 'configured_peer_service' } } + + it 'expects peer.service to equal configured value and source to be peer.service' do + expect(span.get_tag('peer.service')).to eq(configuration_options[:peer_service]) + expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + end end end - context 'when peer_service option is configured' do - let(:configuration_options) { { peer_service: 'configured_peer_service' } } + context 'with default peer services disabled' do + # We still set the `peer.service` tag when it is explicitly configured + + context 'when env_var configured' do + it 'expects peer.service to equal env var value and source to be peer.service' do + expect(span.get_tag('peer.service')).to eq('configured_peer_service_via_env_var') + expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + end + end + + context 'when peer_service option is configured' do + let(:configuration_options) { { peer_service: 'configured_peer_service' } } - it 'expects peer.service to equal configured value and source to be peer.service' do - expect(span.get_tag('peer.service')).to eq(configuration_options[:peer_service]) - expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + it 'expects peer.service to equal configured value and source to be peer.service' do + expect(span.get_tag('peer.service')).to eq(configuration_options[:peer_service]) + expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + end end end end diff --git a/spec/datadog/tracing/contrib/pg/patcher_spec.rb b/spec/datadog/tracing/contrib/pg/patcher_spec.rb index 33dbdae4408..99ec1731390 100644 --- a/spec/datadog/tracing/contrib/pg/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/pg/patcher_spec.rb @@ -109,8 +109,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -244,8 +242,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -383,8 +379,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -510,8 +504,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -650,8 +642,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -769,8 +759,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -911,8 +899,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1037,8 +1023,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1185,8 +1169,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1311,8 +1293,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1451,8 +1431,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1571,8 +1549,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1719,8 +1695,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1843,8 +1817,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -1983,8 +1955,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -2108,9 +2078,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) expect(span.get_tag('db.system')).to eq('postgresql') @@ -2246,8 +2213,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) @@ -2364,8 +2329,6 @@ .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_COMPONENT) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq(Datadog::Tracing::Contrib::Pg::Ext::TAG_OPERATION_QUERY) - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)) - .to eq(dbname) expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME)).to eq(host) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE)).to eq(dbname) expect(span.get_tag(Datadog::Tracing::Contrib::Ext::DB::TAG_USER)).to eq(user) diff --git a/spec/datadog/tracing/contrib/span_attribute_schema_spec.rb b/spec/datadog/tracing/contrib/span_attribute_schema_spec.rb index ca4e86ddfbb..fded36969f0 100644 --- a/spec/datadog/tracing/contrib/span_attribute_schema_spec.rb +++ b/spec/datadog/tracing/contrib/span_attribute_schema_spec.rb @@ -52,6 +52,14 @@ describe '#set_peer_service!' do let(:span) { Datadog::Tracing::Span.new('testPeerServiceLogicSpan', parent_id: 0) } + subject(:set_peer_service!) { described_class.set_peer_service!(span, precursors) } + + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => 'true') do + example.run + end + end + context 'precursor tags set' do context 'AWS Span' do let(:precursors) do @@ -79,6 +87,31 @@ span.clear_tag(precursor) end end + + context 'peer service defaults disabled' do + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => 'false') do + example.run + end + end + + it 'does not set peer.service' do + span.set_tag('aws_service', 'test-service') + span.set_tag('span.kind', 'client') + precursors.each do |precursor| + span.set_tag(precursor, 'test-' << precursor) + + set_peer_service! + expect(span.get_tag('peer.service')).to be_nil + expect(span.get_tag('_dd.peer.service.source')).to be_nil + expect(span.get_tag('_dd.peer.service.remapped_from')).to be_nil + + span.clear_tag('peer.service') + span.clear_tag('_dd.peer.service.source') + span.clear_tag(precursor) + end + end + end end context 'DB Span' do @@ -257,6 +290,23 @@ expect(span.get_tag('_dd.peer.service.remapped_from')).to eq('peer-service-value') end end + + context 'peer service defaults disabled' do + around do |example| + ClimateControl.modify('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED' => 'false') do + example.run + end + end + + it 'keeps explicit peer.service' do + span.set_tag('peer.service', 'peer-service-value') + + set_peer_service! + + expect(span.get_tag('peer.service')).to eq('peer-service-value') + expect(span.get_tag('_dd.peer.service.source')).to eq('peer.service') + end + end end context 'remapping tags' do diff --git a/spec/datadog/tracing/contrib/trilogy/patcher_spec.rb b/spec/datadog/tracing/contrib/trilogy/patcher_spec.rb index 0ba135328f0..bcc94f3aa47 100644 --- a/spec/datadog/tracing/contrib/trilogy/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/trilogy/patcher_spec.rb @@ -73,7 +73,6 @@ expect(span.service).to eq(service_name) expect(span.get_tag('span.kind')).to eq('client') expect(span.get_tag('db.system')).to eq('mysql') - expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE)).to eq(database) end it_behaves_like 'with sql comment propagation', span_op_name: 'trilogy.query'