-
Notifications
You must be signed in to change notification settings - Fork 98
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
Port mysql plugin to support mysql2 #607
Port mysql plugin to support mysql2 #607
Conversation
src/plugins/plugin-mysql2.ts
Outdated
|
||
function createCreateQueryWrap(api) { | ||
return function createQueryWrap(createQuery) { | ||
return function createQuery_trace(sql, values, cb, config) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
api.wrapEmitter(query); | ||
if (query.onResult) { | ||
query.onResult = wrapCallback(api, span, query.onResult); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-mysql2.ts
Outdated
shimmer.unwrap(Pool.prototype, 'getConnection'); | ||
} | ||
} | ||
]; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-mysql2.ts
Outdated
|
||
var shimmer = require('shimmer'); | ||
|
||
var SUPPORTED_VERSIONS = '^1.3.5'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Thanks for the PR! I'm taking a look now... in the meantime, there's a script bin/docker-trace.sh that contains commands for launching docker containers for each of these databases. To make unit tests work you'll need to have all four services running. This should be the only pre-requisite to running unit tests with As the APIs are similar it may be sufficient to edit test/plugins/test-trace-mysql.ts to make it so that every unit test is run twice, once for If you don't have time to do this that's fine, don't hesitate to let me know and I will update the tests. |
Great! That sounds simple enough - I will finish up the tests tomorrow morning then 👍 |
src/plugins/plugin-mysql2.ts
Outdated
|
||
var shimmer = require('shimmer'); | ||
|
||
var SUPPORTED_VERSIONS = '^1.3.5'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
file: 'lib/connection.js', | ||
versions: SUPPORTED_VERSIONS, | ||
patch: function(Connection, api) { | ||
shimmer.wrap(Connection, 'createQuery', createCreateQueryWrap(api)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-mysql2.ts
Outdated
|
||
function createCreateQueryWrap(api) { | ||
return function createQueryWrap(createQuery) { | ||
return function createQuery_trace(sql, values, cb, config) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I'm getting the following failed test when running locally: 1) test-trace-connect
should remove trace frames from stack:
Uncaught AssertionError [ERR_ASSERTION]: 'Namespace.runAndReturn [as runAndReturn]' == 'middleware'
+ expected - actual
-Namespace.runAndReturn [as runAndReturn]
+middleware
at ClientRequest.<anonymous> (/Users/julienvincent/code/cloud-trace-nodejs/test/plugins/test-trace-connect.ts:127:16)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:565:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
at Socket.socketOnData (_http_client.js:454:20)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread [as _originalOnread] (net.js:589:20)
at TCP.onread (/Users/julienvincent/code/cloud-trace-nodejs/node_modules/async-listener/glue.js:188:31) As far as I can see this has nothing to do with the changes I made. Any ideas? |
Oops - this test failure has to do with the |
I'm struggling with a strange issue now that I can't piece together. @kjin Perhaps you could help me understand whats happening here: Defining a patcher for test-trace-mysql-2
✓ should perform basic operations
✓ should propagate context
✓ should remove trace frames from stack
✓ should work with events
✓ should work without events or callback (54ms)
✓ should perform basic transaction
test-trace-mysql2-1
1) "before all" hook
2) "after all" hook
6 passing (368ms)
2 failing
1) test-trace-mysql2-1
"before all" hook:
TypeError: Pool is not a constructor
at Object.module.exports.createPool (test/plugins/fixtures/mysql2-1/node_modules/mysql2/index.js:17:10)
at Context.<anonymous> (/Users/julienvincent/code/cloud-trace-nodejs/test/plugins/test-trace-mysql.ts:44:20)
2) test-trace-mysql2-1
"after all" hook:
TypeError: Cannot read property 'end' of undefined
at Context.<anonymous> (/Users/julienvincent/code/cloud-trace-nodejs/test/plugins/test-trace-mysql.ts:48:11) and the exports of the module.exports = [
{
file: 'lib/connection.js',
versions: SUPPORTED_VERSIONS,
patch: function(Connection, api) {
shimmer.wrap(Connection, 'createQuery', createCreateQueryWrap(api));
},
unpatch: function(Connection) {
shimmer.unwrap(Connection, 'createQuery');
}
},
{
file: 'lib/pool.js',
versions: SUPPORTED_VERSIONS,
patch: function(Pool, api) {
// shimmer.wrap(Pool.prototype, 'getConnection',
// createWrapGetConnection(api));
},
unpatch: function(Pool) {
// shimmer.unwrap(Pool.prototype, 'getConnection');
}
}
]; As you can see the patcher itself is not doing anything to What I have done for now is change the pool patcher to target |
I don't think the tests that just failed on CircleCI were due to my changes - could you retry the build? I think circle was just slow and the timeout was exceeded. |
@julienvincent I looked into the lib/pool.js patch issue you mentioned yesterday... I'm as baffled as you are. Investigating more today. |
I can say that I was able to patch that file fine while using version |
Yes, it seems like it. I think I understand the issue now -- will open a bug imminently. In the meantime, if the patch to |
Aha! Circular references - that makes sense now. Yes the patch to |
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.
LGTM. Thanks! (I'll fix #618, and use your initial version patching lib/pool.js
to see if it works)
Great! Thanks for your help, I will follow #618 for updates 🎉 |
This PR adds support for the
mysql2
npm module (as per #582).I am unsure on how to get the test suite up and running correctly, if someone could point me in the right direction I'd be happy to also write tests for the added plugin 👍
I will put comments on the relevant lines that changed from
plugin-mysql.js