Be able to tag requests with labels as easier way to provide business metrics

This commit is contained in:
Daniel García Aubert
2020-06-08 16:29:22 +02:00
parent 07b9decb03
commit b115bca07e
13 changed files with 39 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
'use strict';
module.exports = function tag ({ tags }) {
if (!Array.isArray(tags) || !tags.every((tag) => typeof tag === 'string')) {
throw new Error('Required "tags" option must be a valid Array: [string, string, ...]');
}
return function tagMiddleware (req, res, next) {
const { logger } = res.locals;
res.locals.tags = tags;
res.on('finish', () => logger.info({ tags: res.locals.tags }));
next();
};
};