Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

[Fixes #14] Merge array of route paths #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down