Skip to content
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

fix(mysql): add enhancedDatabaseReporting to mysql #1337

Merged
merged 25 commits into from
Jan 16, 2023

Conversation

haddasbronfman
Copy link
Member

@haddasbronfman haddasbronfman commented Dec 29, 2022

Which problem is this PR solving?

fixes #1237

Short description of the changes

I added a config object to MySQLInstrumentation with a field called dbStatementSerializer. This is a function which the user can set and decide how to parse his db.statement.

@haddasbronfman haddasbronfman requested a review from a team December 29, 2022 08:48
@codecov
Copy link

codecov bot commented Dec 29, 2022

Codecov Report

Merging #1337 (75d0fab) into main (1ee197e) will decrease coverage by 0.19%.
The diff coverage is 96.55%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1337      +/-   ##
==========================================
- Coverage   96.08%   95.89%   -0.20%     
==========================================
  Files          14       18       +4     
  Lines         893     1168     +275     
  Branches      191      232      +41     
==========================================
+ Hits          858     1120     +262     
- Misses         35       48      +13     
Impacted Files Coverage Δ
...metry-instrumentation-mysql/src/instrumentation.ts 93.18% <94.11%> (ø)
...emetry-instrumentation-mysql/src/AttributeNames.ts 100.00% <100.00%> (ø)
...e/opentelemetry-instrumentation-mysql/src/utils.ts 100.00% <100.00%> (ø)
...tapackages/auto-instrumentations-node/src/utils.ts 98.21% <0.00%> (ø)

@haddasbronfman haddasbronfman marked this pull request as draft December 29, 2022 10:25
@haddasbronfman haddasbronfman marked this pull request as ready for review January 1, 2023 11:42
@haddasbronfman haddasbronfman changed the title fix(mysql): add DbStatementSerializer to mysql fix(mysql): add enhancedDatabaseReporting to mysql Jan 4, 2023
@blumamir
Copy link
Member

blumamir commented Jan 5, 2023

Thanks @haddasbronfman , Maybe I am missing something, but wouldn't all the potentially sensitive values still be written to the db.statement by default?

@haddasbronfman
Copy link
Member Author

You're right.
(This is why I thought to add the dbStatementSerializer in the first place).
But what can we do now?
Serializer is not an option because we should discuss it at the SIG, and enhancedDatabaseReporting is also not an option because it makes no sense to capture the values when they already appear in the db.statement.

@blumamir
Copy link
Member

blumamir commented Jan 5, 2023

You're right. (This is why I thought to add the dbStatementSerializer in the first place). But what can we do now? Serializer is not an option because we should discuss it at the SIG, and enhancedDatabaseReporting is also not an option because it makes no sense to capture the values when they already appear in the db.statement.

The instrumentation actually receives the plain SQL statement without values, and it inject the values here by calling the format function:

  if (typeof query === 'string') {
    return values ? format(query, values) : query;
  } else {
    // According to https://github.com/mysqljs/mysql#performing-queries
    // The values argument will override the values in the option object.
    return values || query.values
      ? format(query.sql, values || query.values)
      : query.sql;
  }

This transforms a query such as SELECT * FROM users WHERE password = ? into SELECT * FROM users WHERE password = "secret".

I think that if we remove the format, we can record the query directly into the values attribute as desired without capturing sensitive data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql instrumentation: query parameters are recorded by default
2 participants