opentelemetry-instrumentation-pg 0.36.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 147a56092b8f0120d9dcda8cb8af7bdf7dedd85747c33c3af830d1f7b8526ae5
|
|
4
|
+
data.tar.gz: 86ce58798fc0256220f8c4b22a58ed8bc0f863d599e4c68a5aa1cb8dd3e9d19a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05acd8886220b23284e5974e73a49120ec599f14f751dda701be3002fff711dc09917a8dcd4f3de9ebf52690a5d54929fd7837d8ea11f8d7c949c4bf61ae785d
|
|
7
|
+
data.tar.gz: 215acc2fff73d8ceff2e208989b1b86509d2300c7fa8e49f5093822f4e82cb9255ae584bdc89f7c87eda1bb8f29c18771653e60a917a8ad6f49c8fa7c0ec14ef
|
data/CHANGELOG.md
CHANGED
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
|
```
|
|
@@ -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 |
|
|
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(
|
|
103
|
+
block.call(result)
|
|
98
104
|
else
|
|
99
|
-
|
|
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 |
|
|
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(
|
|
146
|
+
block.call(result)
|
|
134
147
|
else
|
|
135
|
-
|
|
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
|
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.
|
|
4
|
+
version: 0.37.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
@@ -74,10 +74,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
|
74
74
|
licenses:
|
|
75
75
|
- Apache-2.0
|
|
76
76
|
metadata:
|
|
77
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.
|
|
78
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-pg/v0.
|
|
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
|
|
79
79
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
|
80
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.
|
|
80
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-pg/0.37.0
|
|
81
81
|
rdoc_options: []
|
|
82
82
|
require_paths:
|
|
83
83
|
- lib
|
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
93
|
version: '0'
|
|
94
94
|
requirements: []
|
|
95
|
-
rubygems_version: 4.0.
|
|
95
|
+
rubygems_version: 4.0.10
|
|
96
96
|
specification_version: 4
|
|
97
97
|
summary: PG (PostgreSQL) instrumentation for the OpenTelemetry framework
|
|
98
98
|
test_files: []
|