opentelemetry-instrumentation-pg 0.22.1 → 0.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 179f178f264fbe7f2c157f4253e7d96194484301ffc2079e8026cdc67d7e98dd
4
- data.tar.gz: 6e24f6c7d3a005e517533e948d19ba060cb6e2ee184ccbf0ec5fbe8e0121b2bd
3
+ metadata.gz: e14d3c31673280352523e2c65a63630dd011198b2a5f80050c78498566028731
4
+ data.tar.gz: 7d6837fb749ecaa4603eaddbf6b7bf1e984d5da8592789e0dc8e8d2812b098d0
5
5
  SHA512:
6
- metadata.gz: 04b33b5e664ba6e8601df65b8c6125f8ae75cf7b5c856363a3cc31d7430290b9f30fea4cdba5298f72c69a18b8fe9d565849df61a4893ce0a33179a894f5fd0b
7
- data.tar.gz: 4f955fd3764ec0f40fdf5223920b9ebd7a429cb409d2d5aba88ca885ba793456614962fa0166928809b58793b789d336d1b449a354099e88b30e9de971b1ace2
6
+ metadata.gz: e0ae9029f10e93984a7e042a1703e5d1516ad8452c3bf3a7e777952309d0a394eacbbf950cee24df15d4bf51ed9b0396c762786fa63a346ed29bf5120d382bc8
7
+ data.tar.gz: fa0c955f672a5bc52743f64116a0c2b4f48edec1679d1924d0135db3079c7d4e38350e7aba7ec35bd8e6b5f68a465cdf162d50c9a946376fe60ca846ed1e754b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
7
+ ### v0.22.2 / 2022-11-10
8
+
9
+ * FIXED: Safeguard against host being nil
10
+
3
11
  ### v0.22.1 / 2022-10-27
4
12
 
5
13
  * FIXED: Only take the first item in a comma-separated list for pg attrs
@@ -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,41 +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
- if (idx = item.index(','))
132
- item[0...idx]
133
- else
134
- item
135
- end
136
- end
137
-
138
126
  def client_attributes
139
127
  attributes = {
140
128
  'db.system' => 'postgresql',
141
- 'db.user' => conninfo_hash[:user]&.to_s,
142
- 'db.name' => database_name,
143
- 'net.peer.name' => first_in_list(conninfo_hash[:host]&.to_s)
129
+ 'db.user' => user,
130
+ 'db.name' => db
144
131
  }
145
132
  attributes['peer.service'] = config[:peer_service] if config[:peer_service]
146
133
 
147
134
  attributes.merge(transport_attrs).reject { |_, v| v.nil? }
148
135
  end
149
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
+
150
149
  def transport_attrs
151
- if conninfo_hash[:host]&.start_with?('/')
152
- { 'net.transport' => 'Unix' }
150
+ h = host
151
+ if h&.start_with?('/')
152
+ {
153
+ 'net.sock.family' => 'unix',
154
+ 'net.peer.name' => h
155
+ }
153
156
  else
154
157
  {
155
- 'net.transport' => 'IP.TCP',
156
- 'net.peer.ip' => conninfo_hash[:hostaddr]&.to_s,
157
- '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
158
162
  }
159
163
  end
160
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
161
176
  end
162
177
  end
163
178
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module PG
10
- VERSION = '0.22.1'
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.1
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-10-27 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.1/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.1
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: