diff --git a/lib/index.js b/lib/index.js index e5b2699..ca40a81 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,6 +23,10 @@ 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); } 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', () => {