opentelemetry-instrumentation-pg 0.31.1 → 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: 27552dae38df46b415d38e11216ef734157f2bcb9ad5e19a25cb26d5ce029b02
4
- data.tar.gz: 39e3643f1cfe66f3a6587b1a54f5994cd7b7fc5f3a1dbdc588dd2445da2cf131
3
+ metadata.gz: 55eea698a5680444c893b9ff4bfafcd490f179418b3d84df63eb49737eb89b11
4
+ data.tar.gz: 332bb5e30ee14d66fb880f7645afbee4a5646e1b1e70d16a39d27aba37d5baee
5
5
  SHA512:
6
- metadata.gz: 27cf741489c9998928bfab9f18cf915b19c83c1a776dc0e1c9711835ab4873f5065539920d07645413890881ac3ad757d0eed26e8cd3ade672abebabfe8f064a
7
- data.tar.gz: 3e637c382752c7b515712805c029a7a9cd2461813e198a2dced86f8227931a68ee18711f948e4742e62ebd15556c7dab50d020afc6970b52ae0b61d98801b2a1
6
+ metadata.gz: 8be801a269c94650a3cec4362a551e3f89428956bb20aa988b8196952ff4322ca4eeceb186c62bb8156c616627ecf5a8d954d218fefacfb647643070df7f8aa6
7
+ data.tar.gz: dd5824d49a288621a39cdaaac75aae220e85029cf9a07a5b13bab8f40f9b12021ecfea3477e040f1ace8e3cd070f0218622fc329bb130226bd77c9a29bc15c9f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-instrumentation-pg
2
2
 
3
+ ### v0.33.0 / 2025-11-03
4
+
5
+ * ADDED: Instrument PG connect
6
+
7
+ ### v0.32.0 / 2025-10-22
8
+
9
+ * BREAKING CHANGE: Min Ruby Version 3.2
10
+
11
+ * ADDED: Min Ruby Version 3.2
12
+
3
13
  ### v0.31.1 / 2025-09-30
4
14
 
5
15
  * FIXED: Min OTel Ruby API 1.7
data/README.md CHANGED
@@ -50,9 +50,9 @@ OpenTelemetry::SDK.configure do |c|
50
50
  # will be included on all spans from this instrumentation:
51
51
  peer_service: 'postgres:readonly',
52
52
 
53
- # By default, this instrumentation obfuscate/sanitize the executed SQL as the `db.statement`
53
+ # By default, this instrumentation obfuscates/sanitizes the executed SQL as the `db.statement`
54
54
  # semantic attribute. Optionally, you may disable the inclusion of this attribute entirely by
55
- # setting this option to :omit or disbale sanitization the attribute by setting to :include
55
+ # setting this option to :omit or disable sanitization of the attribute by setting it to :include
56
56
  db_statement: :include,
57
57
  }
58
58
  end
@@ -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.31.1'
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.31.1
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-01 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
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.24'
47
+ version: '0.25'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.24'
54
+ version: '0.25'
55
55
  description: PG (PostgreSQL) instrumentation for the OpenTelemetry framework
56
56
  email:
57
57
  - cncf-opentelemetry-contributors@lists.cncf.io
@@ -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.31.1/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.31.1
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:
@@ -87,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '3.1'
90
+ version: '3.2'
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.3.27
97
+ rubygems_version: 3.4.19
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: PG (PostgreSQL) instrumentation for the OpenTelemetry framework