Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-instrumentation with service_name from environmental variable #2455

Merged
merged 19 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ services:
- mongodb
- mysql
- postgres
- presto
- redis
- redis_old
env_file: ./.env
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/aws/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/aws/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/dalli/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/elasticsearch/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/ethon/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/excon/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/faraday/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end

option :error_handler, default: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/grpc/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end

option :split_by_domain, default: false
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/http/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end

option :split_by_domain, default: false
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/httpclient/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end

option :split_by_domain, default: false
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/httprb/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/mongodb/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

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

option :comment_propagation do |o|
o.default do
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/mysql2/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/pg/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

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

option :comment_propagation do |o|
o.default do
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/pg/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/presto/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
option :service_name do |o|
o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/redis/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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 { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
o.lazy
end

option :split_by_domain, default: false
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/rest_client/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/datadog/tracing/contrib/aws/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on creating a shared example! Super clean! 🧹


it 'generates a span' do
expect(span.name).to eq('aws.command')
Expand Down Expand Up @@ -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')
Expand Down
Loading