lib/opentelemetry/instrumentation/pg/patches/connection.rb in opentelemetry-instrumentation-pg-0.22.0 vs lib/opentelemetry/instrumentation/pg/patches/connection.rb in opentelemetry-instrumentation-pg-0.22.1

- old
+ new

@@ -10,11 +10,11 @@ module OpenTelemetry module Instrumentation module PG module Patches # Module to prepend to PG::Connection for instrumentation - module Connection + module Connection # rubocop:disable Metrics/ModuleLength PG::Constants::EXEC_ISH_METHODS.each do |method| define_method method do |*args| span_name, attrs = span_attrs(:query, *args) tracer.in_span(span_name, attributes: attrs, kind: :client) do super(*args) @@ -125,16 +125,24 @@ def database_name conninfo_hash[:dbname]&.to_s end + def first_in_list(item) + if (idx = item.index(',')) + item[0...idx] + else + item + end + end + def client_attributes attributes = { 'db.system' => 'postgresql', 'db.user' => conninfo_hash[:user]&.to_s, 'db.name' => database_name, - 'net.peer.name' => conninfo_hash[:host]&.to_s + 'net.peer.name' => first_in_list(conninfo_hash[:host]&.to_s) } attributes['peer.service'] = config[:peer_service] if config[:peer_service] attributes.merge(transport_attrs).reject { |_, v| v.nil? } end @@ -144,10 +152,10 @@ { 'net.transport' => 'Unix' } else { 'net.transport' => 'IP.TCP', 'net.peer.ip' => conninfo_hash[:hostaddr]&.to_s, - 'net.peer.port' => conninfo_hash[:port]&.to_s + 'net.peer.port' => first_in_list(conninfo_hash[:port]&.to_s) } end end end end