diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index c2d6d1d0f..43d8ee42f 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -99,6 +99,11 @@ in your Node-RED user directory (${RED.settings.userDir}). noprox = proxyConfig.noproxy; } + let timingLog = false; + if (RED.settings.hasOwnProperty("httpRequestTimingLog")) { + timingLog = RED.settings.httpRequestTimingLog; + } + this.on("input",function(msg,nodeSend,nodeDone) { checkNodeAgentPatch(); //reset redirectList on each request @@ -514,6 +519,9 @@ in your Node-RED user directory (${RED.settings.userDir}). if (res.client && res.client.bytesRead) { node.metric("size.bytes", msg, res.client.bytesRead); } + if (timingLog) { + emitTimingMetricLog(res.timings, msg); + } } // Convert the payload to the required return type @@ -538,6 +546,9 @@ in your Node-RED user directory (${RED.settings.userDir}). } msg.payload = err.toString() + " : " + url; msg.statusCode = err.code || (err.response?err.response.statusCode:undefined); + if (node.metric() && timingLog) { + emitTimingMetricLog(err.timings, msg); + } nodeSend(msg); nodeDone(); }); @@ -547,6 +558,28 @@ in your Node-RED user directory (${RED.settings.userDir}). node.status({}); }); + function emitTimingMetricLog(timings, msg) { + const props = [ + "start", + "socket", + "lookup", + "connect", + "secureConnect", + "upload", + "response", + "end", + "error", + "abort" + ]; + if (timings) { + props.forEach(p => { + if (timings[p]) { + node.metric(`timings.${p}`, msg, timings[p]); + } + }); + } + } + function extractCookies(setCookie) { var cookies = {}; setCookie.forEach(function(c) {