Skip to content

Commit

Permalink
server.address
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jul 24, 2024
1 parent 2f591a1 commit 23689e8
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 8 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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,8 @@ 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'
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
7 changes: 7 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,14 @@
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 satisfy('not be an IP') do |host|
IPAddr.new host
false
rescue InvalidAddressError
true
end 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
5 changes: 5 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
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
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

0 comments on commit 23689e8

Please sign in to comment.