opentelemetry-instrumentation-pg 0.22.2 → 0.22.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1ea9903693d7c6575e9c0c74560429c2400e1c80418553812127c5b9ce2637a
4
- data.tar.gz: adbcffe621a4d67b722505e86e134b65510314d414767fe28a1f549e9551ca00
3
+ metadata.gz: e14d3c31673280352523e2c65a63630dd011198b2a5f80050c78498566028731
4
+ data.tar.gz: 7d6837fb749ecaa4603eaddbf6b7bf1e984d5da8592789e0dc8e8d2812b098d0
5
5
  SHA512:
6
- metadata.gz: f26f3a7458c5a8d80348b093e6d826eaf6f953b7e81ff47a611c5eaa53c677ac278130312fb902a3d1d5e11e93f107c99952bc960ea9d60067a101f666e54076
7
- data.tar.gz: ab345251e00ffe0ef82311f42aa73c14230fb9d9f861275ef7a15712413019b149b5d0644333a553a0656ac83ae2f893dea4f15074f1674b78bdf91b289f3e51
6
+ metadata.gz: e0ae9029f10e93984a7e042a1703e5d1516ad8452c3bf3a7e777952309d0a394eacbbf950cee24df15d4bf51ed9b0396c762786fa63a346ed29bf5120d382bc8
7
+ data.tar.gz: fa0c955f672a5bc52743f64116a0c2b4f48edec1679d1924d0135db3079c7d4e38350e7aba7ec35bd8e6b5f68a465cdf162d50c9a946376fe60ca846ed1e754b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-pg
2
2
 
3
+ ### v0.22.3 / 2022-12-06
4
+
5
+ * FIXED: Use attributes from the active PG connection
6
+
3
7
  ### v0.22.2 / 2022-11-10
4
8
 
5
9
  * FIXED: Safeguard against host being nil
@@ -97,7 +97,7 @@ module OpenTelemetry
97
97
  end
98
98
 
99
99
  def span_name(operation)
100
- [validated_operation(operation), database_name].compact.join(' ')
100
+ [validated_operation(operation), db].compact.join(' ')
101
101
  end
102
102
 
103
103
  def validated_operation(operation)
@@ -123,43 +123,56 @@ module OpenTelemetry
123
123
  @generated_postgres_regex ||= Regexp.union(PG::Constants::POSTGRES_COMPONENTS.map { |component| PG::Constants::COMPONENTS_REGEX_MAP[component] })
124
124
  end
125
125
 
126
- def database_name
127
- conninfo_hash[:dbname]&.to_s
128
- end
129
-
130
- def first_in_list(item)
131
- return unless item
132
-
133
- if (idx = item.index(','))
134
- item[0...idx]
135
- else
136
- item
137
- end
138
- end
139
-
140
126
  def client_attributes
141
127
  attributes = {
142
128
  'db.system' => 'postgresql',
143
- 'db.user' => conninfo_hash[:user]&.to_s,
144
- 'db.name' => database_name,
145
- 'net.peer.name' => first_in_list(conninfo_hash[:host]&.to_s)
129
+ 'db.user' => user,
130
+ 'db.name' => db
146
131
  }
147
132
  attributes['peer.service'] = config[:peer_service] if config[:peer_service]
148
133
 
149
134
  attributes.merge(transport_attrs).reject { |_, v| v.nil? }
150
135
  end
151
136
 
137
+ def transport_addr
138
+ # The hostaddr method is available when the gem is built against
139
+ # a recent version of libpq.
140
+ return hostaddr if defined?(hostaddr)
141
+
142
+ # As a fallback, we can use the hostaddr of the parsed connection
143
+ # string when there is only one. Some older versions of libpq allow
144
+ # multiple without any way to discern which is presently connected.
145
+ addr = conninfo_hash[:hostaddr]
146
+ return addr unless addr&.include?(',')
147
+ end
148
+
152
149
  def transport_attrs
153
- if conninfo_hash[:host]&.start_with?('/')
154
- { 'net.transport' => 'Unix' }
150
+ h = host
151
+ if h&.start_with?('/')
152
+ {
153
+ 'net.sock.family' => 'unix',
154
+ 'net.peer.name' => h
155
+ }
155
156
  else
156
157
  {
157
- 'net.transport' => 'IP.TCP',
158
- 'net.peer.ip' => conninfo_hash[:hostaddr]&.to_s,
159
- 'net.peer.port' => first_in_list(conninfo_hash[:port]&.to_s)
158
+ 'net.transport' => 'ip_tcp',
159
+ 'net.peer.name' => h,
160
+ 'net.peer.ip' => transport_addr,
161
+ 'net.peer.port' => transport_port
160
162
  }
161
163
  end
162
164
  end
165
+
166
+ def transport_port
167
+ # The port method can fail in older versions of the gem. It is
168
+ # accurate and safe to use when the DEF_PGPORT constant is defined.
169
+ return port if defined?(::PG::DEF_PGPORT)
170
+
171
+ # As a fallback, we can use the port of the parsed connection
172
+ # string when there is exactly one.
173
+ p = conninfo_hash[:port]
174
+ return p.to_i unless p.nil? || p.empty? || p.include?(',')
175
+ end
163
176
  end
164
177
  end
165
178
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module PG
10
- VERSION = '0.22.2'
10
+ VERSION = '0.22.3'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.2
4
+ version: 0.22.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-10 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -243,10 +243,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-contrib
243
243
  licenses:
244
244
  - Apache-2.0
245
245
  metadata:
246
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-pg/v0.22.2/file.CHANGELOG.html
246
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-pg/v0.22.3/file.CHANGELOG.html
247
247
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/pg
248
248
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
249
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-pg/v0.22.2
249
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-pg/v0.22.3
250
250
  post_install_message:
251
251
  rdoc_options: []
252
252
  require_paths: