Skip to content

Commit

Permalink
Trilogy: instrument connect and ping
Browse files Browse the repository at this point in the history
These can be just as slow as a query if not slower.
  • Loading branch information
byroot committed Oct 20, 2023
1 parent 27448c4 commit 8e3f01c
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ module Client # rubocop:disable Metrics/ModuleLength

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

def initialize(...)
tracer.in_span(
"connect",
attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
kind: :client
) do
super
end
end

def ping(...)
tracer.in_span(
"ping",
attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
kind: :client
) do
super
end
end

def query(sql)
tracer.in_span(
database_span_name(sql),
Expand All @@ -60,7 +80,7 @@ def query(sql)

private

def client_attributes(sql)
def client_attributes(sql = nil)
attributes = {
::OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM => 'mysql',
::OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => connection_options.fetch(:host, 'unknown sock')
Expand All @@ -71,11 +91,13 @@ def client_attributes(sql)
attributes[::OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] unless config[:peer_service].nil?
attributes['db.mysql.instance.address'] = @connected_host if defined?(@connected_host)

case config[:db_statement]
when :obfuscate
attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql)
when :include
attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = sql
if sql
case config[:db_statement]
when :obfuscate
attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql)
when :include
attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = sql
end
end

attributes
Expand Down

0 comments on commit 8e3f01c

Please sign in to comment.