-
Notifications
You must be signed in to change notification settings - Fork 307
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
update bluebird instrumentation to account for getNewLibraryCopy #813
update bluebird instrumentation to account for getNewLibraryCopy #813
Conversation
…getNetLibraryCopy for 2.11.0 and 3.4.1
just to update, I've gone ahead and added what I think is the right way to do versioning for the plugin, by adding this additional object to the module.exports array. And i think i answered my own question on the
Anyway lmk what you think! cheers |
just a quick update, spoke informally about this with @bengl , he pointed out that this had originally failed 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.
One small change requested. Other than that, looks good.
Also, this functionality is sufficiently complicated that it warrants a test.
|
||
Object.defineProperty(originalLibPrototype, DD_LIB_COPIES, { | ||
enumerable: false, | ||
writable: 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.
You can set the value here rather than on line 29 with value: libraryCopies
.
You should also add configurable: true
.
enumerable: false
is the default, so you can omit it if you want. (Your choice.)
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.
makes sense, updated with configurable
and value
and using the enumerable
default
return result | ||
const libraryCopy = getNewLibraryCopy.apply(this, arguments) | ||
shim.wrap(libraryCopy.prototype, '_then', tx.createWrapThen(tracer, config)) | ||
addToLibraryCopies(originalLib.prototype, libraryCopy) |
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 there any particular reason to stash this on the prototype rather than the class/constructor? Just curious.
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.
nope, no good reason, updated to point to the constructor instead
…nproperty settings, use promise constructor instead of prototype
Thanks for the feedback @bengl , makes sense to me, I've cleaned up the bits mentioned in review and added some additional bluebird tests here for the mechanics introduced for tracking library copies. The tests did require a bit of utility code to isolate testing the |
bluebird = require(`../../../versions/bluebird@${version}`).get() | ||
}) | ||
|
||
describe('patching', () => { |
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.
For testing purposes, I think we're less concerned with the implementation details (except that they're not hanging around after unpatch). The previously added test already ensures that it's been patched. The 'unpatching'
tests ensure that we've properly unpatched, so we're good with that I think.
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.
k makes sense, as long as the hidden property logic is specified in the unpatching section i think that's fine, updated this patching
spec removed
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.
Left a few comments for the tests, but otherwise code LGTM.
…semver check to promise util specs, clean up bluebird spec syntax
…add promise-js version range filtering in specs
Any progress on this? Eagerly waiting for this to be implemented. Want to use Tracing in our production environment :D! |
@guidsen The plan is to include it in the next release. There are just a few small requested changes left and then it's good to go. |
Great to hear. Thanks for the effort. |
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.
tried to address all the last round of feedback @rochdev , i think we're there, but let me know what you think.
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.
@bengl Please do a second pass since you had requested changes. It looks like everything has been addressed.
Hey there. Nice that this is being merged. When are you planning to release this? |
@guidsen Released in 0.17.0. Sorry for the delay! |
No worries. Thanks for the help guys! |
* remove tagging in version script (DataDog#746) * fix runtime metrics in node 8 for windows and mac (DataDog#745) * add environment variables to configure the priority sampler (DataDog#749) * fix grpc parsing error causing an exception from the plugin (DataDog#750) * add tracer metrics for the agent exporter (DataDog#748) * add rum context as tags to browser traces (DataDog#751) * update priority sampling environment variables to be more explicit (DataDog#752) * add more tracer metrics and fix counters (DataDog#753) * fix release script with new endpoint and add retries (DataDog#754) * fix wrong artifact used for node 8 on linux when releasing (DataDog#755) * update prepublish script to use last workflow run instead of first (DataDog#756) * update prepublish script to use last workflow run instead of first * sort workflows and add check for unfinished workflows * update prepublish script to use new workflow api (DataDog#757) * fix fetch plugin dropping headers when calling non-peers (DataDog#758) * fix tracer exception because of missing metrics api method (DataDog#761) * fix xhr errors throwing in sync mode (DataDog#762) * add tests and checksum validation for prebuilt native addons (DataDog#763) * update xhr and fetch to not generate traces for rum intake (DataDog#769) * fix url reference in xhr intake filter (DataDog#770) * fix error in graphql plugin with unpatched context values (DataDog#765) * update build scripts to use a single prebuilds artifact (DataDog#767) * fix log injection removing inherited properties on log records (DataDog#771) * fix async scope tracking not resolving awaited promises (DataDog#772) * update async scope tracking to not track itself (DataDog#773) * fix missing/wrong native extensions in scripts (DataDog#774) * add safety nets for type errors in amqplib plugin (DataDog#777) * add safety nets for type errors in cassandra-driver plugin (DataDog#778) * add safety nets for type errors in connect plugin (DataDog#779) * add safety nets for type errors in couchbase plugin (DataDog#782) * add safety nets for type errors in dns plugin (DataDog#783) * add safety nets for type errors in elasticsearch plugin (DataDog#784) * add safety nets for type errors in generic-pool plugin (DataDog#786) * add safety nets for type errors in fastify plugin (DataDog#785) * add safety nets for type errors in amqp10 plugin (DataDog#776) * fix log injection not working when logger is required before dd-trace (DataDog#781) * Add support for disabling plugins by environment variable (DataDog#733) * add check for integrations disabled config option on tracer init plug loop * [in prog] add specs to test that enable skipped disabled integrations * fix tests and linting, improve naming convention * add api docs markdown and typescript definition formatting * improve debug log language * add ternary operator in configuration to handle converting string environment variable input to array * [wip] refactor to use plugins object in private _set method, add disabledPlugins to instrumentor constructor * account for edge case where .use adds a plugin before disabledPlugins list could be set * handle plugins option config via multiple formats * add specs and lint cleanup * fix specs * fix .enable edgecase where .use is called beforehand by matching w/correct Map key * use correct env var and update api docs * remember to reset disabled plugins on .disable * adjust plugins config to only take boolean or array of disabled plugins and only csv string by env var and update specs accordingly * typo fix in instrumenter * refactor configuration to have disabledPlugins as seperate env var, update specs and docs accordingly, account for white space in csv formatting * refactor to only use env var and update specs and docs accoordingly * typo fix * remove added whitespace * make tests more explicit for env var, cleanup language clarity * delete env var instead of setting to undefined * add safety nets for type errors in graphql plugin (DataDog#787) * add safety nets for type errors in grpc plugin (DataDog#788) * add safety nets for type errors in hapi plugin (DataDog#789) * fix base scope missing the _activate protected method (DataDog#791) * update browser http request resource name to browser.request (DataDog#795) * remove default rate limit in priority sampler (DataDog#796) * add regex support for peer configuration (DataDog#798) * remove dependencies on zone.js and core-js (DataDog#799) * add safety net for uri errors in http plugin (DataDog#800) * add safety nets for type errors in http2 plugin (DataDog#802) * add benchmarks for node platform metrics (DataDog#805) * add safety nets for type errors in ioredis plugin (DataDog#808) * add safety nets for type errors in koa plugin (DataDog#809) * add safety nets for type errors in limitd-client plugin (DataDog#810) * add support for rhea (DataDog#801) * add support for `only` and `skip` in tests * add support for rhea * Revert "remove default rate limit in priority sampler (DataDog#796)" This reverts commit 7ab6af0. * update tracer to support numeric tags (DataDog#804) * add experimental global runtime id tag (DataDog#816) * add span hook for elasticsearch query (DataDog#818) * Add hook for elasticsearch query and option to remove query body * Add typescript tests * Remove includeBody option and add params to hook * Add TransportRequestParams type and test params * Add elasticsearch license * Update license to be consistent * Fix unit tests * Remove dependency on elasticsearch package * fix possible stack overflow with mysql2 command executions (DataDog#821) * fix main-finding in nodejs loader (DataDog#822) Some Node.js packages use a leading `./` to indicate their "main" file. This broke the Node.js loader, which was comparing require paths against this. This is now fixed by using `path.posix.normalize` on the "main" file. * fix rhea integration for numeric tags (DataDog#823) * update sinon chai and sinon-chai (DataDog#824) * fix cassandra-driver plugin not working for >=4.4 (DataDog#825) * fix log injection removing symbols from log records (DataDog#819) * account for Symbol keys for winston splat handling * use for of loop and check for undefined or null records * remove local changes * remove typos on testing local changes * use correct syntax for for of loop * linting fix * simplify for loop * add specs to verify splat formatting is handled correctly * remove duplicated test * update bluebird instrumentation to account for getNewLibraryCopy (DataDog#813) * handle usage of getNewLibraryCopy by sequelize * [wip] add promise spec for getNewLibraryCopy need to determine min version still * fix unwrap typo, add temp fix and todos for version requirements for getNetLibraryCopy for 2.11.0 and 3.4.1 * add getNewLibraryCopy patching only for versions where it exists * handle unwrapping copies _then by maintaining reference to copies on original promise library * make hidden property non enumerable * [wip] add specs for patching and unpatching behavior , clean up hiddenproperty settings, use promise constructor instead of prototype * add specs for mechanics of tracking wrapped bluebird library copies for unpatching * remove duplicate patching specs * add version filter for bluebird version specific instrumentation * generalize unpatching test for all promise libraries * handle edge case when non native promise libraries default to native promises * only instrument promisejs when it doesnt export global promise, move semver check to promise util specs, clean up bluebird spec syntax * only instrument promise-js on versions it isnt used native promises, add promise-js version range filtering in specs * simplify version checking and test pre / post patching and unpatching behavior * es6 syntax improvement * fix beforeEach handling of promises * add test for copy of copy being unwrapped * Dual License (DataDog#832) * add support for WHATWG URL in http client (DataDog#833) * add support for WHATWG by removing Object assign usage * linting and move spec to >10 bc it was breaking on ode8 image * use async format for unit test * add await to spec and make url normalization cleaner * initial fs support (DataDog#814) * initial fs support * allow `yarn lint --fix` * support large payloads in test agent * don't trace fs operations unless there's a parent span * fix tsconfig for current versions of @types/node (DataDog#836) * fix fs readFile when options is string (DataDog#835) * remove support for koa-router 8.x until properly supported * update http status code temporarily to always be a string (DataDog#838) * v0.17.0 (DataDog#839) * remove several unnecessary dependencies in the browser (DataDog#797) * fix runtime metrics having prefix in double (DataDog#843) * Add @google-cloud/pubsub integration (DataDog#834) * add defaults test helper, and optional span logging * add support for @goolge-cloud/pubsub Co-authored-by: Roch Devost <roch.devost@gmail.com> Co-authored-by: Eric Mustin <mustin.eric@gmail.com> Co-authored-by: Bryan English <bryan@bryanenglish.com> Co-authored-by: Brett Langdon <me@brett.is> Co-authored-by: Joey Lappin <joey@creepysnake.com> Co-authored-by: Jeremy <jeremy-lq@users.noreply.github.com>
* remove tagging in version script (DataDog#746) * fix runtime metrics in node 8 for windows and mac (DataDog#745) * add environment variables to configure the priority sampler (DataDog#749) * fix grpc parsing error causing an exception from the plugin (DataDog#750) * add tracer metrics for the agent exporter (DataDog#748) * add rum context as tags to browser traces (DataDog#751) * update priority sampling environment variables to be more explicit (DataDog#752) * add more tracer metrics and fix counters (DataDog#753) * fix release script with new endpoint and add retries (DataDog#754) * fix wrong artifact used for node 8 on linux when releasing (DataDog#755) * update prepublish script to use last workflow run instead of first (DataDog#756) * update prepublish script to use last workflow run instead of first * sort workflows and add check for unfinished workflows * update prepublish script to use new workflow api (DataDog#757) * fix fetch plugin dropping headers when calling non-peers (DataDog#758) * fix tracer exception because of missing metrics api method (DataDog#761) * fix xhr errors throwing in sync mode (DataDog#762) * add tests and checksum validation for prebuilt native addons (DataDog#763) * update xhr and fetch to not generate traces for rum intake (DataDog#769) * fix url reference in xhr intake filter (DataDog#770) * [wip] add configuration to disable express middlware * add specs for disableMiddleware and update related specs * fix error in graphql plugin with unpatched context values (DataDog#765) * update build scripts to use a single prebuilds artifact (DataDog#767) * fix log injection removing inherited properties on log records (DataDog#771) * fix async scope tracking not resolving awaited promises (DataDog#772) * make default false boolean explicit add ts definition and test * dont include duplicate tests * update async scope tracking to not track itself (DataDog#773) * add specs for still instrumenting error handling * update other invocations of web.wrapMiddleware * fix missing/wrong native extensions in scripts (DataDog#774) * add safety nets for type errors in amqplib plugin (DataDog#777) * add safety nets for type errors in cassandra-driver plugin (DataDog#778) * add safety nets for type errors in connect plugin (DataDog#779) * add safety nets for type errors in couchbase plugin (DataDog#782) * add safety nets for type errors in dns plugin (DataDog#783) * add safety nets for type errors in elasticsearch plugin (DataDog#784) * add safety nets for type errors in generic-pool plugin (DataDog#786) * add safety nets for type errors in fastify plugin (DataDog#785) * add safety nets for type errors in amqp10 plugin (DataDog#776) * fix log injection not working when logger is required before dd-trace (DataDog#781) * Add support for disabling plugins by environment variable (DataDog#733) * add check for integrations disabled config option on tracer init plug loop * [in prog] add specs to test that enable skipped disabled integrations * fix tests and linting, improve naming convention * add api docs markdown and typescript definition formatting * improve debug log language * add ternary operator in configuration to handle converting string environment variable input to array * [wip] refactor to use plugins object in private _set method, add disabledPlugins to instrumentor constructor * account for edge case where .use adds a plugin before disabledPlugins list could be set * handle plugins option config via multiple formats * add specs and lint cleanup * fix specs * fix .enable edgecase where .use is called beforehand by matching w/correct Map key * use correct env var and update api docs * remember to reset disabled plugins on .disable * adjust plugins config to only take boolean or array of disabled plugins and only csv string by env var and update specs accordingly * typo fix in instrumenter * refactor configuration to have disabledPlugins as seperate env var, update specs and docs accordingly, account for white space in csv formatting * refactor to only use env var and update specs and docs accoordingly * typo fix * remove added whitespace * make tests more explicit for env var, cleanup language clarity * delete env var instead of setting to undefined * generalize disableMiddleware config to middleware httpserver config, add tests and config for web server frameworks which have middleware auto instrumentation * fix web getMiddlewareSetting logic * [WIP] fixing tests * add safety nets for type errors in graphql plugin (DataDog#787) * add safety nets for type errors in grpc plugin (DataDog#788) * add safety nets for type errors in hapi plugin (DataDog#789) * fix base scope missing the _activate protected method (DataDog#791) * update browser http request resource name to browser.request (DataDog#795) * adjust specs for middleware being disabled * fix test to ensure middleware active scope is null * remove redundant expressOptions and rely on general httpServerOptions * [WIP] wrapMiddleware errors to ensure middleware errors get error message and stack appended to active span * remove default rate limit in priority sampler (DataDog#796) * add regex support for peer configuration (DataDog#798) * remove dependencies on zone.js and core-js (DataDog#799) * add safety net for uri errors in http plugin (DataDog#800) * add safety nets for type errors in http2 plugin (DataDog#802) * add benchmarks for node platform metrics (DataDog#805) * add safety nets for type errors in ioredis plugin (DataDog#808) * add safety nets for type errors in koa plugin (DataDog#809) * add safety nets for type errors in limitd-client plugin (DataDog#810) * add support for rhea (DataDog#801) * add support for `only` and `skip` in tests * add support for rhea * clean up test case for status code validation errors * Revert "remove default rate limit in priority sampler (DataDog#796)" This reverts commit 7ab6af0. * update tracer to support numeric tags (DataDog#804) * add experimental global runtime id tag (DataDog#816) * add span hook for elasticsearch query (DataDog#818) * Add hook for elasticsearch query and option to remove query body * Add typescript tests * Remove includeBody option and add params to hook * Add TransportRequestParams type and test params * Add elasticsearch license * Update license to be consistent * Fix unit tests * Remove dependency on elasticsearch package * fix possible stack overflow with mysql2 command executions (DataDog#821) * fix main-finding in nodejs loader (DataDog#822) Some Node.js packages use a leading `./` to indicate their "main" file. This broke the Node.js loader, which was comparing require paths against this. This is now fixed by using `path.posix.normalize` on the "main" file. * fix rhea integration for numeric tags (DataDog#823) * update sinon chai and sinon-chai (DataDog#824) * fix cassandra-driver plugin not working for >=4.4 (DataDog#825) * fix log injection removing symbols from log records (DataDog#819) * account for Symbol keys for winston splat handling * use for of loop and check for undefined or null records * remove local changes * remove typos on testing local changes * use correct syntax for for of loop * linting fix * simplify for loop * add specs to verify splat formatting is handled correctly * remove duplicated test * update bluebird instrumentation to account for getNewLibraryCopy (DataDog#813) * handle usage of getNewLibraryCopy by sequelize * [wip] add promise spec for getNewLibraryCopy need to determine min version still * fix unwrap typo, add temp fix and todos for version requirements for getNetLibraryCopy for 2.11.0 and 3.4.1 * add getNewLibraryCopy patching only for versions where it exists * handle unwrapping copies _then by maintaining reference to copies on original promise library * make hidden property non enumerable * [wip] add specs for patching and unpatching behavior , clean up hiddenproperty settings, use promise constructor instead of prototype * add specs for mechanics of tracking wrapped bluebird library copies for unpatching * remove duplicate patching specs * add version filter for bluebird version specific instrumentation * generalize unpatching test for all promise libraries * handle edge case when non native promise libraries default to native promises * only instrument promisejs when it doesnt export global promise, move semver check to promise util specs, clean up bluebird spec syntax * only instrument promise-js on versions it isnt used native promises, add promise-js version range filtering in specs * simplify version checking and test pre / post patching and unpatching behavior * es6 syntax improvement * fix beforeEach handling of promises * add test for copy of copy being unwrapped * Dual License (DataDog#832) * add support for WHATWG URL in http client (DataDog#833) * add support for WHATWG by removing Object assign usage * linting and move spec to >10 bc it was breaking on ode8 image * use async format for unit test * add await to spec and make url normalization cleaner * initial fs support (DataDog#814) * initial fs support * allow `yarn lint --fix` * support large payloads in test agent * don't trace fs operations unless there's a parent span * fix tsconfig for current versions of @types/node (DataDog#836) * fix fs readFile when options is string (DataDog#835) * remove support for koa-router 8.x until properly supported * update http status code temporarily to always be a string (DataDog#838) * v0.17.0 (DataDog#839) * remove several unnecessary dependencies in the browser (DataDog#797) * fix runtime metrics having prefix in double (DataDog#843) * Add @google-cloud/pubsub integration (DataDog#834) * add defaults test helper, and optional span logging * add support for @goolge-cloud/pubsub * fix wrong route for koa-router 8 (DataDog#844) * effectively test scope being request scope in middleeware and account for this in web utils * lint fix and use meta status code as string not metric as int * fix koa config passing and tests to account for new router approach Co-authored-by: Roch Devost <roch.devost@gmail.com> Co-authored-by: Eric Mustin <mustin.eric@gmail.com> Co-authored-by: Bryan English <bryan@bryanenglish.com> Co-authored-by: Brett Langdon <me@brett.is> Co-authored-by: Joey Lappin <joey@creepysnake.com> Co-authored-by: Jeremy <jeremy-lq@users.noreply.github.com>
What does this PR do?
The Bluebird promise library added a helper function
getNewLibraryCopy
in versions 2.11.0 and 3.4.1 which:Usage of this helper method in turn causes the dd-trace-js bluebird instrumentation to get dropped. This PR adds instrumentation to ensure that independant copy of the bluebird library is also instrumented.
Motivation
This helper method is used by the popular Node ORM Sequelize, seen here. As a result, if a basic
express/sequelize/(pg|mysql)
MVC application receives concurrent requests, dd-trace-js instrumentation attaches the database spans to the incorrect trace. You can see a quick screenshot of this behavior, and I'm including a link to a basic express/sequelize application and a script for a trivial reproduction of the issue below. Sorry the repro is a bit hacky, it's quite easy to reproduce though if you want to test however you prefer:Reproduction of previous behavior:
Run express/sequelize application:
https://github.com/ericmustin/sample_sequelize_express_app
with the application listening on
localhost:3000
run test script for making concurrent requests:https://gist.github.com/ericmustin/d70dfc9fdfb78732302a119793ad7c44
Output:
And, with this update applied this is handled correctly:
Plugin Checklist
Additional Notes
A few things. First is that this helper method wasn't added for v2 and v3 until 2.11.0 and 3.4.1, respectively (i've linked to the release notes in the previous section). However I wasn't entirely sure how to handle the versioning bit in
datadog-plugin-bluebird/src/index.js
andupdating the(this is auto generated by yarn, ignore) directory. My thinking for the instrumentation was adding additional objects to the module exports aladd-trace-js/versions
But I wasn't entirely if these are incremental or not (ie, should I do all the wrapping in here or just the bit that applies to
^2.11.0
/^3.4.1
?And also is there documentation on how those details in the versions folder are generated?(auto generated by yarn, ignore)In the interim I've just added some defensive code in both the unit tests and the instrumentation code to ensure that we only attempt to patch when this function exists. Any guidance here on the proper way to do this
and how to generate the right files in the versions directory ( is there some stuff in the scripts directory I run?)would be much appreciated.Also just generally let me know if my approach here for accounting for this helper function in bluebird is appropriate. Although this is meant to get sequelize working, as I assume it's a relatively widely used helper function I kept all the instrumentation as part of core bluebird and not something sequelize specific. Lmk if that is way off. This update works for me as far as fixing database spans getting assigned to the wrong trace, but not sure if there's a more canonical way to instrument this sort of helper method.
thanks for taking a look!