opentelemetry-instrumentation-pg 0.35.0 → 0.37.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: 7939f1927799287f8b6aaa52df7b679f48b79e071b890caa729cde97076f4cc7
4
- data.tar.gz: 5ab484d7f918cb112580e1bd380cff06828d7b24df830e5f87c777300fc0e826
3
+ metadata.gz: 147a56092b8f0120d9dcda8cb8af7bdf7dedd85747c33c3af830d1f7b8526ae5
4
+ data.tar.gz: 86ce58798fc0256220f8c4b22a58ed8bc0f863d599e4c68a5aa1cb8dd3e9d19a
5
5
  SHA512:
6
- metadata.gz: 773ad26dd2a8ee92c2abd59453c7ccd3d5ca2cbaf6766ac085a29e4c1c09f446d38a9b7e6a612243ea5c3488b5d8afc87ddc0384a9c27b9410f6afb3d49ec6a2
7
- data.tar.gz: 4a63ed8c931d8f4fd7f73b162d804da1285e211e28fde2631acf975a93344139c6e3694b76870bc22a7eac9c66c74bb41851482b2d6df0360d4c16299b137fc1
6
+ metadata.gz: 05acd8886220b23284e5974e73a49120ec599f14f751dda701be3002fff711dc09917a8dcd4f3de9ebf52690a5d54929fd7837d8ea11f8d7c949c4bf61ae785d
7
+ data.tar.gz: 215acc2fff73d8ceff2e208989b1b86509d2300c7fa8e49f5093822f4e82cb9255ae584bdc89f7c87eda1bb8f29c18771653e60a917a8ad6f49c8fa7c0ec14ef
data/CHANGELOG.md CHANGED
@@ -1,117 +1,125 @@
1
1
  # Release History: opentelemetry-instrumentation-pg
2
2
 
3
- ### v0.35.0 / 2026-01-13
3
+ ## v0.37.0 / 2026-08-05
4
4
 
5
- * ADDED: Add SQL Comment Propagator
5
+ - ADDED: Add returned and affected rows attributes (#2410)
6
6
 
7
- ### v0.34.1 / 2025-12-03
7
+ ## v0.36.0 / 2026-04-14
8
8
 
9
- * FIXED: Update gemspec dependencies to sql-processor
9
+ - BREAKING CHANGE: Min Ruby Version 3.3 (#2125)
10
+ - ADDED: Min Ruby Version 3.3 (#2125)
11
+ - ADDED: Add release tag into source code url of gem metadata (#1984)
10
12
 
11
- ### v0.34.0 / 2025-12-02
13
+ ## v0.35.0 / 2026-01-13
12
14
 
13
- * ADDED: Replace references sql-obfuscation -> sql-processor
15
+ - ADDED: Add SQL Comment Propagator
14
16
 
15
- ### v0.33.0 / 2025-11-03
17
+ ## v0.34.1 / 2025-12-03
16
18
 
17
- * ADDED: Instrument PG connect
19
+ - FIXED: Update gemspec dependencies to sql-processor
18
20
 
19
- ### v0.32.0 / 2025-10-22
21
+ ## v0.34.0 / 2025-12-02
20
22
 
21
- * BREAKING CHANGE: Min Ruby Version 3.2
23
+ - ADDED: Replace references sql-obfuscation -> sql-processor
22
24
 
23
- * ADDED: Min Ruby Version 3.2
25
+ ## v0.33.0 / 2025-11-03
24
26
 
25
- ### v0.31.1 / 2025-09-30
27
+ - ADDED: Instrument PG connect
26
28
 
27
- * FIXED: Min OTel Ruby API 1.7
29
+ ## v0.32.0 / 2025-10-22
28
30
 
29
- ### v0.31.0 / 2025-09-30
31
+ - BREAKING CHANGE: Min Ruby Version 3.2
32
+ - ADDED: Min Ruby Version 3.2
30
33
 
31
- * ADDED: Bump minimum API Version to 1.7
34
+ ## v0.31.1 / 2025-09-30
32
35
 
33
- ### v0.30.1 / 2025-04-16
36
+ - FIXED: Min OTel Ruby API 1.7
34
37
 
35
- * refactor: Use SQL helpers for context attributes #1271
38
+ ## v0.31.0 / 2025-09-30
36
39
 
37
- ### v0.30.0 / 2025-01-16
40
+ - ADDED: Bump minimum API Version to 1.7
38
41
 
39
- * BREAKING CHANGE: Drop Support for EoL Rails 6.1
40
- * BREAKING CHANGE: Set minimum supported version to Ruby 3.1
42
+ ## v0.30.1 / 2025-04-16
41
43
 
42
- * ADDED: Drop Support for EoL Rails 6.1
43
- * ADDED: Set minimum supported version to Ruby 3.1
44
+ - refactor: Use SQL helpers for context attributes #1271
44
45
 
45
- ### v0.29.2 / 2025-01-07
46
+ ## v0.30.0 / 2025-01-16
46
47
 
47
- * FIXED: Update instrumentation pg to support merge statements
48
+ - BREAKING CHANGE: Drop Support for EoL Rails 6.1
49
+ - BREAKING CHANGE: Set minimum supported version to Ruby 3.1
50
+ - ADDED: Drop Support for EoL Rails 6.1
51
+ - ADDED: Set minimum supported version to Ruby 3.1
48
52
 
49
- ### v0.29.1 / 2024-11-26
53
+ ## v0.29.2 / 2025-01-07
50
54
 
51
- * FIXED: Get correct table name if table name is quoted
55
+ - FIXED: Update instrumentation pg to support merge statements
52
56
 
53
- ### v0.29.0 / 2024-09-12
57
+ ## v0.29.1 / 2024-11-26
58
+
59
+ - FIXED: Get correct table name if table name is quoted
60
+
61
+ ## v0.29.0 / 2024-09-12
54
62
 
55
63
  - BREAKING CHANGE: Return message when sql is over the obfuscation limit. Fixes a bug where sql statements with prepended comments that hit the obfuscation limit would be sent raw.
56
64
 
57
- ### v0.28.0 / 2024-08-15
65
+ ## v0.28.0 / 2024-08-15
58
66
 
59
67
  - ADDED: Collect pg db.collection_name attribute
60
68
  - FIXED: Update versions to be tested (includes drop support for pg 1.2)
61
69
 
62
- ### v0.27.4 / 2024-07-23
70
+ ## v0.27.4 / 2024-07-23
63
71
 
64
72
  - DOCS: Add cspell to CI
65
73
 
66
- ### v0.27.3 / 2024-05-11
74
+ ## v0.27.3 / 2024-05-11
67
75
 
68
76
  - ADDED: Support prepend SQL comment for PG instrumentation
69
77
 
70
- ### v0.27.2 / 2024-04-30
78
+ ## v0.27.2 / 2024-04-30
71
79
 
72
80
  - FIXED: Bundler conflict warnings
73
81
 
74
- ### v0.27.1 / 2024-02-08
82
+ ## v0.27.1 / 2024-02-08
75
83
 
76
84
  - FIXED: Add missing requires for sql-helpers to mysql, pg, and trilogy instrumentation
77
85
 
78
- ### v0.27.0 / 2024-02-08
86
+ ## v0.27.0 / 2024-02-08
79
87
 
80
88
  - BREAKING CHANGE: Move shared sql behavior to helper gems
81
89
 
82
- ### v0.26.1 / 2023-11-23
90
+ ## v0.26.1 / 2023-11-23
83
91
 
84
92
  - CHANGED: Applied Rubocop Performance Recommendations [#727](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/727)
85
93
 
86
- ### v0.26.0 / 2023-10-16
94
+ ## v0.26.0 / 2023-10-16
87
95
 
88
96
  - BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement
89
97
 
90
98
  - ADDED: Obfuscation for mysql2, dalli and postgresql as default option for db_statement
91
99
 
92
- ### v0.25.3 / 2023-07-29
100
+ ## v0.25.3 / 2023-07-29
93
101
 
94
102
  - FIXED: Pass block explicitly in `define_method` calls for PG instrumentation query methods
95
103
 
96
- ### v0.25.2 / 2023-06-05
104
+ ## v0.25.2 / 2023-06-05
97
105
 
98
106
  - FIXED: Base config options
99
107
 
100
- ### v0.25.1 / 2023-06-01
108
+ ## v0.25.1 / 2023-06-01
101
109
 
102
110
  - FIXED: Regex non-match with obfuscation limit (issue #486)
103
111
 
104
- ### v0.25.0 / 2023-05-25
112
+ ## v0.25.0 / 2023-05-25
105
113
 
106
114
  - ADDED: Add config[:obfuscation_limit] to pg and mysql2
107
115
 
108
- ### v0.24.0 / 2023-04-17
116
+ ## v0.24.0 / 2023-04-17
109
117
 
110
118
  - BREAKING CHANGE: Drop support for EoL Ruby 2.7
111
119
 
112
120
  - ADDED: Drop support for EoL Ruby 2.7
113
121
 
114
- ### v0.23.0 / 2023-01-14
122
+ ## v0.23.0 / 2023-01-14
115
123
 
116
124
  - BREAKING CHANGE: Removed deprecated instrumentation options
117
125
 
@@ -120,56 +128,56 @@
120
128
  - DOCS: Fix gem homepage
121
129
  - DOCS: More gem documentation fixes
122
130
 
123
- ### v0.22.3 / 2022-12-06
131
+ ## v0.22.3 / 2022-12-06
124
132
 
125
133
  - FIXED: Use attributes from the active PG connection
126
134
 
127
- ### v0.22.2 / 2022-11-10
135
+ ## v0.22.2 / 2022-11-10
128
136
 
129
137
  - FIXED: Safeguard against host being nil
130
138
 
131
- ### v0.22.1 / 2022-10-27
139
+ ## v0.22.1 / 2022-10-27
132
140
 
133
141
  - FIXED: Only take the first item in a comma-separated list for pg attrs
134
142
 
135
- ### v0.22.0 / 2022-10-04
143
+ ## v0.22.0 / 2022-10-04
136
144
 
137
145
  - ADDED: Add `with_attributes` context propagation for PG instrumentation
138
146
 
139
- ### v0.21.0 / 2022-06-09
147
+ ## v0.21.0 / 2022-06-09
140
148
 
141
149
  - Upgrading Base dependency version
142
150
  - FIXED: Broken test file requirements
143
151
 
144
- ### v0.20.0 / 2022-05-02
152
+ ## v0.20.0 / 2022-05-02
145
153
 
146
154
  - ADDED: Validate Using Enums
147
155
  - FIXED: Update pg instrumentation to handle non primitive argument
148
156
  - FIXED: RubyGems Fallback
149
157
 
150
- ### v0.19.2 / 2021-12-02
158
+ ## v0.19.2 / 2021-12-02
151
159
 
152
160
  - (No significant changes)
153
161
 
154
- ### v0.19.1 / 2021-09-29
162
+ ## v0.19.1 / 2021-09-29
155
163
 
156
164
  - (No significant changes)
157
165
 
158
- ### v0.19.0 / 2021-08-12
166
+ ## v0.19.0 / 2021-08-12
159
167
 
160
168
  - ADDED: Add db_statement toggle for postgres
161
169
  - DOCS: Update docs to rely more on environment variable configuration
162
170
 
163
- ### v0.18.1 / 2021-06-23
171
+ ## v0.18.1 / 2021-06-23
164
172
 
165
173
  - (No significant changes)
166
174
 
167
- ### v0.18.0 / 2021-05-21
175
+ ## v0.18.0 / 2021-05-21
168
176
 
169
177
  - ADDED: Updated API dependency for 1.0.0.rc1
170
178
  - ADDED: Add option to postgres instrumentation to disable db.statement
171
179
 
172
- ### v0.17.1 / 2021-04-23
180
+ ## v0.17.1 / 2021-04-23
173
181
 
174
182
  - Initial release.
175
183
  - ADDED: Initial postgresql instrumentation
data/README.md CHANGED
@@ -54,6 +54,22 @@ OpenTelemetry::SDK.configure do |c|
54
54
  # semantic attribute. Optionally, you may disable the inclusion of this attribute entirely by
55
55
  # setting this option to :omit or disable sanitization of the attribute by setting it to :include
56
56
  db_statement: :include,
57
+
58
+ # When `db_statement` is enabled, this instrumentation obfuscates SQL queries. By default, it
59
+ # obfuscates queries up to 2000 characters. You can override the default with a different
60
+ # `obfuscation_limit`, but higher values may impact performance.
61
+ obfuscation_limit: 2000,
62
+
63
+ # By default, this instrumentation does not emit the opt-in
64
+ # `db.response.returned_rows` semantic attribute. Set this option to true
65
+ # to include the number of rows returned by the database operation when
66
+ # available from PG::Result.
67
+ db_response_returned_rows: true,
68
+
69
+ # By default, this instrumentation does not emit the `db.response.affected_rows`
70
+ # attribute. Set this option to true to include the number of rows affected
71
+ # by mutation operations when available from PG::Result.
72
+ db_response_affected_rows: true
57
73
  }
58
74
  end
59
75
  ```
@@ -29,6 +29,8 @@ module OpenTelemetry
29
29
  option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate]
30
30
  option :obfuscation_limit, default: 2000, validate: :integer
31
31
  option :propagator, default: 'none', validate: %w[none tracecontext]
32
+ option :db_response_returned_rows, default: false, validate: :boolean
33
+ option :db_response_affected_rows, default: false, validate: :boolean
32
34
 
33
35
  attr_reader :propagator
34
36
 
@@ -73,13 +73,15 @@ module OpenTelemetry
73
73
 
74
74
  # Module to prepend to PG::Connection for instrumentation
75
75
  module Connection # rubocop:disable Metrics/ModuleLength
76
+ AFFECTED_ROWS_COMMANDS = %w[DELETE INSERT MERGE UPDATE].freeze
77
+
76
78
  # Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
77
79
  TABLE_NAME = /\b(?:FROM|INTO|UPDATE|CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?|DROP\s+TABLE(?:\s+IF\s+EXISTS)?|ALTER\s+TABLE(?:\s+IF\s+EXISTS)?)\s+"?([\w\.]+)"?/i
78
80
 
79
81
  PG::Constants::EXEC_ISH_METHODS.each do |method|
80
82
  define_method method do |*args, &block|
81
83
  span_name, attrs = span_attrs(:query, *args)
82
- tracer.in_span(span_name, attributes: attrs, kind: :client) do |_span, context|
84
+ tracer.in_span(span_name, attributes: attrs, kind: :client) do |span, context|
83
85
  # Inject propagator context into SQL if propagator is configured
84
86
  if propagator && args[0].is_a?(String)
85
87
  sql = args[0]
@@ -93,10 +95,14 @@ module OpenTelemetry
93
95
  end
94
96
  end
95
97
 
98
+ result = super(*args)
99
+ response_attrs = db_response_attributes(result, attrs)
100
+ span.add_attributes(response_attrs) unless response_attrs.empty?
101
+
96
102
  if block
97
- block.call(super(*args))
103
+ block.call(result)
98
104
  else
99
- super(*args)
105
+ result
100
106
  end
101
107
  end
102
108
  end
@@ -105,7 +111,7 @@ module OpenTelemetry
105
111
  PG::Constants::PREPARE_ISH_METHODS.each do |method|
106
112
  define_method method do |*args|
107
113
  span_name, attrs = span_attrs(:prepare, *args)
108
- tracer.in_span(span_name, attributes: attrs, kind: :client) do |_span, context|
114
+ tracer.in_span(span_name, attributes: attrs, kind: :client) do |span, context|
109
115
  # Inject propagator context into SQL if propagator is configured
110
116
  # For prepare, the SQL is in args[1]
111
117
  if propagator && args[1].is_a?(String)
@@ -120,7 +126,10 @@ module OpenTelemetry
120
126
  end
121
127
  end
122
128
 
123
- super(*args)
129
+ result = super(*args)
130
+ response_attrs = db_response_attributes(result, attrs)
131
+ span.add_attributes(response_attrs) unless response_attrs.empty?
132
+ result
124
133
  end
125
134
  end
126
135
  end
@@ -128,11 +137,15 @@ module OpenTelemetry
128
137
  PG::Constants::EXEC_PREPARED_ISH_METHODS.each do |method|
129
138
  define_method method do |*args, &block|
130
139
  span_name, attrs = span_attrs(:execute, *args)
131
- tracer.in_span(span_name, attributes: attrs, kind: :client) do
140
+ tracer.in_span(span_name, attributes: attrs, kind: :client) do |span|
141
+ result = super(*args)
142
+ response_attrs = db_response_attributes(result, attrs)
143
+ span.add_attributes(response_attrs) unless response_attrs.empty?
144
+
132
145
  if block
133
- block.call(super(*args))
146
+ block.call(result)
134
147
  else
135
- super(*args)
148
+ result
136
149
  end
137
150
  end
138
151
  end
@@ -158,6 +171,31 @@ module OpenTelemetry
158
171
  PG::Instrumentation.instance.config
159
172
  end
160
173
 
174
+ def db_response_attributes(result, span_attrs)
175
+ attrs = {}
176
+ attrs['db.response.returned_rows'] = result.ntuples if db_response_returned_rows?(span_attrs)
177
+ attrs['db.response.affected_rows'] = result.cmd_tuples if db_response_affected_rows?(result, span_attrs)
178
+ attrs
179
+ rescue StandardError => e
180
+ OpenTelemetry.handle_error(message: 'Error setting DB response attributes', exception: e)
181
+ {}
182
+ end
183
+
184
+ def db_response_returned_rows?(attrs)
185
+ return false unless config[:db_response_returned_rows]
186
+ return false if attrs.key?('db.response.returned_rows')
187
+
188
+ true
189
+ end
190
+
191
+ def db_response_affected_rows?(result, attrs)
192
+ return false unless config[:db_response_affected_rows]
193
+ return false if attrs.key?('db.response.affected_rows')
194
+ return false unless AFFECTED_ROWS_COMMANDS.include?(result.cmd_status.to_s.split.first)
195
+
196
+ true
197
+ end
198
+
161
199
  def lru_cache
162
200
  # When SQL is being sanitized, we know that this cache will
163
201
  # never be more than 50 entries * 2000 characters (so, presumably
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module PG
10
- VERSION = '0.35.0'
10
+ VERSION = '0.37.0'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-01-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: opentelemetry-helpers-sql
@@ -75,11 +74,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
75
74
  licenses:
76
75
  - Apache-2.0
77
76
  metadata:
78
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.35.0/file/CHANGELOG.md
79
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/pg
77
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.37.0/file/CHANGELOG.md
78
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-pg/v0.37.0/instrumentation/pg
80
79
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
81
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.35.0
82
- post_install_message:
80
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.37.0
83
81
  rdoc_options: []
84
82
  require_paths:
85
83
  - lib
@@ -87,15 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
85
  requirements:
88
86
  - - ">="
89
87
  - !ruby/object:Gem::Version
90
- version: '3.2'
88
+ version: '3.3'
91
89
  required_rubygems_version: !ruby/object:Gem::Requirement
92
90
  requirements:
93
91
  - - ">="
94
92
  - !ruby/object:Gem::Version
95
93
  version: '0'
96
94
  requirements: []
97
- rubygems_version: 3.4.19
98
- signing_key:
95
+ rubygems_version: 4.0.10
99
96
  specification_version: 4
100
97
  summary: PG (PostgreSQL) instrumentation for the OpenTelemetry framework
101
98
  test_files: []