Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ module Client # rubocop:disable Metrics/ModuleLength

FULL_SQL_REGEXP = Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] })

def initialize(args)
@_otel_net_peer_name = args[:host]
super
end

def query(sql)
tracer.in_span(
database_span_name(sql),
Expand All @@ -68,11 +63,12 @@ def query(sql)
def client_attributes(sql)
attributes = {
::OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM => 'mysql',
::OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => net_peer_name
::OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => connection_options.fetch(:host, 'unknown sock'),
}

attributes[::OpenTelemetry::SemanticConventions::Trace::DB_NAME] = database_name if database_name
attributes[::OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] unless config[:peer_service].nil?
attributes['db.mysql.instance.host.name'] = @connected_host if defined?(@connected_host)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea what this be named and I am struggling here.

What do you think @adrianna-chang-shopify @cschleiden ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc: @open-telemetry/specs-semconv-approvers I could use some of your input/feedback here as well.

Copy link
Contributor

@cschleiden cschleiden May 31, 2023

Choose a reason for hiding this comment

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

I see https://github.com/open-telemetry/opentelemetry-ruby/blob/main/semantic_conventions/lib/opentelemetry/semantic_conventions/trace.rb#L71 for something similar for MSSQL

looking at open-telemetry/opentelemetry-specification#3402, maybe
db.mysql.instance.address or db.mysql.address? But db.mysql.instance.host.name would also work for me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice find!

Copy link
Contributor Author

Choose a reason for hiding this comment

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


case config[:db_statement]
when :obfuscate
Expand Down Expand Up @@ -131,16 +127,6 @@ def database_name
connection_options[:database]
end

def net_peer_name
if defined?(@connected_host)
@connected_host
elsif @_otel_net_peer_name
@_otel_net_peer_name
else
'unknown sock'
end
end

def tracer
Trilogy::Instrumentation.instance.tracer
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,18 @@
client.query('SELECT 1')

_(span.name).must_equal 'select'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_NAME]).must_equal(database)
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT]).must_equal 'SELECT ?'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host)
end

it 'includes database name' do
it 'includes database connection information' do
client.query('SELECT 1')

_(span.name).must_equal 'select'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_NAME]).must_equal(database)
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT]).must_equal 'SELECT ?'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host)
_(span.attributes['db.mysql.instance.host.name']).must_be_nil
end

it 'extracts statement type' do
Expand Down Expand Up @@ -175,6 +173,7 @@
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT]).must_equal 'select @@hostname'
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host)
_(span.attributes['db.mysql.instance.host.name']).must_be_nil

client.query('SELECT 1')

Expand All @@ -184,8 +183,8 @@
_(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_NAME]).must_equal(database)
_(last_span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql'
_(last_span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT]).must_equal 'SELECT ?'
_(last_span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).wont_equal(host)
_(last_span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal client.connected_host
_(last_span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host)
_(last_span.attributes['db.mysql.instance.host.name']).must_equal client.connected_host
end
end

Expand Down