opentelemetry-instrumentation-pg 0.32.0 → 0.33.0

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: 930cc6e7ad994e3fc50fbc8d8c87a07e2b6aeb25441baaa518981731cf764e9b
4
- data.tar.gz: e6041ea104689b0baca3c38199e61f5a2e9349c41804466ca123a7621d79692e
3
+ metadata.gz: 55eea698a5680444c893b9ff4bfafcd490f179418b3d84df63eb49737eb89b11
4
+ data.tar.gz: 332bb5e30ee14d66fb880f7645afbee4a5646e1b1e70d16a39d27aba37d5baee
5
5
  SHA512:
6
- metadata.gz: e5feac67db70c5b45236420eb3729b1a7f344661583dedf45885ca09a1c926481dbb312df5825b207179c851547bd931809c91624753efbcdd55c9189e4b5872
7
- data.tar.gz: 48bce539675d9c8f226dab0f040c4bafa32800ffe47c72ca528f9f93d7eb1a0fa644ff074188f7d48e16a22d42e6242e41158be7bacf75ace655543a11a750e9
6
+ metadata.gz: 8be801a269c94650a3cec4362a551e3f89428956bb20aa988b8196952ff4322ca4eeceb186c62bb8156c616627ecf5a8d954d218fefacfb647643070df7f8aa6
7
+ data.tar.gz: dd5824d49a288621a39cdaaac75aae220e85029cf9a07a5b13bab8f40f9b12021ecfea3477e040f1ace8e3cd070f0218622fc329bb130226bd77c9a29bc15c9f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-pg
2
2
 
3
+ ### v0.33.0 / 2025-11-03
4
+
5
+ * ADDED: Instrument PG connect
6
+
3
7
  ### v0.32.0 / 2025-10-22
4
8
 
5
9
  * BREAKING CHANGE: Min Ruby Version 3.2
@@ -94,6 +94,12 @@ module OpenTelemetry
94
94
  async_exec_prepared
95
95
  sync_exec_prepared
96
96
  ].freeze
97
+
98
+ CONNECTION_METHODS = %i[
99
+ connect
100
+ open
101
+ async_connect
102
+ ].freeze
97
103
  end
98
104
  end
99
105
  end
@@ -40,6 +40,7 @@ module OpenTelemetry
40
40
 
41
41
  def patch_client
42
42
  ::PG::Connection.prepend(Patches::Connection)
43
+ ::PG::Connection.singleton_class.prepend(Patches::Connect)
43
44
  end
44
45
  end
45
46
  end
@@ -12,6 +12,65 @@ module OpenTelemetry
12
12
  module Instrumentation
13
13
  module PG
14
14
  module Patches
15
+ # Utility methods for setting connection attributes from Connect module
16
+ module ConnectionHelper
17
+ module_function
18
+
19
+ def set_connection_attributes(span, conn, config)
20
+ attributes = {
21
+ 'db.system' => 'postgresql',
22
+ 'db.name' => conn.db,
23
+ 'db.user' => conn.user
24
+ }
25
+ attributes['peer.service'] = config[:peer_service] if config[:peer_service]
26
+
27
+ h = conn.host
28
+ if h&.start_with?('/')
29
+ attributes['net.sock.family'] = 'unix'
30
+ attributes['net.peer.name'] = h
31
+ else
32
+ attributes['net.transport'] = 'ip_tcp'
33
+ attributes['net.peer.name'] = h
34
+ attributes['net.peer.port'] = conn.port if defined?(::PG::DEF_PGPORT)
35
+ end
36
+
37
+ attributes.merge!(OpenTelemetry::Instrumentation::PG.attributes)
38
+ attributes.compact!
39
+
40
+ span.add_attributes(attributes)
41
+ end
42
+ end
43
+
44
+ # Module to prepend to PG::Connection singleton class for connection initialization
45
+ # We override `new` instead of `initialize` because PG::Connection.new is implemented
46
+ # as a Ruby method that calls the C-level connect_start, bypassing initialize.
47
+ # We also need to override the aliases (open, connect, async_connect) because they
48
+ # were aliased before our prepend, so they point to the original method.
49
+ # See: https://github.com/ged/ruby-pg/blob/master/lib/pg/connection.rb#L870
50
+ module Connect
51
+ def new(...)
52
+ tracer = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.tracer
53
+ config = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.config
54
+
55
+ tracer.in_span('connect', kind: :client) do |span|
56
+ if block_given?
57
+ super do |conn|
58
+ ConnectionHelper.set_connection_attributes(span, conn, config)
59
+ yield conn
60
+ end
61
+ else
62
+ conn = super
63
+ ConnectionHelper.set_connection_attributes(span, conn, config)
64
+ conn
65
+ end
66
+ end
67
+ end
68
+
69
+ PG::Constants::CONNECTION_METHODS.each do |method|
70
+ alias_method method, :new
71
+ end
72
+ end
73
+
15
74
  # Module to prepend to PG::Connection for instrumentation
16
75
  module Connection # rubocop:disable Metrics/ModuleLength
17
76
  # Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module PG
10
- VERSION = '0.32.0'
10
+ VERSION = '0.33.0'
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.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-22 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-helpers-sql
@@ -75,10 +75,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
75
75
  licenses:
76
76
  - Apache-2.0
77
77
  metadata:
78
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.32.0/file/CHANGELOG.md
78
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.33.0/file/CHANGELOG.md
79
79
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/pg
80
80
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
81
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.32.0
81
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.33.0
82
82
  post_install_message:
83
83
  rdoc_options: []
84
84
  require_paths: