From 3233592ff3a397725da1a690b9a2c83ea2cf4b1b Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Mon, 20 Apr 2020 13:34:52 -0400 Subject: [PATCH 1/3] Join path parts --- lib/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index e5b2699..5d6e966 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,11 +23,15 @@ module.exports = function (options) { if (str instanceof RegExp) { str = str.toString(); } + + if (Array.isArray(str)) { + str = str.join(',') + } return str && str.replace(REGEX_PIPE, DELIM); } - function getRoute(req, base_url) { + function getRoutes(req, base_url) { const routePath = req.route && req.route.path ? req.route.path : ''; const baseUrl = (base_url !== false) ? req.baseUrl : ''; return baseUrl + replacePipeChar(routePath); From 889fb8327866db27a283c67b2d0a11b3e59813b3 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Mon, 20 Apr 2020 13:35:46 -0400 Subject: [PATCH 2/3] Undo function rename --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 5d6e966..ca40a81 100644 --- a/lib/index.js +++ b/lib/index.js @@ -31,7 +31,7 @@ module.exports = function (options) { return str && str.replace(REGEX_PIPE, DELIM); } - function getRoutes(req, base_url) { + function getRoute(req, base_url) { const routePath = req.route && req.route.path ? req.route.path : ''; const baseUrl = (base_url !== false) ? req.baseUrl : ''; return baseUrl + replacePipeChar(routePath); From 219b2d2ff3eb1513faebe1876436cb54f9727e8c Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Mon, 20 Apr 2020 13:39:43 -0400 Subject: [PATCH 3/3] Add a test --- lib/index.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/index.test.js b/lib/index.test.js index 11cbb9e..6ee4059 100644 --- a/lib/index.test.js +++ b/lib/index.test.js @@ -183,6 +183,22 @@ describe('connectDatadog', () => { await asyncConnectDatadogAndCallMiddleware({ response_code: true, path }) expectConnectedToDatadog(stat, statTags, false) }) + + describe('when the path is an array of paths', () => { + it('should append the joined path to the metric tag', async () => { + req.route.path = ['/some/path', '/array/of/paths'] + const path = true + const stat = 'node.express.router' + const statTags = [ + `route:${req.route.path}`, + `response_code:${res.statusCode}`, + `path:${req.path}`, + ] + + await asyncConnectDatadogAndCallMiddleware({ response_code: true, path }) + expectConnectedToDatadog(stat, statTags, false) + }) + }) }) describe('when the path option is falsy', () => {