Skip to content

Commit

Permalink
server.address
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jul 25, 2024
1 parent 2f591a1 commit b4822bb
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_MEMCACHED_PORT=11211
TEST_MONGODB_HOST=127.0.0.1
TEST_MONGODB_PORT=27017
TEST_MYSQL_DB=mysql
TEST_MYSQL_HOST=127.0.0.1
TEST_MYSQL_HOST=localhost
TEST_MYSQL_PASSWORD=mysql
TEST_MYSQL_PORT=3306
TEST_MYSQL_ROOT_PASSWORD=root
Expand Down
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--require spec_helper
--backtrace
19 changes: 19 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ end
#
# TODO: Remove this once the issue is resolved: https://github.com/ffi/ffi/issues/1107
gem 'ffi', '~> 1.16.3', require: false

gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596

gem 'rails', '~> 6'
gem 'mysql2'
gem 'trilogy'
gem 'pg'
gem 'dalli'
gem 'elasticsearch'

gem 'ethon'
gem 'excon'
gem 'faraday'
gem 'http'
gem 'httpclient'
gem 'rest-client'
gem 'stripe', '~> 7.0'
gem 'typhoeus'
gem 'redis'
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/propagation/sql_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.prepend_comment(sql, span_op, trace_op, mode)
end
end

"#{Comment.new(tags)} #{sql}"
"#{sql} #{Comment.new(tags)}"
end

def self.datadog_configuration
Expand Down
7 changes: 7 additions & 0 deletions lib/datadog/tracing/metadata/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ module Ext
# Name of external service that performed the work
TAG_PEER_SERVICE = 'peer.service'

# The server domain name that the network client is talking to,
# before DNS resolution (e.g. what the user provided in the client's initializer/configuration);
# otherwise, IP address or Unix domain socket name.
#
# @see https://opentelemetry.io/docs/specs/semconv/general/attributes/#server-attributes
TAG_SERVER_ADDRESS = 'server.address'

TAG_KIND = 'span.kind'

# Set this tag to `1.0` if the span is a Service Entry span.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
let(:mysql) do
{
database: ENV.fetch('TEST_MYSQL_DB', 'mysql'),
host: ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1'),
host: ENV.fetch('TEST_MYSQL_HOST', 'localhost'),
password: ENV.fetch('TEST_MYSQL_ROOT_PASSWORD', 'root'),
port: ENV.fetch('TEST_MYSQL_PORT', '3306')
}
Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/tracing/contrib/active_record/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
expect(span.get_tag('db.instance')).to eq('mysql')
expect(span.get_tag('active_record.db.name')).to eq('mysql')
expect(span.get_tag('active_record.db.cached')).to eq(nil)
# TODO: MYSQL is correct CONTINUE WITH OTHERS
expect(span.get_tag('out.host')).to eq(ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1'))
expect(span.get_tag('out.host')).to_not be_an_ip_address if PlatformHelpers.ci? # This test is hard to run locally because mysql considers `localhost` as a unix socket
expect(span.get_tag('out.port')).to eq(ENV.fetch('TEST_MYSQL_PORT', 3306).to_f)
expect(span.get_tag('sql.query')).to eq(nil)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('active_record')
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/tracing/contrib/active_record/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
context 'when connected to mysql' do
it 'returns `mysql2`' do
root_pw = ENV.fetch('TEST_MYSQL_ROOT_PASSWORD', 'root')
host = ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1')
host = ENV.fetch('TEST_MYSQL_HOST', 'localhost')
port = ENV.fetch('TEST_MYSQL_PORT', '3306')
db = ENV.fetch('TEST_MYSQL_DB', 'mysql')

Expand All @@ -23,7 +23,7 @@
describe 'regression: retrieving database without an active connection does not raise an error' do
before do
root_pw = ENV.fetch('TEST_MYSQL_ROOT_PASSWORD', 'root')
host = ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1')
host = ENV.fetch('TEST_MYSQL_HOST', 'localhost')
port = ENV.fetch('TEST_MYSQL_PORT', '3306')
db = ENV.fetch('TEST_MYSQL_DB', 'mysql')
ActiveRecord::Base.establish_connection("mysql2://root:#{root_pw}@#{host}:#{port}/#{db}")
Expand All @@ -32,7 +32,7 @@

after do
root_pw = ENV.fetch('TEST_MYSQL_ROOT_PASSWORD', 'root')
host = ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1')
host = ENV.fetch('TEST_MYSQL_HOST', 'localhost')
port = ENV.fetch('TEST_MYSQL_PORT', '3306')
db = ENV.fetch('TEST_MYSQL_DB', 'mysql')
ActiveRecord::Base.establish_connection("mysql2://root:#{root_pw}@#{host}:#{port}/#{db}")
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/contrib/dalli/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'datadog/tracing/contrib/dalli/patcher'

RSpec.describe 'Dalli instrumentation' do
let(:test_host) { ENV.fetch('TEST_MEMCACHED_HOST', '127.0.0.1') }
let(:test_host) { ENV.fetch('TEST_MEMCACHED_HOST', 'localhost') }
let(:test_port) { ENV.fetch('TEST_MEMCACHED_PORT', '11211') }

let(:client) { ::Dalli::Client.new("#{test_host}:#{test_port}") }
Expand Down Expand Up @@ -72,6 +72,7 @@
expect(span.resource).to eq('SET')
expect(span).to_not have_tag('memcached.command')
expect(span.get_tag('out.host')).to eq(test_host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(test_port.to_f)
expect(span.get_tag('db.system')).to eq('memcached')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_KIND)).to eq('client')
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
WebMock.disable!
end

let(:host) { ENV.fetch('TEST_ELASTICSEARCH_HOST', '127.0.0.1').freeze }
let(:host) { ENV.fetch('TEST_ELASTICSEARCH_HOST', 'localhost').freeze }
let(:port) { ENV.fetch('TEST_ELASTICSEARCH_PORT', '1234').to_i }
let(:server) { "http://#{host}:#{port}" }

Expand Down Expand Up @@ -111,6 +111,7 @@ def call(env)
expect(span.get_tag('elasticsearch.params')).to be nil
expect(span.get_tag('elasticsearch.body')).to be nil
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(port)
end

Expand Down
1 change: 1 addition & 0 deletions spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
expect(span.get_tag('out.host')).to_not be_an_ip_address
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/datadog/tracing/contrib/excon/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
expect(span.get_tag('out.host')).to_not be_an_ip_address
end
end

Expand Down
15 changes: 8 additions & 7 deletions spec/datadog/tracing/contrib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
WebMock.disable!
end

let(:host) { '127.0.0.1' }
let(:host) { 'localhost' }
let(:port) { 1234 }
let(:uri) { "http://#{host}:#{port}" }
let(:path) { '/my/path' }
Expand Down Expand Up @@ -66,6 +66,7 @@
expect(span.get_tag('http.method')).to eq('GET')
expect(span.get_tag('http.status_code')).to eq('200')
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(port.to_s)
expect(span.get_tag('span.kind')).to eq('client')
expect(span.status).to eq(0)
Expand All @@ -82,7 +83,7 @@
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { '127.0.0.1' }
let(:peer_service_val) { 'localhost' }
let(:peer_service_source) { 'peer.hostname' }
end

Expand Down Expand Up @@ -135,7 +136,7 @@
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { '127.0.0.1' }
let(:peer_service_val) { 'localhost' }
let(:peer_service_source) { 'peer.hostname' }
end

Expand Down Expand Up @@ -169,7 +170,7 @@
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { '127.0.0.1' }
let(:peer_service_val) { 'localhost' }
let(:peer_service_source) { 'peer.hostname' }
end

Expand Down Expand Up @@ -206,7 +207,7 @@
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { '127.0.0.1' }
let(:peer_service_val) { 'localhost' }
let(:peer_service_source) { 'peer.hostname' }
end

Expand Down Expand Up @@ -260,7 +261,7 @@
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { '127.0.0.1' }
let(:peer_service_val) { 'localhost' }
let(:peer_service_source) { 'peer.hostname' }
end
end
Expand All @@ -285,7 +286,7 @@
before do
Datadog.configure do |c|
c.tracing.instrument :http, configuration_options
c.tracing.instrument :http, describes: /127.0.0.1/ do |http|
c.tracing.instrument :http, describes: /localhost/ do |http|
http.service_name = 'bar'
http.split_by_domain = false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('localhost')
expect(span.get_tag('out.host')).to_not be_an_ip_address
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('localhost')
expect(span.get_tag('out.host')).to_not be_an_ip_address
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/tracing/contrib/mongodb/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
expect(spans.first.service).to eq(secondary_service)
end

it 'captures the unresolved host name' do
subject
expect(spans.first.get_tag('out.host')).to eq('localhost')
end

it_behaves_like 'a peer service span' do
let(:peer_service_val) { database }
let(:peer_service_source) { 'mongodb.db' }
Expand Down Expand Up @@ -155,6 +160,7 @@
expect(span.get_tag('mongodb.collection')).to eq(collection_value)
expect(span.get_tag('db.mongodb.collection')).to eq(collection_value)
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(port)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('mongodb')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)).to eq('command')
Expand Down
1 change: 1 addition & 0 deletions spec/datadog/tracing/contrib/mysql2/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
expect(span.get_tag('db.instance')).to eq(database)
expect(span.get_tag('mysql2.db.name')).to eq(database)
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address if PlatformHelpers.ci? # This test is hard to run locally because mysql considers `localhost` as a unix socket
expect(span.get_tag('out.port')).to eq(port)
expect(span.get_tag('db.system')).to eq('mysql')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('mysql2')
Expand Down
5 changes: 3 additions & 2 deletions spec/datadog/tracing/contrib/pg/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
end

let(:host) { ENV.fetch('TEST_POSTGRES_HOST') { '127.0.0.1' } }
let(:host) { ENV.fetch('TEST_POSTGRES_HOST') { 'localhost' } }
let(:port) { ENV.fetch('TEST_POSTGRES_PORT') { '5432' } }
let(:dbname) { ENV.fetch('TEST_POSTGRES_DB') { 'postgres' } }
let(:user) { ENV.fetch('TEST_POSTGRES_USER') { 'postgres' } }
Expand Down Expand Up @@ -115,7 +115,8 @@
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')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_HOST)).to eq(host)
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_PORT)).to eq(port.to_i)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::NET::TAG_DESTINATION_NAME)).to eq(host)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::NET::TAG_DESTINATION_PORT)).to eq(port.to_i)
Expand Down
1 change: 1 addition & 0 deletions spec/datadog/tracing/contrib/presto/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def presto_online?
expect(span.get_tag('presto.http_proxy')).to eq(http_proxy)
expect(span.get_tag('presto.model_version')).to eq(model_version)
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(port)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('presto')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)).to eq(operation)
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/rails/support/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def mysql_url(protocol = 'mysql2')
def mysql_hash
{
database: ENV.fetch('TEST_MYSQL_DB', 'mysql'),
host: ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1'),
host: ENV.fetch('TEST_MYSQL_HOST', 'localhost'),
password: ENV.fetch('TEST_MYSQL_ROOT_PASSWORD', 'root'),
port: ENV.fetch('TEST_MYSQL_PORT', '3306')
}
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/contrib/redis/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'datadog'

RSpec.describe 'Redis instrumentation test' do
let(:test_host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') }
let(:test_host) { ENV.fetch('TEST_REDIS_HOST', 'localhost') }
let(:test_port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i }

# Redis instance supports 16 databases,
Expand Down Expand Up @@ -37,6 +37,7 @@
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)).to eq('command')

expect(span.get_tag('out.host')).to eq(@host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(@port.to_f)
expect(span.get_tag('redis.raw_command')).to eq(@raw_command)
expect(span.get_tag('db.system')).to eq('redis')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
expect(span.get_tag('out.host')).to_not be_an_ip_address
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
db = ENV.fetch('TEST_MYSQL_DB', 'mysql')
"#{adapter}://#{host}:#{port}/#{db}?user=#{user}&password=#{password}"
end
let(:host) { ENV.fetch('TEST_MYSQL_HOST', '127.0.0.1') }
let(:host) { ENV.fetch('TEST_MYSQL_HOST', 'localhost') }
let(:adapter) do
if PlatformHelpers.jruby?
'mysql'
Expand Down
13 changes: 13 additions & 0 deletions spec/datadog/tracing/contrib/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@

diffable
end

# Check if the provided string is a valid IPv4 or IPv6 address.
RSpec::Matchers.define :be_an_ip_address do
match do |actual|
!!IPAddr.new(actual)
rescue IPAddr::InvalidAddressError
false
end

description do
"be an IPv4 or IPv6 address"
end
end
3 changes: 2 additions & 1 deletion spec/datadog/tracing/contrib/trilogy/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
end

let(:host) { ENV.fetch('TEST_MYSQL_HOST') { '127.0.0.1' } }
let(:host) { ENV.fetch('TEST_MYSQL_HOST') { 'localhost' } }
let(:port) { ENV.fetch('TEST_MYSQL_PORT') { '3306' } }
let(:database) { ENV.fetch('TEST_MYSQL_DB') { 'mysql' } }
let(:username) { ENV.fetch('TEST_MYSQL_USER') { 'root' } }
Expand Down Expand Up @@ -88,6 +88,7 @@
expect(span.get_tag('db.instance')).to eq(database)
expect(span.get_tag('trilogy.db.name')).to eq(database)
expect(span.get_tag('out.host')).to eq(host)
expect(span.get_tag('out.host')).to_not be_an_ip_address
expect(span.get_tag('out.port')).to eq(port.to_f)
expect(span.get_tag('db.system')).to eq('mysql')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('trilogy')
Expand Down

0 comments on commit b4822bb

Please sign in to comment.