opentelemetry-instrumentation-pg 0.36.0 → 0.37.1

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: 0f996ad740911dadbeb4e827f62b05f2bd2b57a3cc9a695c7e4e9ece7dadc385
4
- data.tar.gz: 3caedd663abde4a0bb8d9636bb46621dccc4a0d4c8db101e60cf51cb7c6c790f
3
+ metadata.gz: ad8e81754b0cdc6821ffa0ac1844b0b681d3968a02dcc66b2f4aaa38dbab4210
4
+ data.tar.gz: af540cd156af164ca33bb267f1b1facb1fac46eba1a5129e1ae3e0b20f3b6138
5
5
  SHA512:
6
- metadata.gz: 5cd52f1d835d96eb26bbfca70ccfb5261f164c8f2d44203f14d780a1df61fe6b196600ad7a0cbfdbfa34b8eea806125f0a1679718d8119cb00e2d6feefcab553
7
- data.tar.gz: 5ce0ad3fe50cd072497ab0cb040eab2c2bd98a03570872cc94fb3c43a53933f889d379b322541fd089a827d0d656b46bcf43293873c81704187684a6fde7cdcf
6
+ metadata.gz: 3fb98ac6e4f1b7eea7b455780fae059e948e289e73ac55e45c58da8cfe58c27595c99c9a4c2f9c26bb23622d31ec49be76261a2766ffaed9741ae675b069eafc
7
+ data.tar.gz: 87eb28915287d385feecdeade147f9d18a64a6b8a3a5419440ce438a73cfc3a363df8a5f506cdfd7d9de20797a0663997afa0ed060831334428e70053b00f3d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Release History: opentelemetry-instrumentation-pg
2
2
 
3
+ ## v0.37.1 / 2026-10-13
4
+
5
+ - FIXED: Encode SQL commenter propagation keys (#2634, #2638)
6
+
7
+ ## v0.37.0 / 2026-08-05
8
+
9
+ - ADDED: Add returned and affected rows attributes (#2410)
10
+
3
11
  ## v0.36.0 / 2026-04-14
4
12
 
5
13
  - BREAKING CHANGE: Min Ruby Version 3.3 (#2125)
data/README.md CHANGED
@@ -58,7 +58,18 @@ OpenTelemetry::SDK.configure do |c|
58
58
  # When `db_statement` is enabled, this instrumentation obfuscates SQL queries. By default, it
59
59
  # obfuscates queries up to 2000 characters. You can override the default with a different
60
60
  # `obfuscation_limit`, but higher values may impact performance.
61
- obfuscation_limit: 2000
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
62
73
  }
63
74
  end
64
75
  ```
@@ -69,9 +80,9 @@ An example of usage can be seen in [`example/pg.rb`](https://github.com/open-tel
69
80
 
70
81
  ## How can I get involved?
71
82
 
72
- The `opentelemetry-instrumentation-pg` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
83
+ The `opentelemetry-instrumentation-pg` gem source is [on github][repo-github], along with related gems.
73
84
 
74
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
85
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby Special Interest Group (SIG). You can find details on our weekly meeting times, GitHub Discussions, and CNCF Slack channels on the [Ruby SDK SIG page][ruby-sig].
75
86
 
76
87
  ## License
77
88
 
@@ -79,9 +90,6 @@ The `opentelemetry-instrumentation-pg` gem is distributed under the Apache 2.0 l
79
90
 
80
91
  [pg-home]: https://github.com/ged/ruby-pg
81
92
  [bundler-home]: https://bundler.io
82
- [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
93
+ [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib
83
94
  [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
84
- [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
85
- [community-meetings]: https://github.com/open-telemetry/community#community-meetings
86
- [slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
87
- [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
95
+ [ruby-sig]: https://github.com/open-telemetry/community/blob/main/sigs.md#ruby-sdk
@@ -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.36.0'
10
+ VERSION = '0.37.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.37.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
@@ -29,14 +29,20 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.5.1
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
40
  - - ">="
38
41
  - !ruby/object:Gem::Version
39
- version: '0'
42
+ version: 0.5.1
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
40
46
  - !ruby/object:Gem::Dependency
41
47
  name: opentelemetry-instrumentation-base
42
48
  requirement: !ruby/object:Gem::Requirement
@@ -74,10 +80,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
74
80
  licenses:
75
81
  - Apache-2.0
76
82
  metadata:
77
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.36.0/file/CHANGELOG.md
78
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-pg/v0.36.0/instrumentation/pg
83
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.37.1/file/CHANGELOG.md
84
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-pg/v0.37.1/instrumentation/pg
79
85
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
80
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.36.0
86
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.37.1
81
87
  rdoc_options: []
82
88
  require_paths:
83
89
  - lib
@@ -92,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
98
  - !ruby/object:Gem::Version
93
99
  version: '0'
94
100
  requirements: []
95
- rubygems_version: 4.0.6
101
+ rubygems_version: 4.0.16
96
102
  specification_version: 4
97
103
  summary: PG (PostgreSQL) instrumentation for the OpenTelemetry framework
98
104
  test_files: []