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

Commit 20622f4

Browse files
Merge pull request #1 from smalltownheroes/master
Adding http status codes and add levels response_times and response_codes
2 parents a885b9a + 13f6b98 commit 20622f4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All options are optional.
2020
* `path` *boolean* include path tag. `default = true`
2121
* `method` *boolean* include http method tag. `default = false`
2222
* `protocol` *boolean* include protocol tag. `default = false`
23+
* `response_code` *boolean* include http response codes. `default = false`
2324

2425
## License
2526

lib/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = function (options) {
44
var datadog = options.dogstatsd || new DD();
55
var stat = options.stat || "node.express.router";
66
var tags = options.tags || [];
7+
var response_code = options.response_code || false;
78

89
return function (req, res, next) {
910
if (!req._startTime) {
@@ -27,6 +28,7 @@ module.exports = function (options) {
2728
statTags.push("method:" + req.method.toLowerCase());
2829
}
2930

31+
3032
if (options.protocol && req.protocol) {
3133
statTags.push("protocol:" + req.protocol);
3234
}
@@ -35,7 +37,13 @@ module.exports = function (options) {
3537
statTags.push("path:" + req.path);
3638
}
3739

38-
datadog.histogram(stat, (new Date() - req._startTime), 1, statTags);
40+
if (response_code) {
41+
statTags.push("response_code:" + res.statusCode);
42+
datadog.increment(stat + '.response_code.' + res.statusCode , 1, statTags);
43+
datadog.increment(stat + '.response_code.all' , 1, statTags);
44+
}
45+
46+
datadog.histogram(stat + '.response_time', (new Date() - req._startTime), 1, statTags);
3947
};
4048

4149
next();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"license": "MIT",
1616
"readmeFilename": "README.md",
1717
"dependencies": {
18-
"node-dogstatsd": "0.0.4"
18+
"node-dogstatsd": "0.0.5"
1919
}
2020
}

0 commit comments

Comments
 (0)