opentelemetry-helpers-sql-obfuscation 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +5 -3
- data/lib/opentelemetry/helpers/sql_obfuscation/version.rb +1 -1
- data/lib/opentelemetry/helpers/sql_obfuscation.rb +3 -12
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b82b7f32ebee1fdef7b847aab0fdcac539dff5ca52f78fa354afbd571b8223cb
|
4
|
+
data.tar.gz: 7c475ed907c19c0299779b139f0cbe5583639fa6a65020558b623fc8ed060e89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e778e2f31f7e6b733927ea1d8d1f167a2d4c437deac34679d1fa0cbdac8379219c5f0b9539d4186707a9f75afb443110e862d8e1635f243904d353e34f89b6dc
|
7
|
+
data.tar.gz: f400ec85ce9026ce735307af7e139da25f47243ab07302429989ff6fdc0b5e053c0b62b93207d622af1b588873911477aab7aaef6e4c6968613a1589bc32fef6
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
# Release History: opentelemetry-helpers-sql-obfuscation
|
1
|
+
# Release History: opentelemetry-helpers-sql-obfuscation
|
2
|
+
|
3
|
+
### v0.2.0 / 2024-09-12
|
4
|
+
|
5
|
+
- BREAKING CHANGE: Return message when sql is over the obfuscation limit. Fixes a bug where sql statements with prepended comments that hit the obfuscation limit would be sent raw.
|
2
6
|
|
3
7
|
### v0.1.1 / 2024-06-18
|
4
8
|
|
5
|
-
|
9
|
+
- FIXED: Relax otel common gem constraints
|
6
10
|
|
7
11
|
### v0.1.0 / 2024-02-08
|
8
12
|
|
data/README.md
CHANGED
@@ -24,7 +24,8 @@ end
|
|
24
24
|
```
|
25
25
|
|
26
26
|
Make sure the `Instrumentation` class for your gem contains configuration options for:
|
27
|
-
|
27
|
+
|
28
|
+
- `:obfuscation_limit`: the length at which the SQL string will not be obfuscated
|
28
29
|
Example: `option :obfuscation_limit, default: 2000, validate: :integer`
|
29
30
|
|
30
31
|
If you want to add support for a new adapter, update the following constants to include keys for your adapter:
|
@@ -48,7 +49,7 @@ OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: con
|
|
48
49
|
|
49
50
|
The `opentelemetry-helpers-sql-obfuscation` gem source is [on github][repo-github], along with related gems including `opentelemetry-instrumentation-pg` and `opentelemetry-instrumentation-trilogy`.
|
50
51
|
|
51
|
-
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry
|
52
|
+
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
|
52
53
|
|
53
54
|
## License
|
54
55
|
|
@@ -59,4 +60,5 @@ The `opentelemetry-helpers-sql-obfuscation` gem is distributed under the Apache
|
|
59
60
|
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
60
61
|
[ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
|
61
62
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
62
|
-
[
|
63
|
+
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
64
|
+
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
@@ -94,7 +94,7 @@ module OpenTelemetry
|
|
94
94
|
# This is a SQL obfuscation utility intended for use in database adapter instrumentation.
|
95
95
|
#
|
96
96
|
# @param sql [String] The SQL to obfuscate.
|
97
|
-
# @param obfuscation_limit [optional Integer]
|
97
|
+
# @param obfuscation_limit [optional Integer] the length at which the SQL string will not be obfuscated
|
98
98
|
# @param adapter [optional Symbol] the type of database adapter calling the method. `:default`, `:mysql` and `:postgres` are supported.
|
99
99
|
# @return [String] The SQL query string where the values are replaced with "?". When the sql statement exceeds the obufscation limit
|
100
100
|
# the first matched pair from the SQL statement will be returned, with an appended truncation message. If trunaction is unsuccessful,
|
@@ -102,6 +102,8 @@ module OpenTelemetry
|
|
102
102
|
#
|
103
103
|
# @api public
|
104
104
|
def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
|
105
|
+
return "SQL not obfuscated, query exceeds #{obfuscation_limit} characters" if sql.size > obfuscation_limit
|
106
|
+
|
105
107
|
regex = case adapter
|
106
108
|
when :mysql
|
107
109
|
MYSQL_COMPONENTS_REGEX
|
@@ -115,7 +117,6 @@ module OpenTelemetry
|
|
115
117
|
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/160
|
116
118
|
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/345
|
117
119
|
sql = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
|
118
|
-
return truncate_statement(sql, regex, obfuscation_limit) if sql.size > obfuscation_limit
|
119
120
|
|
120
121
|
sql = sql.gsub(regex, PLACEHOLDER)
|
121
122
|
return 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if CLEANUP_REGEX[adapter].match(sql)
|
@@ -124,16 +125,6 @@ module OpenTelemetry
|
|
124
125
|
rescue StandardError => e
|
125
126
|
OpenTelemetry.handle_error(message: 'Failed to obfuscate SQL', exception: e)
|
126
127
|
end
|
127
|
-
|
128
|
-
# @api private
|
129
|
-
def truncate_statement(sql, regex, limit)
|
130
|
-
first_match_index = sql.index(regex)
|
131
|
-
truncation_message = "SQL truncated (> #{limit} characters)"
|
132
|
-
return truncation_message unless first_match_index
|
133
|
-
|
134
|
-
truncated_sql = sql[..first_match_index - 1]
|
135
|
-
"#{truncated_sql}...\n#{truncation_message}"
|
136
|
-
end
|
137
128
|
end
|
138
129
|
end
|
139
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-helpers-sql-obfuscation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2024-
|
11
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-common
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.66.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
96
|
+
version: 1.66.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop-performance
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,10 +155,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
155
155
|
licenses:
|
156
156
|
- Apache-2.0
|
157
157
|
metadata:
|
158
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-obfuscation/0.
|
158
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-obfuscation/0.2.0/file/CHANGELOG.md
|
159
159
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/helpers/sql-obfuscation
|
160
160
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
161
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-obfuscation/0.
|
161
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-obfuscation/0.2.0
|
162
162
|
post_install_message:
|
163
163
|
rdoc_options: []
|
164
164
|
require_paths:
|