Skip to content

Commit

Permalink
Merge pull request #2765 from DataDog/zarir/service-name-integrations…
Browse files Browse the repository at this point in the history
…-part-two

Change default `service_name` values Part 2
  • Loading branch information
TonyCTHsu authored May 4, 2023
2 parents 354f7c7 + 86f9593 commit 8c6384d
Show file tree
Hide file tree
Showing 43 changed files with 307 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :cache_service, default: Ext::SERVICE_CACHE
option :cache_service do |o|
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
'',
Ext::SERVICE_CACHE
)
end
o.lazy
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Settings < Contrib::Configuration::Settings
option :distributed_tracing, default: true

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end

Expand Down
7 changes: 5 additions & 2 deletions lib/datadog/tracing/contrib/httpclient/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ def annotate_span_with_request!(span, req, req_options)
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, uri.host)
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, uri.port)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, uri.host)

set_analytics_sample_rate(span, req_options)
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/tracing/contrib/httprb/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Settings < Contrib::Configuration::Settings
option :distributed_tracing, default: true

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end

Expand Down
6 changes: 4 additions & 2 deletions lib/datadog/tracing/contrib/httprb/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def annotate_span_with_request!(span, req, req_options)
logger.debug("service #{req_options[:service_name]} span #{Ext::SPAN_REQUEST} missing uri")
end

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

set_analytics_sample_rate(span, req_options)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class Settings < Contrib::Configuration::Settings
option :quantize, default: DEFAULT_QUANTIZE

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/datadog/tracing/contrib/mongodb/subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ def started(event)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, event.address.host)

# Set analytics sample rate
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/tracing/contrib/mysql2/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Settings < Contrib::Configuration::Settings
end

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end

Expand Down
7 changes: 5 additions & 2 deletions lib/datadog/tracing/contrib/mysql2/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def query(sql, options = {})
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, query_options[:host])

# Set analytics sample rate
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/tracing/contrib/pg/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Settings < Contrib::Configuration::Settings
end

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end

Expand Down
7 changes: 5 additions & 2 deletions lib/datadog/tracing/contrib/pg/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ def annotate_span_with_query!(span, service)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, host)

span.set_tag(Contrib::Ext::DB::TAG_INSTANCE, db)
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/tracing/contrib/presto/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class Settings < Contrib::Configuration::Settings
end

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/datadog/tracing/contrib/presto/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def decorate!(span, operation)
set_nilable_tag!(span, :http_proxy, Ext::TAG_PROXY)
set_nilable_tag!(span, :model_version, Ext::TAG_MODEL_VERSION)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

# Set analytics sample rate
if Contrib::Analytics.enabled?(datadog_configuration[:analytics_enabled])
Expand Down
10 changes: 9 additions & 1 deletion lib/datadog/tracing/contrib/racecar/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ 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
Contrib::SpanAttributeSchema.fetch_service_name(
'',
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/tracing/contrib/racecar/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def process(span, event, _id, payload)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

# Set analytics sample rate
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/tracing/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ def trace_http_server(span_name, start_time:)
)

# Set peer service (so its not believed to belong to this app)
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, configuration[:web_service_name])
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, configuration[:web_service_name])
end

span
end
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/tracing/contrib/redis/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class Settings < Contrib::Configuration::Settings
end

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/redis/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def set_common_tags(client, span, show_command_args)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, client.host)

span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Settings < Contrib::Configuration::Settings
option :distributed_tracing, default: true

option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.default do
Contrib::SpanAttributeSchema.fetch_service_name(
Ext::ENV_SERVICE_NAME,
Ext::DEFAULT_PEER_SERVICE_NAME
)
end
o.lazy
end

Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/rest_client/request_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def datadog_tag_request(uri, span)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, uri.host)

# Set analytics sample rate
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/sequel/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def run(sql, options = ::Sequel::OPTS)
Tracing.trace(Ext::SPAN_QUERY) do |span|
span.service = Datadog.configuration_for(self, :service_name) \
|| Datadog.configuration.tracing[:sequel][:service_name] \
|| adapter_name
|| Contrib::SpanAttributeSchema.fetch_service_name(
'',
adapter_name
)
span.resource = opts[:query]
span.span_type = Tracing::Metadata::Ext::SQL::TYPE
Utils.set_common_tags(span, self)
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/sequel/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def trace_execute(super_method, sql, options, &block)
Tracing.trace(Ext::SPAN_QUERY) do |span|
span.service = Datadog.configuration_for(db, :service_name) \
|| Datadog.configuration.tracing[:sequel][:service_name] \
|| adapter_name
|| Contrib::SpanAttributeSchema.fetch_service_name(
'',
adapter_name
)
span.resource = opts[:query]
span.span_type = Tracing::Metadata::Ext::SQL::TYPE
Utils.set_common_tags(span, db)
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/sequel/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def set_common_tags(span, db)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)

# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
if Contrib::SpanAttributeSchema.default_span_attribute_schema?
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

# TODO: Extract host for Sequel with JDBC. The easiest way seem to be through
# TODO: the database URI. Unfortunately, JDBC URIs do not work with `URI.parse`.
# host, _port = extract_host_port_from_uri(db.uri)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'datadog/tracing/contrib/active_support/configuration/settings'
require 'datadog/tracing/contrib/service_name_settings_examples'

RSpec.describe Datadog::Tracing::Contrib::ActiveSupport::Configuration::Settings do
describe 'Option `cache_service`' do
context 'when with cache_service' do # default to include base
it do
expect(described_class.new(cache_service: 'test-service').cache_service).to eq('test-service')
end
end

context 'when without service_name v0' do # default to include base
it do
with_modified_env DD_TRACE_SPAN_ATTRIBUTE_SCHEMA: 'v0' do
expect(described_class.new.cache_service).to eq('active_support-cache')
end
end
end

context 'when without service_name v1' do # default to include base
it do
with_modified_env DD_TRACE_SPAN_ATTRIBUTE_SCHEMA: 'v1' do
expect(described_class.new.cache_service).to eq('rspec')
end
end
end
end

def with_modified_env(options = {}, &block)
ClimateControl.modify(options, &block)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'datadog/tracing/contrib/httpclient/configuration/settings'
require 'datadog/tracing/contrib/service_name_settings_examples'

RSpec.describe Datadog::Tracing::Contrib::Httpclient::Configuration::Settings do
it_behaves_like 'service name setting', 'httpclient'
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'datadog/tracing/contrib/integration_examples'
require 'datadog/tracing/contrib/support/spec_helper'
require 'datadog/tracing/contrib/environment_service_name_examples'
require 'datadog/tracing/contrib/span_attribute_schema_examples'
require 'datadog/tracing/contrib/http_examples'
require 'spec/support/thread_helpers'

Expand Down Expand Up @@ -138,6 +139,7 @@
end

it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME'
it_behaves_like 'schema version span'

it_behaves_like 'analytics for integration' do
let(:analytics_enabled_var) { Datadog::Tracing::Contrib::Httpclient::Ext::ENV_ANALYTICS_ENABLED }
Expand Down Expand Up @@ -168,6 +170,7 @@
end

it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME'
it_behaves_like 'schema version span'
end

context 'response has not found status' do
Expand All @@ -193,6 +196,7 @@
end

it_behaves_like 'environment service name', 'DD_TRACE_HTTPCLIENT_SERVICE_NAME'
it_behaves_like 'schema version span'
end

context 'distributed tracing default' do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'datadog/tracing/contrib/httprb/configuration/settings'
require 'datadog/tracing/contrib/service_name_settings_examples'

RSpec.describe Datadog::Tracing::Contrib::Httprb::Configuration::Settings do
it_behaves_like 'service name setting', 'httprb'
end
Loading

0 comments on commit 8c6384d

Please sign in to comment.