diff --git a/index.js b/index.js index 11a43a9..6bce111 100644 --- a/index.js +++ b/index.js @@ -6,12 +6,16 @@ const url = require('url'); module.exports = { Plugin: MetricsByEndpoint }; +let useOnlyRequestNames; + // NOTE: Will not work with `parallel` - need request UIDs for that function MetricsByEndpoint(script, events) { if (!script.config.processor) { script.config.processor = {}; } + useOnlyRequestNames = script.config.plugins["metrics-by-endpoint-test"].useOnlyRequestNames || false; + script.config.processor.metricsByEndpoint_beforeRequest = metricsByEndpoint_beforeRequest; script.config.processor.metricsByEndpoint_afterResponse = metricsByEndpoint_afterResponse; @@ -33,9 +37,16 @@ function metricsByEndpoint_afterResponse(req, res, userContext, events, done) { // TODO: If hostname is not target, keep it. const baseUrl = url.parse(req.url).path; - let histoName = req.name ? - `${baseUrl} (${req.name})` : - `${baseUrl}`; + let histoName; + + if (useOnlyRequestNames && req.name) { + histoName = req.name; + } else if (req.name) { + histoName = `${baseUrl} (${req.name})`; + } else { + histoName = baseUrl; + } + let counterName = histoName; if (res.headers['server-timing']) {