Skip to content

Commit

Permalink
simplify instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-id authored Sep 17, 2024
1 parent 729241d commit 6ffc21f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/datadog-instrumentations/src/passport-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ function wrapVerifiedAndPublish (username, password, verified, type) {
})
}

function wrapVerify (verify, passReq) {
if (passReq) {
return function (req, username, password, verified) {
arguments[3] = wrapVerifiedAndPublish(username, password, verified, this.name)
return verify.apply(this, arguments)
}
} else {
return function (username, password, verified) {
arguments[2] = wrapVerifiedAndPublish(username, password, verified, this.name)
return verify.apply(this, arguments)
function wrapVerify (verify) {
return function wrappedVerify (req, username, password, verified) {
let index = 3

if (!this._passReqToCallback) {
index = 2
username = req
password = username
verified = password
}

arguments[index] = wrapVerifiedAndPublish(username, password, verified, this.name)

return verify.apply(this, arguments)
}
}

function wrapStrategy (Strategy) {
return function wrappedStrategy () {
if (typeof arguments[0] === 'function') {
arguments[0] = wrapVerify(arguments[0], false)
arguments[0] = wrapVerify(arguments[0])
} else {
arguments[1] = wrapVerify(arguments[1], (arguments[0] && arguments[0].passReqToCallback))
arguments[1] = wrapVerify(arguments[1])
}
return Strategy.apply(this, arguments)
}
Expand Down

0 comments on commit 6ffc21f

Please sign in to comment.