-
Notifications
You must be signed in to change notification settings - Fork 226
fix: handle encoding errors in mysql obfuscation #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1806119 to
c98338c
Compare
c98338c to
cbcad76
Compare
plantfansam
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| obfuscated | ||
| end | ||
| rescue StandardError | ||
| 'OpenTelemetry error: failed to obfuscate sql' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make a more specific error message here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how specific to make it, this is what will get plunked into the the db.statement attribute field. I'm being prudent about capturing any information about what was failed to be obfuscated.
What did you have in mind? Like the error class or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realize that this would get put into the db.statement field, which is my bad for not looking closely enough. I think this is fine. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not something you need to address here, but it'd be useful to use a common prefix for all the "error" type substitutions (this and the two above) - it'd make it easier for Observability teams to monitor this behaviour. Metrics might be nice as well, but a competent engineer can build metrics from the db.statement in a span processor or in the collector.
|
Ya'll need to stop approving my failing PR lol |
|
Can anyone guess why the span.name is true in my failing test 😭 Lines 144 to 148 in cbcad76
|
|
I mean technically true is not nil. Lines 98 to 112 in cbcad76
|
8f213a1 to
bab4c08
Compare
| QUERY_NAME_RE.match(sql) { |match| match[1].downcase } unless sql.nil? | ||
| rescue StandardError => e | ||
| OpenTelemetry.logger.debug("Error extracting sql statement type: #{e.message}") | ||
| nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is covered by my new test.
| 'SQL query too large to remove sensitive data ...' | ||
| else | ||
| obfuscated = sql.gsub(generated_mysql_regex, '?') | ||
| obfuscated = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're setting binary to true in redis, and dalli.
Line 70 in 6df0122
| OpenTelemetry::Common::Utilities.utf8_encode(serialized_commands, binary: true) |
opentelemetry-ruby-contrib/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/utils.rb
Line 57 in 6df0122
| command = OpenTelemetry::Common::Utilities.utf8_encode(command, binary: true, placeholder: placeholder) |
So I think it makes sense here.
https://github.com/open-telemetry/opentelemetry-ruby/blob/18bfd391f2bda2c958d5d6935886c8cba61414dd/common/lib/opentelemetry/common/utilities.rb#L40-L63
@robertlaurin this is merely a reflection of how high your trust battery charge is with me |
|
Are other SQL instrumentations broken in the same way? |
It looks like Trilogy and PG may be vulnerable to the same error. I'll get this out and it see how it does in production before porting it over to the other two. |
😭