opentelemetry-instrumentation-trilogy 0.51.0 → 0.52.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: e37d376e94b8a014ebe7d25b48aca04b2c85cf883dd423b3d050e3be247e6381
4
- data.tar.gz: 9ca235a06152bcb09ab0c37036b6163ae34175ca200cf4414000dd8b0c54ba8a
3
+ metadata.gz: 98394ad5f8a94bbc13c06521d80b89c761ec59de025cc0af41d855a13491be86
4
+ data.tar.gz: d35aa0062e3deefde1a080ae6b49f9d9d2f4fe243c25ac8058901f04a222f93f
5
5
  SHA512:
6
- metadata.gz: 855ab0dc76858d023424a39f95b7f1b5f499dd0d17cd51d05f298046b19816fe5569e2a013b5f90583117ece100eb95518b707eca51d0a2fc5cf6dffbd12b573
7
- data.tar.gz: bbe75c9e57619fecc0eb8ae3c32fba5f57d5550745a92edc791a5f0cf2326c90073da8ca272c4f26b08e518052a8a6398d45cc0c3c77f1ee55b6dbc9d15ee40e
6
+ metadata.gz: c12b338b919be130784c76b0d26195d96717115b333c2acfac2b2463fb3ba4f2d33a56735e55d48b44e772c15fc3d6e2a684f4aebf03383d1df3e78b4fb3f061
7
+ data.tar.gz: 11a064a8f1215e110cf16920dea54dc068a0d72911f7815db21113e9cf423f677bfb3773cab379cedb49255ad2ec70ce03bdf4ac541cc704556608e9affb3dc6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Release History: opentelemetry-instrumentation-trilogy
2
2
 
3
+ ### v0.52.0 / 2023-03-06
4
+
5
+ * ADDED: Add with_attributes context propagation to Trilogy instrumentation
6
+ * ADDED: Add option to configure span name for trilogy
7
+ * FIXED: Ensure encoding errors handled during SQL obfuscation for Trilogy
8
+
9
+ ### v0.51.1 / 2023-01-14
10
+
11
+ * DOCS: Fix gem homepage
12
+ * DOCS: More gem documentation fixes
13
+
3
14
  ### v0.51.0 / 2022-06-09
4
15
 
5
16
  * Upgrading Base dependency version
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`.
@@ -53,7 +64,7 @@ The `opentelemetry-instrumentation-trilogy` gem is distributed under the Apache
53
64
  [trilogy-home]: https://github.com/github/trilogy
54
65
  [bundler-home]: https://bundler.io
55
66
  [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
56
- [license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/main/LICENSE
67
+ [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
57
68
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
58
69
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
59
70
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -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.0'
10
+ VERSION = '0.52.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.0
4
+ version: 0.52.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: 2022-06-09 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.17'
75
+ version: '2.4'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.17'
82
+ version: '2.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 12.3.3
159
+ version: '13.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 12.3.3
166
+ version: '13.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rspec-mocks
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 0.73.0
187
+ version: 1.41.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: 0.73.0
194
+ version: 1.41.1
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: simplecov
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -271,14 +271,14 @@ files:
271
271
  - lib/opentelemetry/instrumentation/trilogy/instrumentation.rb
272
272
  - lib/opentelemetry/instrumentation/trilogy/patches/client.rb
273
273
  - lib/opentelemetry/instrumentation/trilogy/version.rb
274
- homepage: https://github.com/open-telemetry/opentelemetry-ruby
274
+ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
275
275
  licenses:
276
276
  - Apache-2.0
277
277
  metadata:
278
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-trilogy/v0.51.0/file.CHANGELOG.html
279
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/trilogy
280
- bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
281
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-trilogy/v0.51.0
278
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.52.0/file/CHANGELOG.md
279
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/trilogy
280
+ bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
281
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-trilogy/0.52.0
282
282
  post_install_message:
283
283
  rdoc_options: []
284
284
  require_paths: