lib/opentelemetry/instrumentation/trilogy/patches/client.rb in opentelemetry-instrumentation-trilogy-0.55.1 vs lib/opentelemetry/instrumentation/trilogy/patches/client.rb in opentelemetry-instrumentation-trilogy-0.56.0
- old
+ new
@@ -46,15 +46,10 @@
multi_line_comments
].freeze
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),
attributes: client_attributes(sql).merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
kind: :client
@@ -66,15 +61,16 @@
private
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.address'] = @connected_host if defined?(@connected_host)
case config[:db_statement]
when :obfuscate
attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql)
when :include
@@ -131,19 +127,9 @@
end || 'mysql'
end
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