Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only take the first item in a comma-separated list for pg attrs #142

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
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 @@ -12,7 +12,7 @@ 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)
Expand Down Expand Up @@ -127,12 +127,20 @@ 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]

Expand All @@ -146,7 +154,7 @@ def transport_attrs
{
'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
Expand Down