opentelemetry-instrumentation-mysql2 0.25.0 → 0.26.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb52d41370dd6f755503f63f131a747bb9790f7fb680f863dc4864932c7b5c1
|
4
|
+
data.tar.gz: f1779dde36425c213453c779d3ffe3cf3cd4f2bc71f2e6f83cce3c143567e505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c880aabf7e508fec4e11b83663319dfb620c890da0e1860d567e548427ad11bdef3811ccdc72d42cca0a056388a1ed87c0620057447492299ca6654c6d8731b
|
7
|
+
data.tar.gz: ab203d87c0d2d12afa8ba9596ae01ceba00c33802079d87a02f067d22b935795b9516764ff17bf58829ea42c6a0f0eaf54adf2a64ed535051ed9fe88b86903a8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-mysql2
|
2
2
|
|
3
|
+
### v0.26.1 / 2024-02-08
|
4
|
+
|
5
|
+
* FIXED: Add missing requires for sql-helpers to mysql, pg, and trilogy instrumentation
|
6
|
+
|
7
|
+
### v0.26.0 / 2024-02-08
|
8
|
+
|
9
|
+
* BREAKING CHANGE: Move shared sql behavior to helper gems
|
10
|
+
|
11
|
+
|
3
12
|
### v0.25.0 / 2023-10-16
|
4
13
|
|
5
14
|
* BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement
|
@@ -4,63 +4,35 @@
|
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
|
+
require 'opentelemetry-helpers-mysql'
|
8
|
+
require 'opentelemetry-helpers-sql-obfuscation'
|
9
|
+
|
7
10
|
module OpenTelemetry
|
8
11
|
module Instrumentation
|
9
12
|
module Mysql2
|
10
13
|
module Patches
|
11
14
|
# 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
|
-
|
15
|
+
module Client
|
54
16
|
def query(sql, options = {})
|
55
17
|
attributes = client_attributes
|
56
18
|
case config[:db_statement]
|
57
19
|
when :include
|
58
20
|
attributes[SemanticConventions::Trace::DB_STATEMENT] = sql
|
59
21
|
when :obfuscate
|
60
|
-
attributes[SemanticConventions::Trace::DB_STATEMENT] =
|
22
|
+
attributes[SemanticConventions::Trace::DB_STATEMENT] =
|
23
|
+
OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(
|
24
|
+
sql, obfuscation_limit: config[:obfuscation_limit], adapter: :mysql
|
25
|
+
)
|
61
26
|
end
|
62
27
|
tracer.in_span(
|
63
|
-
database_span_name(
|
28
|
+
OpenTelemetry::Helpers::MySQL.database_span_name(
|
29
|
+
sql,
|
30
|
+
OpenTelemetry::Instrumentation::Mysql2.attributes[
|
31
|
+
SemanticConventions::Trace::DB_OPERATION
|
32
|
+
],
|
33
|
+
database_name,
|
34
|
+
config
|
35
|
+
),
|
64
36
|
attributes: attributes.merge!(OpenTelemetry::Instrumentation::Mysql2.attributes),
|
65
37
|
kind: :client
|
66
38
|
) do
|
@@ -70,57 +42,6 @@ module OpenTelemetry
|
|
70
42
|
|
71
43
|
private
|
72
44
|
|
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
45
|
def database_name
|
125
46
|
# https://github.com/brianmario/mysql2/blob/ca08712c6c8ea672df658bb25b931fea22555f27/lib/mysql2/client.rb#L78
|
126
47
|
(query_options[:database] || query_options[:dbname] || query_options[:db])&.to_s
|
@@ -150,13 +71,6 @@ module OpenTelemetry
|
|
150
71
|
def config
|
151
72
|
Mysql2::Instrumentation.instance.config
|
152
73
|
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
74
|
end
|
161
75
|
end
|
162
76
|
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.1
|
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.1/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.1
|
220
262
|
post_install_message:
|
221
263
|
rdoc_options: []
|
222
264
|
require_paths:
|