Skip to content

Commit 0f4b75e

Browse files
authored
fix: made wrapFunction unique to functions (#6796)
1 parent ee7e32f commit 0f4b75e

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

packages/datadog-instrumentations/src/cucumber.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function wrapRun (pl, isLatestVersion, version) {
259259
testStartCh.runStores(ctx, () => {})
260260
const promises = {}
261261
try {
262-
this.eventBroadcaster.on('envelope', shimmer.wrapFunction(null, () => async (testCase) => {
262+
this.eventBroadcaster.on('envelope', async (testCase) => {
263263
// Only supported from >=8.0.0
264264
if (testCase?.testCaseFinished) {
265265
const { testCaseFinished: { willBeRetried } } = testCase
@@ -289,7 +289,7 @@ function wrapRun (pl, isLatestVersion, version) {
289289
testStartCh.runStores(newCtx, () => {})
290290
}
291291
}
292-
}))
292+
})
293293
let promise
294294

295295
testFnCh.runStores(ctx, () => {

packages/datadog-instrumentations/src/mariadb.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ function createWrapQueryCallback (options) {
8282

8383
const cb = arguments[arguments.length - 1]
8484
const ctx = { sql, conf: options }
85-
86-
if (typeof cb !== 'function') {
87-
arguments.length += 1
88-
}
89-
90-
arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function (err) {
85+
const wrapper = (cb) => function (err) {
9186
if (err) {
9287
ctx.error = err
9388
errorCh.publish(ctx)
@@ -96,7 +91,14 @@ function createWrapQueryCallback (options) {
9691
return typeof cb === 'function'
9792
? finishCh.runStores(ctx, cb, this, ...arguments)
9893
: finishCh.publish(ctx)
99-
})
94+
}
95+
96+
if (typeof cb === 'function') {
97+
arguments[arguments.length - 1] = shimmer.wrapFunction(cb, wrapper)
98+
} else {
99+
arguments.length += 1
100+
arguments[arguments.length - 1] = wrapper()
101+
}
100102

101103
return startCh.runStores(ctx, query, this, ...arguments)
102104
}

packages/datadog-shimmer/src/shimmer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function copyObjectProperties (original, wrapped, skipKey) {
7373
* @returns {Function} The wrapped function.
7474
*/
7575
function wrapFunction (original, wrapper) {
76-
if (typeof original === 'object' && original !== null) return original
76+
if (typeof original !== 'function') return original
7777

7878
const wrapped = wrapper(original)
7979

packages/datadog-shimmer/test/shimmer.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ describe('shimmer', () => {
372372
expect(() => shimmer.wrap(() => {}, () => {})).to.throw()
373373
})
374374

375-
it('should work with null instead of function', () => {
375+
it('should not work with null instead of function', () => {
376376
const a = null
377377
const wrapped = shimmer.wrapFunction(a, x => () => x)
378-
expect(wrapped()).to.equal(a)
378+
expect(typeof wrapped).to.not.equal('function')
379379
})
380380

381381
it('should not work with an object', () => {

0 commit comments

Comments
 (0)