-
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
Changes from 6 commits
c20af16
8165515
a5f4159
ec3a81c
98320d7
9bd9ea6
11d627c
0838c00
9297097
2d6860d
f2a97d2
5d26c79
2cc45bb
361c6d0
29152ed
afdf878
7f834c2
99c0518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,58 @@ | |
|
||
const tx = require('../../dd-trace/src/plugins/util/promise') | ||
|
||
const DD_LIB_COPIES = '_datadog_library_copies' | ||
|
||
function createGetNewLibraryCopyWrap (tracer, config, originalLib, shim) { | ||
return function wrapGetNewLibraryCopy (getNewLibraryCopy) { | ||
return function getNewLibraryCopyWithTrace () { | ||
const libraryCopy = getNewLibraryCopy.apply(this, arguments) | ||
shim.wrap(libraryCopy.prototype, '_then', tx.createWrapThen(tracer, config)) | ||
addToLibraryCopies(originalLib.prototype, libraryCopy) | ||
return libraryCopy | ||
} | ||
} | ||
} | ||
|
||
function addToLibraryCopies (originalLibPrototype, libraryCopy) { | ||
let libraryCopies = originalLibPrototype[DD_LIB_COPIES] | ||
|
||
if (!libraryCopies) { | ||
libraryCopies = new Set() | ||
|
||
Object.defineProperty(originalLibPrototype, DD_LIB_COPIES, { | ||
enumerable: false, | ||
writable: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can set the value here rather than on line 29 with You should also add
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, updated with |
||
}) | ||
|
||
originalLibPrototype[DD_LIB_COPIES] = libraryCopies | ||
} | ||
|
||
libraryCopies.add(libraryCopy) | ||
} | ||
|
||
function unwrapLibraryCopies (originalLibPrototype, shim) { | ||
const libraryCopies = originalLibPrototype[DD_LIB_COPIES] | ||
|
||
if (libraryCopies) { | ||
libraryCopies.forEach(libraryCopy => shim.unwrap(libraryCopy.prototype, '_then')) | ||
libraryCopies.clear() | ||
delete originalLibPrototype[DD_LIB_COPIES] | ||
} | ||
} | ||
|
||
module.exports = [ | ||
{ | ||
name: 'bluebird', | ||
versions: ['^2.11.0', '^3.4.1'], | ||
patch (Promise, tracer, config) { | ||
this.wrap(Promise, 'getNewLibraryCopy', createGetNewLibraryCopyWrap(tracer, config, Promise, this)) | ||
}, | ||
unpatch (Promise) { | ||
this.unwrap(Promise, 'getNewLibraryCopy') | ||
unwrapLibraryCopies(Promise.prototype, this) | ||
} | ||
}, | ||
{ | ||
name: 'bluebird', | ||
versions: ['>=2.0.2'], // 2.0.0 and 2.0.1 were removed from npm | ||
|
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