opentelemetry-instrumentation-mysql2 0.25.0 → 0.26.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: 8dd5337ce5e46679d577e51b807122cb037299d844ab8405d46c2043d2484931
|
4
|
+
data.tar.gz: c5df05b92be367a4c4397cfcb9eb76c5b5ca0f4fd0b6ee21d61a7bfafa1f1611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f183aee9dd0938d0c59928cafa9dd146fafaddb10a246b8486e333139abef478decd4fa1cea0c493012ab300c508302446102b15653092ead1e91d6a739e275
|
7
|
+
data.tar.gz: 4fc278b6756d5f744bf532999da01d95328eca700594e572039c2e51d81df668fc7674b040dbc2d8f350232a3fc267566974d40f393aef35428f1e308dc364be
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-mysql2
|
2
2
|
|
3
|
+
### v0.26.0 / 2024-02-08
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Move shared sql behavior to helper gems
|
6
|
+
|
7
|
+
|
3
8
|
### v0.25.0 / 2023-10-16
|
4
9
|
|
5
10
|
* BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement
|
@@ -9,58 +9,27 @@ module OpenTelemetry
|
|
9
9
|
module Mysql2
|
10
10
|
module Patches
|
11
11
|
# Module to prepend to Mysql2::Client for instrumentation
|
12
|
-
module Client
|
13
|
-
QUERY_NAMES = [
|
14
|
-
'set names',
|
15
|
-
'select',
|
16
|
-
'insert',
|
17
|
-
'update',
|
18
|
-
'delete',
|
19
|
-
'begin',
|
20
|
-
'commit',
|
21
|
-
'rollback',
|
22
|
-
'savepoint',
|
23
|
-
'release savepoint',
|
24
|
-
'explain',
|
25
|
-
'drop database',
|
26
|
-
'drop table',
|
27
|
-
'create database',
|
28
|
-
'create table'
|
29
|
-
].freeze
|
30
|
-
|
31
|
-
QUERY_NAME_RE = Regexp.new("^(#{QUERY_NAMES.join('|')})", Regexp::IGNORECASE)
|
32
|
-
|
33
|
-
# From: https://github.com/newrelic/newrelic-ruby-agent/blob/0235b288d85b8bc795bdc1a24621dd9f84cfef45/lib/new_relic/agent/database/obfuscation_helpers.rb#L9-L34
|
34
|
-
COMPONENTS_REGEX_MAP = {
|
35
|
-
single_quotes: /'(?:[^']|'')*?(?:\\'.*|'(?!'))/,
|
36
|
-
double_quotes: /"(?:[^"]|"")*?(?:\\".*|"(?!"))/,
|
37
|
-
numeric_literals: /-?\b(?:[0-9]+\.)?[0-9]+([eE][+-]?[0-9]+)?\b/,
|
38
|
-
boolean_literals: /\b(?:true|false|null)\b/i,
|
39
|
-
hexadecimal_literals: /0x[0-9a-fA-F]+/,
|
40
|
-
comments: /(?:#|--).*?(?=\r|\n|$)/i,
|
41
|
-
multi_line_comments: %r{\/\*(?:[^\/]|\/[^*])*?(?:\*\/|\/\*.*)}
|
42
|
-
}.freeze
|
43
|
-
|
44
|
-
MYSQL_COMPONENTS = %i[
|
45
|
-
single_quotes
|
46
|
-
double_quotes
|
47
|
-
numeric_literals
|
48
|
-
boolean_literals
|
49
|
-
hexadecimal_literals
|
50
|
-
comments
|
51
|
-
multi_line_comments
|
52
|
-
].freeze
|
53
|
-
|
12
|
+
module Client
|
54
13
|
def query(sql, options = {})
|
55
14
|
attributes = client_attributes
|
56
15
|
case config[:db_statement]
|
57
16
|
when :include
|
58
17
|
attributes[SemanticConventions::Trace::DB_STATEMENT] = sql
|
59
18
|
when :obfuscate
|
60
|
-
attributes[SemanticConventions::Trace::DB_STATEMENT] =
|
19
|
+
attributes[SemanticConventions::Trace::DB_STATEMENT] =
|
20
|
+
OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(
|
21
|
+
sql, obfuscation_limit: config[:obfuscation_limit], adapter: :mysql
|
22
|
+
)
|
61
23
|
end
|
62
24
|
tracer.in_span(
|
63
|
-
database_span_name(
|
25
|
+
OpenTelemetry::Helpers::MySQL.database_span_name(
|
26
|
+
sql,
|
27
|
+
OpenTelemetry::Instrumentation::Mysql2.attributes[
|
28
|
+
SemanticConventions::Trace::DB_OPERATION
|
29
|
+
],
|
30
|
+
database_name,
|
31
|
+
config
|
32
|
+
),
|
64
33
|
attributes: attributes.merge!(OpenTelemetry::Instrumentation::Mysql2.attributes),
|
65
34
|
kind: :client
|
66
35
|
) do
|
@@ -70,57 +39,6 @@ module OpenTelemetry
|
|
70
39
|
|
71
40
|
private
|
72
41
|
|
73
|
-
def obfuscate_sql(sql)
|
74
|
-
if sql.size > config[:obfuscation_limit]
|
75
|
-
first_match_index = sql.index(generated_mysql_regex)
|
76
|
-
truncation_message = "SQL truncated (> #{config[:obfuscation_limit]} characters)"
|
77
|
-
return truncation_message unless first_match_index
|
78
|
-
|
79
|
-
truncated_sql = sql[..first_match_index - 1]
|
80
|
-
"#{truncated_sql}...\n#{truncation_message}"
|
81
|
-
else
|
82
|
-
obfuscated = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
|
83
|
-
obfuscated = obfuscated.gsub(generated_mysql_regex, '?')
|
84
|
-
obfuscated = 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if detect_unmatched_pairs(obfuscated)
|
85
|
-
obfuscated
|
86
|
-
end
|
87
|
-
rescue StandardError => e
|
88
|
-
OpenTelemetry.handle_error(message: 'Failed to obfuscate SQL', exception: e)
|
89
|
-
'OpenTelemetry error: failed to obfuscate sql'
|
90
|
-
end
|
91
|
-
|
92
|
-
def generated_mysql_regex
|
93
|
-
@generated_mysql_regex ||= Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] })
|
94
|
-
end
|
95
|
-
|
96
|
-
def detect_unmatched_pairs(obfuscated)
|
97
|
-
# We use this to check whether the query contains any quote characters
|
98
|
-
# after obfuscation. If so, that's a good indication that the original
|
99
|
-
# query was malformed, and so our obfuscation can't reliably find
|
100
|
-
# literals. In such a case, we'll replace the entire query with a
|
101
|
-
# placeholder.
|
102
|
-
%r{'|"|\/\*|\*\/}.match(obfuscated)
|
103
|
-
end
|
104
|
-
|
105
|
-
def database_span_name(sql)
|
106
|
-
case config[:span_name]
|
107
|
-
when :statement_type
|
108
|
-
extract_statement_type(sql)
|
109
|
-
when :db_name
|
110
|
-
database_name
|
111
|
-
when :db_operation_and_name
|
112
|
-
op = OpenTelemetry::Instrumentation::Mysql2.attributes[SemanticConventions::Trace::DB_OPERATION]
|
113
|
-
name = database_name
|
114
|
-
if op && name
|
115
|
-
"#{op} #{name}"
|
116
|
-
elsif op
|
117
|
-
op
|
118
|
-
elsif name
|
119
|
-
name
|
120
|
-
end
|
121
|
-
end || 'mysql'
|
122
|
-
end
|
123
|
-
|
124
42
|
def database_name
|
125
43
|
# https://github.com/brianmario/mysql2/blob/ca08712c6c8ea672df658bb25b931fea22555f27/lib/mysql2/client.rb#L78
|
126
44
|
(query_options[:database] || query_options[:dbname] || query_options[:db])&.to_s
|
@@ -150,13 +68,6 @@ module OpenTelemetry
|
|
150
68
|
def config
|
151
69
|
Mysql2::Instrumentation.instance.config
|
152
70
|
end
|
153
|
-
|
154
|
-
def extract_statement_type(sql)
|
155
|
-
QUERY_NAME_RE.match(sql) { |match| match[1].downcase } unless sql.nil?
|
156
|
-
rescue StandardError => e
|
157
|
-
OpenTelemetry.logger.debug("Error extracting sql statement type: #{e.message}")
|
158
|
-
nil
|
159
|
-
end
|
160
71
|
end
|
161
72
|
end
|
162
73
|
end
|
@@ -20,18 +20,18 @@ module OpenTelemetry
|
|
20
20
|
# Returns the attributes hash representing the Mysql2 context found
|
21
21
|
# in the optional context or the current context if none is provided.
|
22
22
|
#
|
23
|
-
# @param [optional Context]
|
23
|
+
# @param context [optional Context] The context to lookup the current
|
24
24
|
# attributes hash. Defaults to Context.current
|
25
25
|
def attributes(context = nil)
|
26
26
|
context ||= Context.current
|
27
27
|
context.value(CURRENT_ATTRIBUTES_KEY) || {}
|
28
28
|
end
|
29
29
|
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# @param [optional Context] context The context to use as the parent for
|
30
|
+
# @param attributes_hash [Hash] The attributes to add to the context
|
31
|
+
# @param parent_context [optional Context] The context to use as the parent for
|
34
32
|
# the returned context
|
33
|
+
# @return A context containing the merged attributes hash, derived from the
|
34
|
+
# optional parent context, or the current context if one was not provided.
|
35
35
|
def context_with_attributes(attributes_hash, parent_context: Context.current)
|
36
36
|
attributes_hash = attributes(parent_context).merge(attributes_hash)
|
37
37
|
parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-instrumentation-mysql2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.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:
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opentelemetry-helpers-mysql
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opentelemetry-helpers-sql-obfuscation
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: opentelemetry-instrumentation-base
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +184,28 @@ dependencies:
|
|
156
184
|
requirements:
|
157
185
|
- - "~>"
|
158
186
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
187
|
+
version: 1.60.1
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.60.1
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-performance
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '1.20'
|
160
202
|
type: :development
|
161
203
|
prerelease: false
|
162
204
|
version_requirements: !ruby/object:Gem::Requirement
|
163
205
|
requirements:
|
164
206
|
- - "~>"
|
165
207
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
208
|
+
version: '1.20'
|
167
209
|
- !ruby/object:Gem::Dependency
|
168
210
|
name: simplecov
|
169
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,10 +255,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
213
255
|
licenses:
|
214
256
|
- Apache-2.0
|
215
257
|
metadata:
|
216
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-mysql2/0.
|
258
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-mysql2/0.26.0/file/CHANGELOG.md
|
217
259
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/mysql2
|
218
260
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
219
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-mysql2/0.
|
261
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-mysql2/0.26.0
|
220
262
|
post_install_message:
|
221
263
|
rdoc_options: []
|
222
264
|
require_paths:
|