Skip to content

Commit

Permalink
feat(enc-80): support for dynamic tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent committed Jun 30, 2021
1 parent ebfaf44 commit 9687173
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package.json
package-lock.json
node_modules/
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ async function fastifyDatadog (fastify, options = {}) {
return seconds * 1e3 + nanoseconds / 1e6
}

let dynamicTags = tags;
fastify.addHook('onRequest', async (req, reply) => {
req[startTimeSymbol] = now()
if (typeof tags === 'function') {
dynamicTags = tags(req);
}
})

fastify.addHook('onSend', async (req, reply) => {
const { context, statusCode } = reply

const statTags = [`route:${context.config.url}`, ...tags]
const statTags = [`route:${context.config.url}`, ...dynamicTags]

if (method) {
statTags.push(`method:${req.method.toLowerCase()}`)
Expand Down

0 comments on commit 9687173

Please sign in to comment.