-
Notifications
You must be signed in to change notification settings - Fork 544
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(instrumentation-mysql2)!: instrumentation should not include values in db.statement #1857
base: main
Are you sure you want to change the base?
fix(instrumentation-mysql2)!: instrumentation should not include values in db.statement #1857
Conversation
7c101a0
to
6d7aedf
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1857 +/- ##
==========================================
+ Coverage 90.75% 90.81% +0.06%
==========================================
Files 169 169
Lines 8026 8035 +9
Branches 1635 1634 -1
==========================================
+ Hits 7284 7297 +13
+ Misses 742 738 -4
|
8abdce1
to
4fa33f0
Compare
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.
Thanks for the fix!
Added few nit optional comments
plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql2.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
I just found this PR. Its quite egregious to include values in logs. Opens up a lot of auditing issues. Would be great to have this! Seems like development halted on this though 😞 |
Sorry, I was working on the tests when I had to interrupt. |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Hi @JamieDanielson I'll be at kubecon next week, and I'm considering to work on this during the Contribfest, WDYT? |
Sounds good. I'll be there too. |
For whoever decides to work on this, a few considerations:
|
Docker compose snippet: mysql:
image: mysql:5.7
# No ARM64 image layer. See https://stackoverflow.com/a/65592942
platform: linux/x86_64
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
ports:
- "3306:3306"
volumes:
- nodemysqldata:/var/lib/mysql
healthcheck:
test: ["CMD", "mysql" ,"-h", "mysql", "-P", "3306", "-u", "root", "-e", "SELECT 1"]
interval: 1s
timeout: 10s
retries: 30
|
to run the tests on arm64, spin up a container manually
and then run: |
4fa33f0
to
77ee46c
Compare
This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature. |
497024f
to
a2fe940
Compare
I'll sponsor this to avoid the autoclose for unmaintained packages. |
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.
- The plan for this PR has changed. Please update the PR description to describe the current plan.
- Given this is a breaking change, please change the PR title to be
fix(instrumentation-mysql2)!: instrumentation should not include values in db.statement
. The exclamation point indicates a breaking change for the release process. - Note: instrumentation-mysql dealt with this same issue (including values in 'db.statement') in fix(mysql): add enhancedDatabaseReporting to mysql #1337 In that PR a
enhancedDatabaseReporting
boolean config option was added to get the old behaviour back. I think this PR should not add this config option and instead just make the breaking change and wait for common DB handling to be specified by the DB SIG (as Marylia mentioned above).
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts
Outdated
Show resolved
Hide resolved
if ( | ||
arguments.length === 1 || | ||
(arguments.length === 2 && typeof arguments[1] !== 'function') | ||
) { |
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 is an interesting fix that could be mentioned in the PR description. IIUC, before this change, the following usage would result in an unended span:
const sql = 'SELECT 1+? as solution';
const query = connection.query(sql, [2]);
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.
not sure it was a bug, I had to add it since some existing tests were failing. Anyway, looking at it after your comment, I rewrote the statement to simplify it.
@macno This looks great, just a few small requested changes. |
a2fe940
to
d5cd88f
Compare
@macno a side-node: If you are able to avoid force-pushing to a feature branch after there are reviews, that would be helpful. A force push removes the earlier commit shas, so I am not able to see the changes since my last review, for example. It is okay to have a bunch of commits on a feature branch. They will all be squashed into a single commit when the PR is merged. |
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.
Looking good. I have some suggestions, but they don't need to block.
span.end(); | ||
}); | ||
|
||
if (arguments.length === 1) { | ||
if (typeof arguments[arguments.length - 1] !== 'function') { |
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 is okay, but isn't exactly the logic that mysql2
uses to determine if a callback function is passed in. For example, I think the following usage would work with the library, but break the instrumentation:
const sql = 'SELECT 1+1 as solution';
const query = connection.query(sql, cb, null);
Granted that's spectacularly unlikely to be used by a user. :)
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 added a fixup that should address the point you raised
if (isWrapped(ConnectionPrototype.query)) { | ||
this._unwrap(ConnectionPrototype, 'query'); | ||
} | ||
if (isWrapped(ConnectionPrototype.execute)) { | ||
this._unwrap(ConnectionPrototype, 'execute'); | ||
} |
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'm curious, was this added because of your added "initialization" test below? Was that resulting in logger('no original to unwrap to -- has ' + name + ' already been unwrapped?')
console errors?
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.
yes, correct
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('initialization', () => { |
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.
Why the addition of this test? Did you hit some specific issue?
- I think this is not testing what you think it is testing.
With both instrumentation
and instrumentation2
being enabled: the first one wraps, then the second one unwrap and wraps. Then when .disable()
is called for both, the first one unwraps, and the second one is a no-op.
When running just this "initialization" test and with some added logging to show the value of isWrapped(mysqlTypes.Connection.prototype.query)
before and after each enable/disable call, it looks like this:
% RUN_MYSQL_TESTS=1 npm test
> @opentelemetry/[email protected] test
> nyc mocha 'test/**/*.test.ts'
mysql2
initialization
XXX instr2.enable() isWrapped? false
XXX instr2.enabled isWrapped? true
XXX instr.enable() isWrapped? true
XXX instr.enabled isWrapped? true
✔ should not wrap more than once
XXX instr.disable() isWrapped? true
XXX instr.disabled isWrapped? false
XXX instr2.disable() isWrapped? false
XXX instr2.disabled isWrapped? false
1 passing (17ms)
My diff for that test run is here: https://gist.github.com/trentm/d85145848dce0f45b8c440a6f655a078
- We are actually considering dropping
Instrumentation#disable()
functionality altogether. See [instrumentation] consider droppingInstrumentation#disable()
opentelemetry-js#5154 if you are curious.
My preference would be to not add this test.
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.
Honestly, I added it to reach 100% functions and lines coverage and see the branches not covered.
At the moment the only branch not covered is this one https://github.com/macno/opentelemetry-js-contrib/blob/issue-1758-mysql2-instrumentations-values-in-db.statement/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts#L80 which I have no idea how to test..
…db.statement span attribute (open-telemetry#1758)
d5cd88f
to
ee6f9b6
Compare
…ues to db.statement span attribute (open-telemetry#1758)
6f0a8cb
to
6cf79ef
Compare
Which problem is this PR solving?
This PR addresses the bug in #1758 also following what emerged in open-telemetry/semantic-conventions#436
Short description of the changes
This is a breaking change