diff --git a/modules/nodejs-agent/lib/plugins/http/http.js b/modules/nodejs-agent/lib/plugins/http/http.js index 39c95ad47ee82c7b4885dd096be0e76ea510db29..81402d0e612e27eca32b3d870358096232e33c30 100644 --- a/modules/nodejs-agent/lib/plugins/http/http.js +++ b/modules/nodejs-agent/lib/plugins/http/http.js @@ -58,6 +58,7 @@ module.exports = function(httpModule, instrumentation, contextManager) { function wrapEmit(original) { return function(event, req, res) { if (event === "request") { + let originRes = res; let contextCarrier = new ContextCarrier(); contextCarrier.fetchBy(function(key) { if (req.headers.hasOwnProperty(key)) { @@ -75,7 +76,7 @@ module.exports = function(httpModule, instrumentation, contextManager) { span.log(err); } - if (this.statusCode > 400) { + if (originRes.statusCode > 400) { span.errorOccurred(); }