Skip to content

Commit

Permalink
fix: Guard clause for truncation
Browse files Browse the repository at this point in the history
Don't even set the regex adapter if the SQL's over the limit, just
return the message and get out of there
  • Loading branch information
kaylareopelle committed Sep 6, 2024
1 parent 15a3d10 commit 6a13777
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def generate_regex(dialect)
#
# @api public
def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
return "SQL truncated (> #{obfuscation_limit} characters)" if sql.size > obfuscation_limit

regex = case adapter
when :mysql
MYSQL_COMPONENTS_REGEX
Expand All @@ -114,7 +116,6 @@ def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
# Original MySQL UTF-8 Encoding Fixes:
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/160
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/345
return "SQL truncated (> #{obfuscation_limit} characters)" if sql.size > obfuscation_limit
sql = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)

sql = sql.gsub(regex, PLACEHOLDER)
Expand Down

0 comments on commit 6a13777

Please sign in to comment.