diff --git a/README.md b/README.md index 1c3d42c..594ff47 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,10 @@ All options are optional. * `dogstatsd` node-dogstatsd client. `default = new (require("node-dogstatsd")).StatsD()` * `stat` *string* name for the stat. `default = "node.express.router"` -* `tags` *array* of tags to be added to the histogram. `default = []` +* `tags` either: + * *array* of tags to be added to the histogram + * *function* that takes `req` and `res`, returning an array of tags + * `default = []` * `path` *boolean* include path tag. `default = false` * `method` *boolean* include http method tag. `default = false` * `protocol` *boolean* include protocol tag. `default = false` diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0d38be6 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,9 @@ +import { RequestHandler } from 'express' + +// name 'connectDatadog' doesn't really matter +// Just make sure that the function and namespace below have the same names +declare function connectDatadog(options: any): RequestHandler +declare namespace connectDatadog { + +} +export = connectDatadog diff --git a/lib/index.js b/lib/index.js index dd47dbf..1dd678d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,7 +25,7 @@ module.exports = function (options) { var baseUrl = (base_url !== false) ? req.baseUrl : ''; var statTags = [ "route:" + baseUrl + req.route.path - ].concat(tags); + ].concat(typeof tags === 'function' ? tags(req, res) : tags); if (options.method) { statTags.push("method:" + req.method.toLowerCase()); diff --git a/package.json b/package.json index 34d32f3..dc70df6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "connect-datadog", - "version": "0.0.6", + "version": "0.0.7", "description": "Datadog middleware for Connect JS / Express", "main": "index.js", "repository": { @@ -15,6 +15,10 @@ "license": "MIT", "readmeFilename": "README.md", "dependencies": { + "express": "^4.16.3", "node-dogstatsd": "0.0.6" + }, + "devDependencies": { + "@types/express": "^4.16.0" } }