opentelemetry-instrumentation-trilogy 0.51.1 → 0.53.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6241d5ba63c7c5865f7cf548d39aa770f596aeb2c4ee2afecb7cdfa9c49c717
4
- data.tar.gz: 1bfd9359a9a17b6e964a5bb820ca97edecfe68c9881bd7ff22ebadb2c969ae9e
3
+ metadata.gz: e1714d43b908e2ef4f6af27fd1d92376e509ceed407df30ca7380028bba61b45
4
+ data.tar.gz: 1ee3f0f262b413e6b6a149cd2f99f01e2fdfd5c2f39b7a4897779b3366b1b3f4
5
5
  SHA512:
6
- metadata.gz: 620b27ac8992366fc522a232c679cc1065b31e2dd3919f922b1e55552f71e23390745242a18f31d25d84876211d216759e2275ff272f25ba8dbe660259287183
7
- data.tar.gz: b651e768889aa07c3871516fb12eae564457c5c896f49ed861218a09ed405fab8707b67e61b906ab249d2cdd5a4ab2d420565a6ae453fe9c1f6544300b915831
6
+ metadata.gz: 4730f45bf6c73dbd32f370229ab46d452a12f2ac8459e79bf15b83f8d99aeee4bae9243723e60522f2821c68f5a1d76363ba736923abd42832706534417d32f7
7
+ data.tar.gz: d0d8f471da5f50d9f4139c6fe31973d255a2f399add2d55e84ebe514ad3f688144491e3b58711e1a3c880142511c92c5648d83bd7ab95028b0c1accb2c767704
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History: opentelemetry-instrumentation-trilogy
2
2
 
3
+ ### v0.53.0 / 2023-04-17
4
+
5
+ * BREAKING CHANGE: Drop support for EoL Ruby 2.7
6
+
7
+ * ADDED: Drop support for EoL Ruby 2.7
8
+
9
+ ### v0.52.0 / 2023-03-06
10
+
11
+ * ADDED: Add with_attributes context propagation to Trilogy instrumentation
12
+ * ADDED: Add option to configure span name for trilogy
13
+ * FIXED: Ensure encoding errors handled during SQL obfuscation for Trilogy
14
+
3
15
  ### v0.51.1 / 2023-01-14
4
16
 
5
17
  * DOCS: Fix gem homepage
data/README.md CHANGED
@@ -40,6 +40,17 @@ OpenTelemetry::SDK.configure do |c|
40
40
  end
41
41
  ```
42
42
 
43
+ The `trilogy` instrumentation allows the user to supply additional attributes via the `with_attributes` method. This makes it possible to supply additional attributes on trilogy spans. Attributes supplied in `with_attributes` supersede those automatically generated within `trilogy`'s automatic instrumentation. If you supply a `db.statement` attribute in `with_attributes`, this library's `:db_statement` configuration will not be applied.
44
+
45
+ ```ruby
46
+ require 'opentelemetry-instrumentation-trilogy'
47
+
48
+ client = Trilogy.new(:host => 'localhost', :username => 'root')
49
+ OpenTelemetry::Instrumentation::Trilogy.with_attributes('pizzatoppings' => 'mushrooms') do
50
+ client.query('SELECT 1')
51
+ end
52
+ ```
53
+
43
54
  ## How can I get involved?
44
55
 
45
56
  The `opentelemetry-instrumentation-trilogy` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
@@ -24,6 +24,7 @@ module OpenTelemetry
24
24
 
25
25
  option :peer_service, default: nil, validate: :string
26
26
  option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate]
27
+ option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name]
27
28
 
28
29
  private
29
30
 
@@ -56,7 +56,7 @@ module OpenTelemetry
56
56
  def query(sql)
57
57
  tracer.in_span(
58
58
  database_span_name(sql),
59
- attributes: client_attributes(sql),
59
+ attributes: client_attributes(sql).merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
60
60
  kind: :client
61
61
  ) do
62
62
  super(sql)
@@ -87,10 +87,14 @@ module OpenTelemetry
87
87
  if sql.size > 2000
88
88
  'SQL query too large to remove sensitive data ...'
89
89
  else
90
- obfuscated = sql.gsub(FULL_SQL_REGEXP, '?')
90
+ obfuscated = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
91
+ obfuscated = obfuscated.gsub(FULL_SQL_REGEXP, '?')
91
92
  obfuscated = 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if detect_unmatched_pairs(obfuscated)
92
93
  obfuscated
93
94
  end
95
+ rescue StandardError => e
96
+ OpenTelemetry.handle_error(message: 'Failed to obfuscate SQL', exception: e)
97
+ 'OpenTelemetry error: failed to obfuscate sql'
94
98
  end
95
99
 
96
100
  def detect_unmatched_pairs(obfuscated)
@@ -102,20 +106,27 @@ module OpenTelemetry
102
106
  %r{'|"|\/\*|\*\/}.match(obfuscated)
103
107
  end
104
108
 
105
- def database_span_name(sql)
106
- # Setting span name to the SQL query without obfuscation would
107
- # result in PII + cardinality issues.
108
- # First attempt to infer the statement type then fallback to
109
- # current Otel approach {database.component_name}.{database_instance_name}
110
- # https://github.com/open-telemetry/opentelemetry-python/blob/39fa078312e6f41c403aa8cad1868264011f7546/ext/opentelemetry-ext-dbapi/tests/test_dbapi_integration.py#L53
111
- # This creates span names like mysql.default, mysql.replica, postgresql.staging etc.
112
-
113
- statement_type = extract_statement_type(sql)
114
-
115
- return statement_type unless statement_type.nil?
109
+ def database_span_name(sql) # rubocop:disable Metrics/CyclomaticComplexity
110
+ case config[:span_name]
111
+ when :statement_type
112
+ extract_statement_type(sql)
113
+ when :db_name
114
+ database_name
115
+ when :db_operation_and_name
116
+ op = OpenTelemetry::Instrumentation::Trilogy.attributes['db.operation']
117
+ name = database_name
118
+ if op && name
119
+ "#{op} #{name}"
120
+ elsif op
121
+ op
122
+ elsif name
123
+ name
124
+ end
125
+ end || 'mysql'
126
+ end
116
127
 
117
- # fallback
118
- 'mysql'
128
+ def database_name
129
+ connection_options[:database]
119
130
  end
120
131
 
121
132
  def net_peer_name
@@ -140,6 +151,7 @@ module OpenTelemetry
140
151
  QUERY_NAME_RE.match(sql) { |match| match[1].downcase } unless sql.nil?
141
152
  rescue StandardError => e
142
153
  OpenTelemetry.logger.error("Error extracting sql statement type: #{e.message}")
154
+ nil
143
155
  end
144
156
  end
145
157
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module Trilogy
10
- VERSION = '0.51.1'
10
+ VERSION = '0.53.0'
11
11
  end
12
12
  end
13
13
  end
@@ -11,6 +11,45 @@ module OpenTelemetry
11
11
  module Instrumentation
12
12
  # Contains the OpenTelemetry instrumentation for the Trilogy gem
13
13
  module Trilogy
14
+ extend self
15
+
16
+ CURRENT_ATTRIBUTES_KEY = Context.create_key('trilogy-attributes-hash')
17
+
18
+ private_constant :CURRENT_ATTRIBUTES_KEY
19
+
20
+ # Returns the attributes hash representing the Trilogy context found
21
+ # in the optional context or the current context if none is provided.
22
+ #
23
+ # @param [optional Context] context The context to lookup the current
24
+ # attributes hash. Defaults to Context.current
25
+ def attributes(context = nil)
26
+ context ||= Context.current
27
+ context.value(CURRENT_ATTRIBUTES_KEY) || {}
28
+ end
29
+
30
+ # Returns a context containing the merged attributes hash, derived from the
31
+ # optional parent context, or the current context if one was not provided.
32
+ #
33
+ # @param [optional Context] context The context to use as the parent for
34
+ # the returned context
35
+ def context_with_attributes(attributes_hash, parent_context: Context.current)
36
+ attributes_hash = attributes(parent_context).merge(attributes_hash)
37
+ parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
38
+ end
39
+
40
+ # Activates/deactivates the merged attributes hash within the current Context,
41
+ # which makes the "current attributes hash" available implicitly.
42
+ #
43
+ # On exit, the attributes hash that was active before calling this method
44
+ # will be reactivated.
45
+ #
46
+ # @param [Span] span the span to activate
47
+ # @yield [Hash, Context] yields attributes hash and a context containing the
48
+ # attributes hash to the block.
49
+ def with_attributes(attributes_hash)
50
+ attributes_hash = attributes.merge(attributes_hash)
51
+ Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
52
+ end
14
53
  end
15
54
  end
16
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-trilogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.1
4
+ version: 0.53.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: 2023-01-14 00:00:00.000000000 Z
11
+ date: 2023-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.21.0
33
+ version: 0.22.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.21.0
40
+ version: 0.22.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opentelemetry-semantic_conventions
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: opentelemetry-test-helpers
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '0.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '0.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 1.41.1
187
+ version: 1.48.1
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 1.41.1
194
+ version: 1.48.1
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: simplecov
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -275,10 +275,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
275
275
  licenses:
276
276
  - Apache-2.0
277
277
  metadata:
278
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.51.1/file/CHANGELOG.md
278
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.53.0/file/CHANGELOG.md
279
279
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/trilogy
280
280
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
281
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.51.1
281
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.53.0
282
282
  post_install_message:
283
283
  rdoc_options: []
284
284
  require_paths:
@@ -287,14 +287,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
287
287
  requirements:
288
288
  - - ">="
289
289
  - !ruby/object:Gem::Version
290
- version: 2.6.0
290
+ version: '3.0'
291
291
  required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  requirements:
293
293
  - - ">="
294
294
  - !ruby/object:Gem::Version
295
295
  version: '0'
296
296
  requirements: []
297
- rubygems_version: 3.1.6
297
+ rubygems_version: 3.2.33
298
298
  signing_key:
299
299
  specification_version: 4
300
300
  summary: Trilogy instrumentation for the OpenTelemetry framework